Hi. I have one automation which is triggered by my holding a button and it dims/brightens a light. There is an input_boolean which gets flipped and which provides a state to the automation telling whether to dim or brighten. This part is working.
I'd like to have a second automation to reset the input_boolean to off if nothing happens to it for 10 seconds -- i don't care which state it's in as long as it is in the current state. How to best do that. This is what I have for the second automation:
- alias: "Lights: Reset To Dim Helper on final Stop"
id: wrgomwergoerygjoeayrgoaieughjoaiehglaier
mode: single # Ensure it doesn't run multiple times concurrently for the same event
triggers:
- trigger: event
event_type: REMOTE_STOP_ACTION # Listen for the custom event
actions:
- variables:
helper_id: "{{ trigger.event.data.helper_entity_id }}" # Get the helper entity ID from the event data
helper_state: "{{states(helper_id)}}"
- alias: "Wait for 10 seconds of no state change -- this gets triggered once and waits until user is done holding the buttons for the particular light. Never times out, eventually resets input_boolean when"
wait_for_trigger:
- platform: template
value_template: "{{ states(helper_id) == helper_state}}"
for: "0:00:10"
- service: input_boolean.turn_off
data:
entity_id: "{{ helper_id }}"
But the problem here is that the template does not take into account state changes which happen while it's waiting. What's the proper way to do this? I've also tried accessign the .last_changed property of the state object and comparaing to now(), but this only evaluates once evey minute, so the resolution is not there. I can't just have a normal state trigger, because I don't know which of the entities it will be a priori and a state trigger doesn't want a teamplate for entity_id.