I am failing understanding how I can setup in yaml for instance a sensor updated every hours and another one updated every 7 minutes.
Template doc talks about blocks but it shows only 1 example with multiple blocks. Unfortunately it is just 2 blocks with the 2nd being state based update. No example where it would be 2 trigger based update blocks.
Trigger template sensors can have multiple triggers, but afaik, you can only add these via yaml. Here's one I actually use -
- triggers:
- trigger: state
entity_id: climate.thermostat
conditions:
- condition: template
value_template: >
{{ states('climate.thermostat') in ['heat', 'cool'] }}
sensor:
- name: Thermostat Last Mode
unique_id: thermostat_last_mode
state: >
{{ states('climate.thermostat') if states('climate.thermostat') in ['heat', 'cool'] else this.state }}
But I could add additional triggers under the trigger key, for example -
- triggers:
- trigger: state
entity_id: climate.thermostat
- trigger: state
entity_id: fan.thermostat
conditions:
- condition: template
value_template: >
{{ states('climate.thermostat') in ['heat', 'cool'] }}
sensor:
- name: Thermostat Last Mode
unique_id: thermostat_last_mode
state: >
{{ states('climate.thermostat')
if states('climate.thermostat') in ['heat', 'cool']
else this.state }}
For what you're trying to do, you'd probably want to create triggers for "time" or a "time_pattern". Time will do specific times of the day. Time pattern will do something like every 5 minutes (whatever differential you want.)
The template integration expects a list. In YAML list items are denoted with a -, so to add a new trigger-based template entity, you start with a -. Then you add the triggers, domain key, and any of the other optional configuration keys:
template:
- triggers: #The dash on this line starts a new item under template
- trigger: time_pattern
hours: "/1"
sensor:
- name: My Every-hour Trigger-Based Sensor
state: "{{ now().minute is even }}"
- triggers: #The dash on this line starts a new item under template
- trigger: time_pattern
minutes: "/7"
sensor:
- name: My Every-7-minutes Trigger-Based Sensor
state: "{{ now().minute is odd }}"
- sensor: #The dash still starts a new item under template, even though I started with sensor this time
- name: My 1pm Trigger-Based Sensor
state: "{{ now().day is odd }}"
triggers:
- trigger: time
at: "13:00:00"
I have added blank lines between the items, but they are not necessary.