If I would use this configuration inside of a package, will the scan_interval setting only apply to test_sensor_a and test_sensor_b? Or will it apply to ALL template sensors?
I was just trying to do this but the sensor doesn’t seem to update at all:
- platform: template
scan_interval: 10
sensors:
offline_devices:
friendly_name: Offline Devices
value_template: >-
{%- for entity_id in states.group.all_devices.attributes.entity_id if states(entity_id) == 'not_home' -%}
{% set parts = entity_id.split('.') -%}
{%- if loop.first %} {% elif loop.last %}, {% else %}, {% endif -%}{{ states[parts[0]][parts[1]].name }}
{%- endfor %}
And when I move the scan_interval line further down, I get a config error:
Invalid config for [sensor.template]: [scan_interval] is an invalid option for [sensor.template]. Check: sensor.template->sensors->offline_devices->scan_interval. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
So, when I replied originally to @DavidW, I was only commenting on how configuration data is organized and sent to the platform code. I didn’t check to see if a Template Sensor actually took scan_interval as a valid option. According to the doc page you referenced, it does not appear that scan_interval is a valid option for Template Sensors (although some components/platforms allow “extra” data in the config that will just be ignored if present.)
I suspect your problem is that the template sensor is only being updated when the state of group.all_devices changes, and that will only change going between one person being home and nobody being home and vice versa. I.e., if someone is home and another person comes home, the group’s state doesn’t change because it’s already home. To get this to work may need to add entity_id and list all the devices in the group.
Oh, and for what it’s worth, I did try the basic template on the Templates page and it seems to work fine. You can simplify a bit by changing:
Thanks @pnbruckner - the explanation with the status of the all_devices group makes sense.
And I noticed as well that on the template page the loop works fine - it just doesn’t carry through to the UI, which I find strange.
When looking at the documentation for the template sensor I saw that the scan_interval is not mentioned there explicitly, but then again: so are(n’t) many other options I’m using in other components. I just thought maybe somebody had found a way to rig that
I second @pnbruckner. Scan_interval is going to do nothing for you because the state of your entity will still be the same. Its just scanning for state changes, then executes when the state has changed. Your best option is to list out the entity_id’s. You could also get fancy with the time platform. That will force updates pretty regularly, but you need to build it into your value template.
Also, Side note. You should know that template sensors have a limit of 255 characters (might be 240). If your compounded string gets longer than that you will get an error.
@pnbruckner is right, the option only applies to the template sensors in my example and NOT to other template sensors used in other packages. But however, the scan_interval option does not apply for a template sensor.
I was a bit confused by this page, however it does not apply for template sensors.
My template sensors stopped working as well when the scan_interval was added to the config.
I don’t actually use the component, but it is like any other sensor. It’s going to be an entity that shows up in your interface. I believe it is ‘sensor.time’ if you use -time in the configuration.