Many of my automations follow a simple flow where I have a group of inputs/sensors that if the group turns on, it turns on a device…if the group turns off, it turns off the device. For an unknown reason, once in a while it randomly turns something on when it should be off. I’m unsure how to debug it as I have typically only noticed hours later and the log has usually wrapped or not contained anything.
Here is today’s example, the laundry room light stayed on after everyone left home.
group:
# This group is all the booleans that can turn the device "on"
laundry_lamp_on_conditions:
entities:
# Motion sensor
- binary_sensor.laundry_room_recent_occupied
# Door to garage
- binary_sensor.inside_garage_door
# Door to kitchen
- binary_sensor.laundry_door
automation:
# Turn the device on if any "on" condition and no "block" conditions are met
- alias: "laundry_lamp_turn_on"
trigger:
- platform: state
entity_id: group.laundry_lamp_on_conditions
to: 'on'
- platform: state
entity_id: switch.laundry_light
from: 'unavailable'
to: 'off'
condition:
- condition: state
entity_id: group.laundry_lamp_on_conditions
state: 'on'
action:
service: switch.turn_on
entity_id: switch.laundry_light
# Turn the device off if no "on" conditions are met, or if any "block" conditions are met
- alias: "laundry_lamp_turn_off"
trigger:
- platform: state
entity_id: group.laundry_lamp_on_conditions
to: 'off'
for: '00:00:05'
- platform: state
entity_id: switch.laundry_light
from: 'unavailable'
to: 'on'
condition:
- condition: or
conditions:
- condition: state
entity_id: group.laundry_lamp_on_conditions
state: 'off'
action:
service: switch.turn_off
entity_id: switch.laundry_light
Annoyingly, it is random…last time it was the front porch lights. Another time the garage lights. When I manually set a condition on/off it seems to work as expected.
I think you are making think too complicated. I would condense your automation down to this:
automation:
# Turn the device on if any "on" condition and no "block" conditions are met
- alias: "laundry_lamp_turn_on"
trigger:
- platform: state
entity_id: group.laundry_lamp_on_conditions
to: 'on'
action:
service: switch.turn_on
entity_id: switch.laundry_light
# Turn the device off if no "on" conditions are met, or if any "block" conditions are met
- alias: "laundry_lamp_turn_off"
trigger:
- platform: state
entity_id: group.laundry_lamp_on_conditions
to: 'off'
for: '00:00:05'
action:
service: switch.turn_off
entity_id: switch.laundry_light
Also, not sure if you want things to turn off after 5 seconds ‘00:00:05’ of no sensor activity or 5 mins ‘00:05:00’. Some of the things you have are kind of redundant, and not needed, but to make a long story short, I think this is what you need.
Could be some sort of timeout issue where the device/entity doesn’t report back a successful status change. Does this perhaps happen more often? How is your Zwave mesh? What controller and setup are you using? Has this started recently?
I’ve only noticed it very recently, as far as I know the mesh is strong and reliable. Any time I have commanded anything to happen its nearly instant, especially with the 700-series Aeotec stick I got back when the switch to ZwaveJS happened. This also seems very infrequent it acts up, maybe once a week for the last couple weeks.
The slight extra complexity is because I use a standard format across all my stuff so I can also have “blockers” to turn something off overriding “on conditions” (e.g. if it’s sunny or we aren’t home it blocks anything turning on)
And I did mean 5 seconds, that’s to handle an edge case where sometimes if you go thru a door quickly the motion-sensor is zigbee which those take 2-3 seconds to report back and are less reliable than Z-wave so delaying turn-off by 5 seconds prevents it from turning off if you quickly go into the room, close the door behind, and it hasn’t yet registered your motion.
The “unavailable → on” and “unavailable → off” is to handle when the power blips the switches get out of sync from the server, so HA will command it off/on when it becomes available again (since the server is tracking what the state should be).
I removed the placeholder comments to reduce clutter
group:
# This group is all the booleans that can turn the device "on"
laundry_lamp_on_conditions:
entities:
#- input_boolean.laundry_lamp_garage_door_entering_on
- binary_sensor.laundry_room_recent_occupied
- binary_sensor.inside_garage_door
- binary_sensor.laundry_door
# This group is all the booleans that can turn the device off and block it from being turned on
# laundry_lamp_blocker_conditions:
# entities:
# - placeholder
automation:
# Turn the device on if any "on" condition and no "block" conditions are met
- alias: "laundry_lamp_turn_on"
id: "laundry_lamp_turn_on"
trigger:
- platform: state
entity_id: group.laundry_lamp_on_conditions
to: 'on'
# - platform: state
# entity_id: group.laundry_lamp_blocker_conditions
# to: 'off'
- platform: state
entity_id: switch.laundry_light
from: 'unavailable'
to: 'off'
# - platform: homeassistant
# event: start
condition:
- condition: state
entity_id: group.laundry_lamp_on_conditions
state: 'on'
# - condition: state
# entity_id: group.laundry_lamp_blocker_conditions
# state: 'off'
action:
service: switch.turn_on
entity_id: switch.laundry_light
# Turn the device off if no "on" conditions are met, or if any "block" conditions are met
- alias: "laundry_lamp_turn_off"
id: "laundry_lamp_turn_off"
trigger:
- platform: state
entity_id: group.laundry_lamp_on_conditions
to: 'off'
for: '00:00:05'
# - platform: state
# entity_id: group.laundry_lamp_blocker_conditions
# to: 'on'
- platform: state
entity_id: switch.laundry_light
from: 'unavailable'
to: 'on'
# - platform: homeassistant
# event: start
condition:
- condition: or
conditions:
- condition: state
entity_id: group.laundry_lamp_on_conditions
state: 'off'
# - condition: state
# entity_id: group.laundry_lamp_blocker_conditions
# state: 'on'
action:
service: switch.turn_off
entity_id: switch.laundry_light
Different example (but I don’t have screenshots) this one acted up last week which I noticed when I came home and the front porch lights were on…
group:
# This group is all the booleans that can turn the device "on"
outside_front_porch_lights_on_conditions:
entities:
- input_boolean.outside_front_porch_garage_lights_timers_on
- input_boolean.outside_front_porch_garage_lights_motion_on
- input_boolean.outside_front_porch_garage_lights_main_door_open_on
# This group is all the booleans that can turn the device off and block it from being turned on
outside_front_porch_lights_blocker_conditions:
entities:
- binary_sensor.halloween_night
automation:
# Turn the device on if any "on" condition and no "block" conditions are met
- alias: "outside_front_porch_lights_turn_on"
id: "outside_front_porch_lights_turn_on"
trigger:
- platform: state
entity_id: group.outside_front_porch_lights_on_conditions
to: 'on'
- platform: state
entity_id: group.outside_front_porch_lights_blocker_conditions
to: 'off'
- platform: state
entity_id:
- switch.front_porch_lights
from: 'unavailable'
to: 'off'
# - platform: homeassistant
# event: start
# - platform: event
# event_type: zwave.network_ready
condition:
- condition: state
entity_id: group.outside_front_porch_lights_on_conditions
state: 'on'
- condition: state
entity_id: group.outside_front_porch_lights_blocker_conditions
state: 'off'
action:
service: switch.turn_on
entity_id:
- switch.front_porch_lights
# Turn the device off if no "on" conditions are met, or if any "block" conditions are met
- alias: "outside_front_porch_lights_turn_off"
id: "outside_front_porch_lights_turn_off"
trigger:
- platform: state
entity_id: group.outside_front_porch_lights_on_conditions
to: 'off'
- platform: state
entity_id: group.outside_front_porch_lights_blocker_conditions
to: 'on'
- platform: state
entity_id:
- switch.front_porch_lights
from: 'unavailable'
to: 'on'
# - platform: homeassistant
# event: start
# - platform: event
# event_type: zwave.network_ready
condition:
- condition: or
conditions:
- condition: state
entity_id: group.outside_front_porch_lights_on_conditions
state: 'off'
- condition: state
entity_id: group.outside_front_porch_lights_blocker_conditions
state: 'on'
action:
service: switch.turn_off
entity_id:
- switch.front_porch_lights
…and again, it works perfectly most of the time but 1 or 2 days last week it just…didn’t turn off in the morning and logbook showed it was “turned on by” the turn_off automation.
A couple weeks ago it was the garage light, same deal (and same copy-paste replace the name code)