I have an aqara fp2 setup where the dining room lights should turn off when it isn’t occupied but whenever the wife turns it on with a voice command, it doesn’t turn off the lights. Is that how it’s supposed to work? I have two triggers for this automation, one is when its occupied and one when its not occupied. Not trying to change it but I just want to confirm if that’s how most automations work with HA? New to the game.
Definitely NOT.
Best to post your automation so we can see what is going wrong.
Sorry I’m new to HA and I don’t know how they post YAML codes nicer and with colors so I just copied this from clipboard. Also I don’t edit with YAML.
alias: Dining Room Lights Occupied Toggle
description: ""
trigger:
- type: occupied
platform: device
device_id: 5d8daa154878c6283428eb2be6958d07
entity_id: 535d904efc97a35068ae8901ccd0f172
domain: binary_sensor
id: Dining-on
- type: not_occupied
platform: device
device_id: 5d8daa154878c6283428eb2be6958d07
entity_id: 535d904efc97a35068ae8901ccd0f172
domain: binary_sensor
id: Dining-off
for:
hours: 0
minutes: 0
seconds: 30
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Dining-on
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.dining_room_switch
- conditions:
- condition: trigger
id:
- Dining-on
- Dining-off
sequence:
- service: light.turn_off
data: {}
target:
entity_id: light.dining_room_switch
mode: single
Thank you! Now I’ll be able to post codes properly.
Cool.
Now there’s a few things you should fix in that:
Firstly, change from using ‘device’ triggers, to ‘entity-id’ triggers as this will be much less painful in the future if you swap out a device, of if the device is unavailable.
Secondly, change the mode to ‘restart’.
The reason your light isn’t turning off looks to me because you have the trigger condition set as both dining-on & dining-off. If you make the ‘off’ part of the automation only have the dining-off trigger condition it should work I think.
Thanks for the advice! I will start changing devices to entity id. Regarding the automation though, I do not mind that it doesn’t turn off whenever my wife uses voice command. I actually made it to be triggered by 2 devices in order to turn off the lights thinking that maybe turning the lights on from the switch won’t trigger the turn off automation.
My living room on the other hand doesn’t have to be triggered by 2 entity id and yet it behaves the same way of my dining room lights
alias: Living Room Occupied
description: ""
trigger:
- type: occupied
platform: device
device_id: 5d8daa154878c6283428eb2be6958d07
entity_id: ca4edbfe053f701e7de8711214b315f5
domain: binary_sensor
id: Sofa-on
- type: not_occupied
platform: device
device_id: 5d8daa154878c6283428eb2be6958d07
entity_id: ca4edbfe053f701e7de8711214b315f5
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 30
id: Sofa-off
condition:
- condition: time
after: "16:30:00"
before: "03:00:00"
weekday:
- sun
- mon
- tue
- wed
- thu
- fri
- sat
action:
- choose:
- conditions:
- condition: trigger
id:
- Sofa-on
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.living_room_switch
- conditions:
- condition: trigger
id:
- Sofa-off
sequence:
- service: light.turn_off
data: {}
target:
entity_id: light.living_room_switch
mode: single
Yes, that’s fine, but having two opposing conditions makes no sense. You are telling it to turn OFF the light if the trigger is either DINING-ON or DINING-OFF…but at the same time telling it to turn the same light ON if the trigger is also DINING-ON. I fail to see how that works properly at all.
Here’s how I control my lights based on presence, with zero issues at all. Lights never accidently turn off on me and only turn on if the light level is low enough (ie: at night or if blinds are closed etc.)
- id: f4e1bb68-319b-4183-a83b-07ae397420ae
alias: 'Kitchen downlights auto'
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.kitchen_ms6_home_security_motion_detection
from: 'off'
to: 'on'
- platform: state
entity_id: binary_sensor.kitchen_presence_occupancy
from: 'off'
to: 'on'
condition:
condition: or
conditions:
- condition: template
value_template: "{{ states('sensor.kitchen_ms6_illuminance') | int(0) < states('input_number.kitchen_min_lux') | int(1) }}"
- condition: state
entity_id: light.kitchen_light_level
state: 'on'
action:
- service: light.turn_on
data:
entity_id: light.kitchen_light_level
brightness_pct: "{{ state_attr('switch.adaptive_lighting_kitchen', 'brightness_pct') | int(100) }}"
- wait_template: "{{ is_state('binary_sensor.kitchen_presence', 'off') }}"
timeout: '01:00:00'
- delay: '00:00:30'
- condition: and
conditions:
- condition: state
entity_id: light.kitchen_light_level
state: 'on'
- service: light.turn_on
data:
entity_id: light.kitchen_light_level
brightness_pct: "{{ state_attr('switch.adaptive_lighting_kitchen', 'brightness_pct') /2 | int(100) }}"
- delay: '00:0{{ states.input_number.kitchen_light_auto_off_time.state | int(1) }}:00'
- service: light.turn_off
entity_id: light.kitchen_light_level
There’s a ‘staged’ off routine in there because the dimmer doesn’t support transitions.
Thanks! I thought about playing around the light levels, I will definitely work on it when I get some more time. Could you explain me what restart mode does? I googled it but I feel like I still don’t understand, does it restart the automation whenever it gets triggered?
Exactly.
So in your case where you have a waiting time of 30 seconds for the not_occupied
trigger and someone was to walk into the room, mode: restart
will ensure that 30 seconds is reset and the occupied
trigger will fire again. Now, since you don’t have a delay timer in there and you are purely relying on the presence sensor and the 30 seconds on the trigger, you likely won’t see a difference, however you can do it differently, like mine where I use a delay for OFF, but will re-trigger if motion/presence is detected again. For me this works better, especially in a kitchen where I could be in and out quickly in a short period.
That would make my automation a lot better! Thanks for the help, I learned a lot!