Hi, I copied some code from an example, but I’m struggling to understand some things.
- Are the trigger IDs I put in configuration.yaml template section global? If so, I obviously need to name them better. Trigger IDs created in automations seem local to the automation, so I’m confused about the scope.
- Why is there no hyphen before sensor:? I spent hours trying to find my bug. Does that relate to 1, somehow grouping the trigger with the sensor? Should I somehow separate the second, unrelated sensor? Basically, if I had two unrelated sensors with unrelated trigger IDs, I’m not sure what the format would be. Ideally I would encapsulate them in separate objects, but I can’t tell if that’s possible.
- Why when setting the state during reset do you use 0 instead of {{ 0 }}?
template:
- trigger:
- id: count # are these names global?
platform: state
entity_id: binary_sensor.rain_gauge_contact
- id: reset
platform: time
at: '00:00:00'
- id: restart
platform: homeassistant
event: start
- id: reload
platform: event
event_type: event_template_reloaded
sensor: # why is there no hyphen before sensor?
- name: 'Rainfall (day)'
unique_id: 'rainfall_day'
state_class: measurement
device_class: precipitation
unit_of_measurement: 'in'
state: >
{% set in_per_flip = (1 / 24) | round(2) %}
{% if trigger.id == 'reset' or trigger.id == 'restart' or trigger.id == 'reload' %}
0 # why not {{ 0 }}?
{% else %}
{{ this.state | float(0) + in_per_flip }}
{% endif %}
- name: 'garage fan current on minutes'
unique_id: 'garage_fan_current_on_minutes'
state_class: measurement
device_class: duration
unit_of_measurement: min
state: >
{% if states('switch.garage_fan') == 'on' %}
{{ ((as_timestamp(now()) - as_timestamp(states['switch.garage_fan'].last_changed| default(0)) | int) / 60) | round(0, 'floor') }}
{% else %}
0
{% endif %}