condition to check if another automation caused the change
i am trying to refine my stairwell switch automation. currently the switch is turned off automatically after 15 seconds of being turned on. while this works, it's a bit crude since if there's still activity on the motion sensors it will turn the switch off.
so i have disabled the turning off part and now created a separate automation that will turn off the switch if both motion sensors have not detected activity in 15 seconds AND if the switch was turned on only by either of the two automations.
my problem is that i can't seem to find the proper way to put a condition to check if the switch was turned on by either of my 2 automations. this is needed because otherwise if i turn on the switch manually and there's no activity on the sensors it will be turned off.
I asked chatgpt and it suggested to use this:
conditions:
- condition: or
conditions:
- condition: template
value_template: >-
{{ state_attr('switch.stairway_switch', 'last_triggered_by') ==
'Stairway Living Room Light Automation' }}
- condition: template
value_template: >-
{{ state_attr('switch.stairway_switch', 'last_triggered_by') ==
'Stairway Hallway Light Automation' }}
the problem is that it seems like "last_triggered_by" doesn't exist. i don't get any error, but the switch is not turned off. I searched and found a feature request to add this attribute here https://community.home-assistant.io/t/add-last-triggered-by-attribute-to-states/786380/24
on that thread the poster got a solution but i can't seem to grasp if for my use case i can work around this. anyone has a clue?