I have template sensors that measure the average energy consumption for certain devices over the last 7 days. However, it doesn't make sense for it to be updating constantly throughout the day.
I've read this documentation: https://www.home-assistant.io/integrations/template/ But it doesn't seem to be helping because I'm not sure how triggers interact with the sensor.
I was testing it with trying to get it to only update every hour. Here's the code I thought would work:
`- triggers:
- trigger: time_pattern
This will update every hour
minutes: 0
sensor: - name: "Bedroom AC Plug Average"
unique_id: bedroomacplugaverage
icon: mdi:home-lightning-bolt
state: >-
{% if ( states('sensor.bedroom_ac_consumption_over_7_days') | float ) <= 0 %}
0
{% else %}
{{ (( states('sensor.bedroom_ac_consumption_over_7_days') | float ) / 7 ) | round(3) }}
{% endif %}
attributes:
friendly_name: "Bedroom AC Plug Average"
unit_of_measurement: kWh`
But, when I check it in states, it still seems to update when states('sensor.bedroom_ac_consumption_over_7_days') has a significant update. This equates to roughly every 70-80 seconds while Bedroom AC is running. I've tried trying to get the indentation to closer match the documentation, but file editor and visual code studio give me errors when matching it up.
When I try to google/duckduckgo search it, I just get pages with generic information about trigger sensors. When I try to find a video on YouTube, I can't seem to find a video about how to get what I want. It all seems to be videos on how to write a basic sensor or how to use triggers in automations.
I do have template: !include_dir_merge_list config/templates in configuration.yaml.