Keeping it simple here so not going into every detail - using the datetime stamp of an entity state change, from “last_updated” - how do I get the trigger data (at a later time) from that event
(such as “trigger.to_state.context.####” to determine if it was manually changed at that time) - without setting up more variables to manually keep track of and maintain?
Here is the use case if more details are needed for clarity:
- Motion sensor automation turns on wall switch for overhead light
- At some point, someone turns OFF the wall switch manually and walks out of the room
As my motion sensor is configured to only detect motion once per minute, this use case usually works fine - IF the movement to turn off the light is detected and transmitted to Home Assistant -BEFORE the light is switched off, AND the person walks out of the room within one minute of when that motion is detected.
As you can imagine that is a little problematic - and annoying if the lights go back on while you are or just after you walk out of the room!
So, I am not sure how to enhance the condition for the automation in #1 to NOT turn said lights on if they were turned off manually within the last, say 5 minutes. Here is my research on how to implement this but it is lacking - and where I need help (the simple inelegant way is to set up variables maintained to use in the condition but I’d rather not) -
I believe this would tell me if the switch was turned off within the last 5 minutes:
{{ (as_timestamp(now()) - as_timestamp((states.input_boolean.entity_id_being_monitored.last_updated)) < 300)}}
and this will tell me if it was turned off MANUALLY (BUT I believe this information is only available at the exact time the state of the switch is changed previously - the information is not available later, is it?) -
condition:
- “{{ trigger.to_state.context.id != none }}”
- “{{ trigger.to_state.context.parent_id == none }}”
- “{{ trigger.to_state.context.user_id == none }}”
So - without setting up variables to handle this (and as you can imagine I would then have a ton of these - ugh) - how do I get “trigger.to_state.context.####” information from a state that had changed in the past?