When I go to sleep I enable the ‘sleep mode’ switch to change the lighting in my house. Now I also want HA to turn off my motion sensor automation in the hallway, so when the cats run around at night, I won’t get woken up. I believe I have written a correct automation for this (it gets triggered upon a change in the state of the sleep mode) but it does not turn off the automation. Can anyone advise me on what is going wrong ?
The script (written using the UI but this is the code):
I’m not sure if one could do it like this. What’s the state reported by switch.adaptive_lighting_sleep_mode_default anyway if you check development tools?
Hi @distinq, can you please mark this topic as solved?
If you mark this thread as solved by selecting the answer which gave you the solution, other members will not jump in to try to help (like I just did) AND the topic can be useful for others having a similar issue.
Why not just add this as the condition in automation.hallway_light:
condition:
conditon: state
state: 'off'
entity_id: switch.adaptive_lighting_sleep_mode_default
So the hallway light automation doesn’t do anything unless the sleep mode switch is off.
Maybe its just me but having automations turn others on and off seems very confusing. Now you have an extra automation and you have to look in two different automations to have a complete understanding of the logic. Seems better to have all the logic in one place.
I agree with CentralCommand; it’s not a good practice to have one automation disable another as a normal operation.
If you want one script/automation to influence the behavior of another script/automation, consider using another entity, perhaps an input_boolean, to serve as a middleman. For example, one script/automation turns the input_boolean on or off, the other uses the input_boolean’s state, in a State Condition, to determine if it should proceed or not.
This strategy still allows you to manually disable an automation when needed without danger of having it automatically re-enabled by another automation.