Although I’ve used HA for a while now, I haven’t put together many automations and I can’t quite work out how to complete the one I am currently working on.
The setup involves 3 devices in one room - a Philips Hue Smart bulb, a Philips Hue Motion sensor, and an Aqara smart button.
I currently have 2 automations using the bulb and the motion sensor, and this works correctly. The bulb turns on via automation1 if motion is detected (occupancy input_bool is ‘on’ when motion detected) AND if the light level is below 40lux. If no motion is detected for 2 minutes, the input_bool changes to ‘off’ and the bulb turns off again via automation2.
With the new Aqara smart switch button, I am trying to replace the manual wall light switch, and allow users to ‘override’ the motion sensor temporarily while they are in the room. I’ve searched and can’t find this exact scenario on here, so am looking for a little help please.
Desired scenario:
Light automatically comes on upon entering room, but you want the light to be off until you’ve left the room.
Trigger: Single button press
Condition: If the light state is already ‘on’
Action: Set the light state to ‘off’ and disable the ‘motion-triggered-light-on’ automation until no motion is detected for at least 2 minutes
If the light hasn’t turned on automatically upon entering the room (lux level too low high for example), turn the light on
Trigger: Single button press
Condition: If the light state is ‘off’
Action: Set the light state to ‘on’ and stay on until occupancy input-bool turns off. I don’t want the light to turn back off if lux levels are still above the automation threshold, but this should be ok i believe as movement will still be detected regardless.
I was thinking about creating another input-bool helper that gets set to ‘on’ when manually overriding the motion automation and turning the light off. Bu then in order for the motion automation to remain disabled during the override, I could add this new helper as a condition for the motion activation and state that it must be off for the normal motion automation to work. But then once this new helper input_bool is turned off, how could I turn it back off again after there has been no movement for 2 minutes? This is the part that I’m struggling with.
Can anyone help me with the automation to cover these scenarios please?
Automation code for the new Aqara button so far:
alias: Room Smart Button
description: ""
trigger:
- platform: state
entity_id:
- sensor.room_button_action
to: single
id: single
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: single
- condition: state
entity_id: light.room_light
state: "off"
sequence:
- service: light.turn_on
data:
brightness_pct: 30
target:
device_id: c0a0fb1a1ebb981e9e7385a9147f1d5c
- conditions:
- condition: state
entity_id: light.room_light
state: "on"
sequence:
- service: light.turn_off
data: {}
target:
device_id: c0a0fb1a1ebb981e9e7385a9147f1d5c
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.room_light_override ### Haven't created this yet or included it in the original motion automation as a condition ###
mode: single
@GlennHA Yes it’s as I described, but not very clearly - let me try again - so you walk into the room and the light turns on automatically like normal, however you don’t want it to be on on this one occasion (headache for example!) so you push the button to turn the light off. You want the light to remain off for the duration of your occupancy, and then once movement hasn’t been detected for at least 2 minutes i.e you have left the room, the motion activation kicks back in ready for the next person that does into the room. Hopefully that makes sense.
That portion is actually easier than keeping the lights on.
You want the trigger to be a change from off to on; if the light is turned off manually, then light will not turn back on until there is a period of no motion and then motion happens again.
Thanks - are you able to help with either how the Automation in the UI should be set out, or the Automation yaml should look (what I need to add or change in my above code) to cater for both of my scenarios described please?
I could, but I’m a little rusty for automation inside HA. I’ve been doing my automations with Node-Red for awhile now. Do a search in ‘blueprints’ someone may have done this for you already.
I did wonder about learning about Node-Red as I may be able to visualise things a bit better building it that way, but that would be another learning curve which is all I seem be have been facing recently!
Can anyone else help out with the motion sensor override part in the meantime?
Well I finally figured out a way of achieving most of what I want with this. I’ve had to compromise slightly and change my plan but testing has gone well. I’ve removed the condition of ‘lux’ threshold for the light to come on with the motion sensor, as this seemed to be getting in the way, so instead, the light always comes on when entering the room now. If you decide you don’t want the light on, you can press the button which turns the light off. The light will stay off until motion hasn’t been detected for at least 2 minutes and then the motion sensor becomes active again ready to tun the light on.
This removes the requirement to be able to turn the light on manually if it doesn’t come on due to lux level being too high etc.
There may be other ways to achieve keeping the lux threshold condition involved, and there may be more concise ways of achieving this in Node-Red for example, but these 5 automations are what I have put together and it works well as a solution for my needs:
- id: '1666529349657'
alias: Room Occupancy
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.motion_sensor_occupancy
to: 'on'
id: 'on'
- platform: state
entity_id:
- binary_sensor.motion_sensor_occupancy
to: 'off'
id: 'off'
for:
hours: 0
minutes: 2
seconds: 0
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.motion_sensor_occupancy
state: 'on'
sequence:
- service: input_boolean.turn_on
entity_id: input_boolean.is_someone_in_room
data: {}
- conditions:
- condition: state
entity_id: binary_sensor.motion_sensor_occupancy
state: 'off'
sequence:
- service: input_boolean.turn_off
entity_id: input_boolean.is_someone_in_room
data: {}
mode: single
- id: '1666534631095'
alias: Room Light On
description: ''
trigger:
- platform: state
entity_id:
- input_boolean.is_someone_in_room
to: 'on'
condition:
- condition: state
entity_id: input_boolean.room_light_override
state: 'off'
action:
- service: light.turn_on
data: {}
target:
device_id: c0a0fb1a1ebb981e9e7385a9147f1d5c
mode: single
- id: '1666793725377'
alias: Room Light Off
description: ''
trigger:
- platform: state
entity_id:
- input_boolean.is_someone_in_room
to: 'off'
for:
hours: 0
minutes: 0
seconds: 0
condition: []
action:
- service: light.turn_off
data: {}
target:
device_id: c0a0fb1a1ebb981e9e7385a9147f1d5c
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.room_light_override
mode: single
- id: '1672930043986'
alias: Room Override ON
description: ''
trigger:
- platform: state
entity_id:
- sensor.room_button_action
to: single
id: single
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: single
- condition: state
entity_id: light.room_light
state: 'off'
sequence:
- service: light.turn_on
data:
brightness_pct: 30
target:
device_id: c0a0fb1a1ebb981e9e7385a9147f1d5c
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.room_light_override
- conditions:
- condition: state
entity_id: light.room_light
state: 'on'
sequence:
- service: light.turn_off
data: {}
target:
device_id: c0a0fb1a1ebb981e9e7385a9147f1d5c
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.room_light_override
mode: single
- id: '1673699241003'
alias: Room Override OFF
description: ''
trigger:
- platform: state
entity_id:
- input_boolean.is_someone_in_room
for:
hours: 0
minutes: 0
seconds: 0
to: 'off'
condition: []
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.room_light_override
mode: single
Hopefully this will be of use to someone searching for the same sort of solution - obviously I welcome any improvements/suggestions to consolidate or achieve the same result in a ‘better’ way!