If I include entities
in a sensor will HA still try and ascertain any other entities that should be watched for state changes or does it assume only those listed explicitly are required?
As far as I understand it and from experience, no. If you explicitly nominate entities to watch it does not search the template for more.
Thanks, not the answer I was hoping for but at least I know to work with itâŚ
I assume you mean template sensors or template binary sensors?
I can confirm @tom_lâs answer. In the current implementation, if you specify entities using the entities
option, it will only watch those; the template(s) are not searched for other entities. One of the reasons I tend to suggest not using the entities
option unless itâs necessary.
BTW, it would be relatively easy to add a new option, say, additional_entities
, that list entities to monitor in addition to the ones that are extracted from the templates. Or maybe a new option that controls whether the entities listed in entity_id
replace, or add to, the ones extracted from the templates. Maybe someone can add that to their list of things to do.
I wonder if there is a good reason why it doesnât already monitor both those listed and those (that could be) extracted?
Apart from efficiency of course which whilst obviously a âgood reasonâ doesnât fit with all use cases.
Probably not. Probably it just evolved that way. I.e., first it just extracted entities. Then too many people found that doesnât always work, so someone came up with the idea to provide an alternate way to specify which entities to monitor, âŚ, and simply didnât think of the scenario where youâd want it to do both. Of course, one of the main reasons the automation extraction technique isnât sufficient is due to using now()
in the template. I suppose another idea would be to enhance the extraction algorithm to notice if now
or utcnow
are used, and if so, add another periodic based update.
Bottom line ⌠like many things in HA, it just evolves as people find new needs and have the time & motivation to address them.
since this is about clarification the entities in template sensors⌠let me jump in. Sorry if this not the exact same question, but I am confused and hope you can help.
After updating to 110.2/3 I got errors in the log about HA not being able to extract entities to create the template, and it would only be updated manually. (my words)
This was rather surprising to me, because 1) they had worked before and 2) the entities used in the template are very clearâŚ
kantoor_thermostat_selected_schema:
entity_id: climate.kantoor #<-- force to use this now
friendly_name: Selected schema
value_template: >
{{state_attr('climate.kantoor','selected_schema')}}
and several other template sensor I have for the climate entity. Strangly enough, not for all
kantoor_thermostat_temperature_boiler:
friendly_name: Boiler temp
value_template: >
{{state_attr('climate.kantoor','boiler_temperature')}}
this one works as before and got no complaints. have more of those too.
also, it happened only with this entity/set of templates.
What could be an explanation? Could it be the integration wasnât fully initialized at startup maybe? Or some other startup issue?
So what exactly was the template sensor configuration that caused the warning, and can you provide the exact wording of the warning?
Template sensor 'kantoor_thermostat_selected_schema' has no entity ids configured to track nor were we able to extract the entities to track from the icon template(s). This entity will only be able to be updated manually.
and these are my templates:
sensor:
- platform: template
sensors:
kantoor_thermostat_state:
friendly_name: Current state
value_template: >
{{states('climate.kantoor')|capitalize}}
icon_template: >
{% set state = states('climate.kantoor') %}
{% if state == 'auto' %} mdi:autorenew
{% elif state == 'idle' %} mdi:pause
{% else %} mdi:power-off
{% endif %}
kantoor_thermostat_hvac_action:
friendly_name: Hvac action
value_template: >
{{state_attr('climate.kantoor','hvac_action')|capitalize}}
icon_template: >
{% set action = state_attr('climate.kantoor','hvac_action') %}
{% set icon = {'heating':'mdi:fire',
'cooling':'mdi:snowflake',
'auto':'mdi:autorenew'} %}
{{icon[action] if action in icon else 'mdi:pause-circle'}}
kantoor_thermostat_temperature_current:
friendly_name: Current temp
value_template: >
{{state_attr('climate.kantoor','current_temperature')}}
icon_template: >
{% if state_attr('climate.kantoor','current_temperature') > 15 %} mdi:home-thermometer
{% else %} mdi:home-thermometer-outline
{% endif %}
unit_of_measurement: '°C'
kantoor_thermostat_temperature_target:
# entity_id: climate.kantoor
friendly_name: Target temp
value_template: >
{{state_attr('climate.kantoor','temperature')}}
icon_template: >
{{'mdi:thermostat'}}
unit_of_measurement: '°C'
kantoor_thermostat_temperature_boiler:
friendly_name: Boiler temp
value_template: >
{{state_attr('climate.kantoor','boiler_temperature')}}
icon_template: >
{% set boiler = state_attr('climate.kantoor','boiler_temperature')|int %}
{% if boiler > 60 %} mdi:thermometer-high
{% elif boiler > 20 %} mdi:thermometer
{% elif boiler > 0 %} mdi:thermometer-low
{% else %} mdi:thermometer-alert
{% endif %}
unit_of_measurement: '°C'
kantoor_thermostat_temperature_outdoor:
friendly_name: Outdoor temp
value_template: >
{{state_attr('climate.kantoor','outdoor_temperature')}}
icon_template: >
{% set outdoor = state_attr('climate.kantoor','outdoor_temperature')|int %}
{% if outdoor > 20 %} mdi:thermometer-high
{% elif outdoor > 10 %} mdi:thermometer
{% elif outdoor > 0 %} mdi:thermometer-low
{% else %} mdi:thermometer-alert
{% endif %}
unit_of_measurement: '°C'
kantoor_thermostat_available_schemas:
# entity_id: climate.kantoor
friendly_name: Available schemas
value_template: >
{{state_attr('climate.kantoor','available_schemas')}}
icon_template: >
{{'mdi:calendar-multiple-check'}}
kantoor_thermostat_selected_schema:
# entity_id: climate.kantoor
friendly_name: Selected schema
value_template: >
{{state_attr('climate.kantoor','selected_schema')}}
icon_template: >
{{'mdi:calendar-multiple-check'}}
kantoor_thermostat_preset_modes:
# entity_id: climate.kantoor
friendly_name: Preset modes
value_template: >
{{state_attr('climate.kantoor','preset_modes')}}
icon_template: >
{{'mdi:format-list-bulleted'}}
kantoor_thermostat_current_preset_mode:
friendly_name: Current preset mode
value_template: >
{{state_attr('climate.kantoor','preset_mode')|replace('_',' ')|capitalize}}
icon_template: >
{% set mode = state_attr('climate.kantoor','preset_mode') %}
{% set icon = {'Temporary':'mdi:gesture-double-tap',
'Regulier':'mdi:check-circle',
'Manual':'mdi:gesture-swipe-vertical',
'away':'mdi:home-export-outline',
'vacation':'mdi:beach',
'asleep':'mdi:hotel',
'no_frost':'mdi:snowflake'} %}
{{icon[mode] if mode in icon else 'mdi:home'}}
kantoor_thermostat_hvac_modes:
# entity_id: climate.kantoor
friendly_name: Hvac modes
value_template: >
{{state_attr('climate.kantoor','hvac_modes')}}
icon_template: >
{{'mdi:format-list-text'}}
kantoor_thermostat_min_temp:
# entity_id: climate.kantoor
friendly_name: Min temp
value_template: >
{{state_attr('climate.kantoor','min_temp')}}
icon_template: >
{{'mdi:thermometer-minus'}}
kantoor_thermostat_max_temp:
# entity_id: climate.kantoor
friendly_name: Max temp
value_template: >
{{state_attr('climate.kantoor','max_temp')}}
icon_template: >
{{'mdi:thermometer-plus'}}
as you can see in the Yaml above, the ones with the commented entity_id show the warning, the others, with an exact same state_attr() seem to fare well.
(these Warnings only show in the developer-tools/logs page, not in homeassistant.log which has level error. I do see this, which might be related?:
sensor:
- platform: template
sensors:
kantoor_thermostat_state:
friendly_name: Current state
value_template: >
{{states('climate.kantoor')|capitalize}}
icon_template: >
{% set state = states('climate.kantoor') %}
{% if state == 'auto' %} mdi:autorenew
{% elif state == 'idle' %} mdi:pause
{% else %} mdi:power-off
{% endif %}
kantoor_thermostat_hvac_action:
friendly_name: Hvac action
value_template: >
{{state_attr('climate.kantoor','hvac_action')|capitalize}}
icon_template: >
{% set action = state_attr('climate.kantoor','hvac_action') %}
{% set icon = {'heating':'mdi:fire',
'cooling':'mdi:snowflake',
'auto':'mdi:autorenew'} %}
{{icon[action] if action in icon else 'mdi:pause-circle'}}
kantoor_thermostat_temperature_current:
friendly_name: Current temp
value_template: >
{{state_attr('climate.kantoor','current_temperature')}}
icon_template: >
{% if state_attr('climate.kantoor','current_temperature') > 15 %} mdi:home-thermometer
{% else %} mdi:home-thermometer-outline
{% endif %}
unit_of_measurement: '°C'
kantoor_thermostat_temperature_target:
# entity_id: climate.kantoor
friendly_name: Target temp
value_template: >
{{state_attr('climate.kantoor','temperature')}}
icon_template: >
{{'mdi:thermostat'}}
unit_of_measurement: '°C'
kantoor_thermostat_temperature_boiler:
friendly_name: Boiler temp
value_template: >
{{state_attr('climate.kantoor','boiler_temperature')}}
icon_template: >
{% set boiler = state_attr('climate.kantoor','boiler_temperature')|int %}
{% if boiler > 60 %} mdi:thermometer-high
{% elif boiler > 20 %} mdi:thermometer
{% elif boiler > 0 %} mdi:thermometer-low
{% else %} mdi:thermometer-alert
{% endif %}
unit_of_measurement: '°C'
kantoor_thermostat_temperature_outdoor:
friendly_name: Outdoor temp
value_template: >
{{state_attr('climate.kantoor','outdoor_temperature')}}
icon_template: >
{% set outdoor = state_attr('climate.kantoor','outdoor_temperature')|int %}
{% if outdoor > 20 %} mdi:thermometer-high
{% elif outdoor > 10 %} mdi:thermometer
{% elif outdoor > 0 %} mdi:thermometer-low
{% else %} mdi:thermometer-alert
{% endif %}
unit_of_measurement: '°C'
kantoor_thermostat_available_schemas:
# entity_id: climate.kantoor
friendly_name: Available schemas
value_template: >
{{state_attr('climate.kantoor','available_schemas')}}
icon_template: >
{{'mdi:calendar-multiple-check'}}
kantoor_thermostat_selected_schema:
# entity_id: climate.kantoor
friendly_name: Selected schema
value_template: >
{{state_attr('climate.kantoor','selected_schema')}}
icon_template: >
{{'mdi:calendar-multiple-check'}}
kantoor_thermostat_preset_modes:
# entity_id: climate.kantoor
friendly_name: Preset modes
value_template: >
{{state_attr('climate.kantoor','preset_modes')}}
icon_template: >
{{'mdi:format-list-bulleted'}}
kantoor_thermostat_current_preset_mode:
friendly_name: Current preset mode
value_template: >
{{state_attr('climate.kantoor','preset_mode')|replace('_',' ')|capitalize}}
icon_template: >
{% set mode = state_attr('climate.kantoor','preset_mode') %}
{% set icon = {'Temporary':'mdi:gesture-double-tap',
'Regulier':'mdi:check-circle',
'Manual':'mdi:gesture-swipe-vertical',
'away':'mdi:home-export-outline',
'vacation':'mdi:beach',
'asleep':'mdi:hotel',
'no_frost':'mdi:snowflake'} %}
{{icon[mode] if mode in icon else 'mdi:home'}}
kantoor_thermostat_hvac_modes:
# entity_id: climate.kantoor
friendly_name: Hvac modes
value_template: >
{{state_attr('climate.kantoor','hvac_modes')}}
icon_template: >
{{'mdi:format-list-text'}}
kantoor_thermostat_min_temp:
# entity_id: climate.kantoor
friendly_name: Min temp
value_template: >
{{state_attr('climate.kantoor','min_temp')}}
icon_template: >
{{'mdi:thermometer-minus'}}
kantoor_thermostat_max_temp:
# entity_id: climate.kantoor
friendly_name: Max temp
value_template: >
{{state_attr('climate.kantoor','max_temp')}}
icon_template: >
{{'mdi:thermometer-plus'}}
if I check the entities in the frontend they are present:
nor were we able to extract the entities to track from the icon template(s)
So the warning tells you the problem is in the icon template, not the value template. E.g.:
icon_template: >
{{'mdi:format-list-text'}}
These are not really templates, are they? So why use icom_template
? Why not just use Configuration â Customization instead?
bingo! Solved. (canât mark it solved somehow, so credits where credits are due like this then )
wel spotted⌠Ive looked at this a dozen times, and tbh, those are the only templates in my config that use that âtrickââŚ
I should have known betterâŚ
Thanks Phil!
Of course this is because the template sensor forces us to use an icon_template, and doesnt allow a single icon setting. Which should really be PRâedâŚ
Iâm not sure if this would be OT but as it is my topic I guess I can choose?
I do, and it doesnât seem to work.
e.g.
homeassistant:
customize:
sensor.hall_battery_level:
device_class: battery
- type: entities
title: Various stuff
show_header_toggle: false
entities:
- sensor.hall_battery_level
Customization already provided the ability to specify an icon for anything. Why should a template sensor config need it? icon_template
, of course, was added to provide a templated way to specify an icon, which in your case, you did not need.
EDIT: And I think you can specify the icon via your Lovelace config, which I believe is preferred these days???
Thatâs weird. I definitely have customizations that work, including device_class
for a binary_sensor
. Hmm⌠What does it look like when you click the âmore infoâ button for it in the STATES tab?
yep,
devâs seem to steer us in that direction. Which I still feel is a letdown compared to the global way of customizing.
No such thing as coincidence as I have just made this little repo on the revivement of Andreyâs custom-ui, and how to use that in nowadays Homeassistant - Lovelace
What about if you use:
icon_template: >
{% if true %}
mdi:format-list-text
{% endif %}
Maybe itâs the card???
I created a template sensor. Before any customization:
After customizing via Configuration -> Customization:
It would still complain about not being able to find any entities I would think.