Skip to main content

Jinja Templates

This templating system is the same that Home Assistant implements. You can use the majority of the template methods and objects. The entire template will be processed, rendered and the result will be used as the desired option. If you don't want to display anything in certain scenarios, you should return an empty string in those cases. The next client side varianles will be available in Jinja templates:

  • user_name: String with the logged user's name
  • user_is_admin: Bolean value than indicates if the logged user is admin or not
  • user_is_owner: Bolean value than indicates if the logged user is the owner or not
  • user_agent: User agent of the browser in which Home Assistant is being executed

When the entities used in a templates change their state, it will trigger an update and the updated result of the template will be rendered.

Example

The next example will set the next options:

  1. Sets the title of the sidebar as "My Home" followed by the current time.
  2. Adds the number of HACS updates as a notification in the HACS item in the sidebar. In case that there are no updates, an empty string is returned and in these cases the notification will not be displayed.
  3. Creates a new item that redirects to the Home Assistant info page with a dynamic text with the word "Info" followed by the installed Supervisor version between parentheses and the Operating System version in the info text.
<config directory>/www/sidebar-config.yaml
title: 'My Home {{ as_timestamp(states("sensor.date_time_iso")) | timestamp_custom("%H:%M") }}'
order:
- item: 'hacs'
notification: |
{{
expand(states.update)
| selectattr('state', 'eq', 'on')
| map(attribute='entity_id')
| map('device_attr', 'identifiers')
| map('contains', 'hacs')
| list
| length or ""
}}
- new_item: true
item: 'info'
name: 'Info ({{ state_attr("update.home_assistant_supervisor_update", "latest_version") }})'
info: 'OS {{ state_attr("update.home_assistant_operating_system_update", "latest_version") }}'
href: '/config/info'
icon: 'mdi:information-outline'