I’m looking for a way to automate some stair lights. I’ll have motion detectors in the stairway, I’d like the stair lights to turn on when motion is detected and off when motion stops. BUT, if the stair lights are turned on using the wall switch I’d like them to stay on regardless of the motion detectors turning on/off.
I haven’t picked a smart switch yet, but would prefer a switch with ESPhome, I’d consider Zwave if needed.
Is there someway to differentiate in HA when a wall switch his used to turn the light on? If so, I figure I could set a template binary sensor to “on” when the wall switch is used and set a condition that the template sensor needs to be “off” for the motion activated lights.
To accomplish something similar, I’ve taken advantage of the zwave scenes available in my Inovelli dimmers and switches. When an occupant manually hits a switch it triggers a zwave scene event. I use this event to start a timer. In any automations that would turn this light on or off I have a condition that checks if the timer is idle.
This is the automation to start the light in use timer.
- id: zwave_side_entrance_light_1D1U
alias: "[ZWave] Side Entrance Light 1D1U"
description: "Respond to light switch 1X Down or 1X Up command."
initial_state: true
mode: single
trigger:
- platform: event
event_type: zwave.scene_activated
event_data:
entity_id: zwave.side_entrance_light
scene_data: 7680
scene_id: 1
- platform: event
event_type: zwave.scene_activated
event_data:
entity_id: zwave.side_entrance_light
scene_data: 7680
scene_id: 2
action:
- service: timer.start
entity_id: timer.side_entrance_light
This is the condition present in any automation that alters the state of this light. If the timer is active, the automation will not trigger.
- condition: state
entity_id: timer.side_entrance_light
state: idle
I have a couple of WIFI lights where zwave scenes are not available. On these lights, I have an automation that starts the timer any time the light state is changed. When an automation is changing the light state (say when the sun comes up) I turn off the timer trigger automation before changing the light state so the timer will not start, since it wasn’t the occupant that turned the light on/off.
- id: light_living_room_pot_lights_in_use
alias: "[Light] Living Room Pot Lights In Use"
description: "Turn in use timer on when device state changes."
initial_state: true
mode: restart
trigger:
- platform: state
entity_id: light.living_room_pot_lights
action:
- service: timer.start
data:
entity_id: timer.living_room_pot_lights
This is an example code excerpt where an automation is controlling the light.
# turn off automation so we don't trigger device in use timers
- service: automation.turn_off
entity_id: automation.light_living_room_pot_lights_in_use
- choose:
- conditions:
- condition: state
entity_id: timer.living_room_pot_lights
state: idle
sequence:
- service: light.turn_on
data:
entity_id: light.living_room_pot_lights
brightness: 20
- service: automation.turn_on
entity_id: automation.light_living_room_pot_lights_in_use
I like where you are going here. Basically, I can tell HA if the motion is triggered AND the light is off when the motion is triggered turn on a template binary sensor. If that template binary sensor is “on” then turn off the lights when the motion stops. Also, when the lights turn off, turn off that template sensor. But if the lights are turned on with the wall switch the template sensor remains off which will prevent the motion stop trigger from turning off the lights Do I have that right?
If you replace every single instance where you typed template sensor and replaced it with input boolean, what you have described here will accomplish what you are looking for. I used a timer instead of an input boolean because I want my lights to resume “automating” automatically after a set period (it differs for every light). It sounds like you don’t want that so an input boolean would be the way to go.
Node-red is the answer here. I have the same as you, motion controlling a light. But then I also have a scene of my Inovelli switches. I just assigned a traffic light that prevent the motion to controlling anymore, and then you can make it do WHATEVER you want.
So, for Jasco Z-Wave switches at least, there is a simple answer. These devices send a “Central Scene Action” when physically pressed — and this isn’t triggered by changing the on/off state remotely. So, you don’t need anything fancy in your automations. Just trigger on this.
On my switches, “Endpoint 0 Scene 001” is the on paddle and “Endpoint 0 Scene 002” is off. And you can respond to a single press (or release), as well as long press (hold) or double and triple clicks. (Be careful with those, though — don’t want to accidentally factory-reset the switch!)