I get the new energy prices for tomorrow sometime during the day. These are stored as attributes.
At midnight I want to transfer the prices for tomorrow to the prices for today. These prices should survice a reboot.
The values of trigger based sensors should survive a reboot, so I tried:
template:
- trigger:
- platform: time
at: "00:00"
sensor:
- name: electricityprices_today
state: "OK"
unique_id: electricityprices_today
attribute_templates:
data: >-
{% set ns = namespace(items=[]) %}
{% for i in states.sensor.electricityprices_tomorrow.attributes.data %}
{% set ns.items = ns.items + [ {'date': i.date, 'price': i.price} ] %}
{% endfor %}
{{ ns.items }}
I get the following error:
Invalid config for 'template' at my_packages/electricity.yaml, line 67: 'attribute_templates' is an invalid option for 'template', check: sensor->0->attribute_templates
Thanks a lot, this solved it.
Can I use attributes instead of attribute_templates also for sensors?
I like to keep things consistent and as I’m just starting it is not a lot of work to change it.
Read through the template docs. The format you are using for the trigger-based sensor is different from the legacy sensors. Use whichever is appropriate. They don’t mix.
Invalid config for 'template' at my_packages/test.yaml,
line 11: expected a dictionary for dictionary value 'sensor->0->attributes', got ['data'] Invalid config for 'template' at my_packages/test.yaml,
line 7: 'platform' is an invalid option for 'template', check: sensor->0->platform Invalid config for 'template' at my_packages/test.yaml,
line 9: 'resource' is an invalid option for 'template', check: sensor->0->resource
Thanks for your answer. Who knows maybe sometime in the future it will be possible.
The idea was that a trigger based sensor doesn’t refresh it’s data over a restart.
This way during development I don’t hammer the website providing the information to much, avoiding running out of my token limit.
Correct. A Trigger-based Template Sensor updates its value only when it’s triggered by one of its triggers.
However, you can’t combine the configurations for two completely different integrations (Template and RESTful Sensor) and expect the end-result to work.