after doing simple stuff, i am ready to do something more complex.
1- when motion near dining table, turn lights on to 100% brightness. if no motion within 10 mins, turn lights off.
2- when front door is open after 7pm, turn lights on to 30% brightness. turn off after 5 minutes
3- IF someone is already moving as in step 1, ignore step 2 when front door is open.
4- OR if i open the door, turn to 30% brightness and increase to 100% when i step near dining room. turn off after 10 minutes if no motion.
i can set up step 1 and 2. but how to implement step 3? or is HA smart enough to do resolve conflicting automation?
i think i can do step 4.
The automation logic is simplified if you change step 3 to this:
3 - If the light is already on, ignore step 2 when front door is open.
The idea here is that if someone is already moving within range of the motion sensor, the light will be on (100%). If you arrive home, open the front door, and the light is already on, there’s no need to turn it on. However, if you arrive home and the light is off, then the light will be turned on to 30%.
The moment you walk within range of the motion sensor, the light’s brightness will be increased to 100%.
yes, you read my mind. this is exactly what i want. when no one is home, just turn light on 30% when front door is opened because i will walk to the 2nd floor. and shut off 5 mins because no one will be downstairs.
so the 4 rules i listed will be 4 automations or can they all be squeezed into 1 automation? hehe
The fourth rule is actually just the first and second rules in operation.
You open the front door, the light is currently off, it gets turned on to 30% (rule 2).
You walk in, get detected by the motion sensor, the light is turned on to 100% (rule 1).
Basically, 2 or 3 automations can achieve your requirements.
- id: '1570209701939'
alias: auto light on living room when there is movement in living_room
trigger:
- platform: state
entity_id: binary_sensor.motion
to: 'on'
condition:
- after: '10:00:00'
condition: time
action:
- service: homeassistant.turn_on
data:
entity_id:
- light.zooz_zen22_dimmer_v2_level
brightness_pct: 100
- service: timer.start
data:
entity_id: timer.living_room
- id: '1570211808181'
alias: auto light off living room 10 minutes after trigger
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.living_room
action:
service: homeassistant.turn_off
data:
entity_id:
- light.zooz_zen22_dimmer_v2_level
my rule for #2 is:
- id: '1570648352848'
alias: auto light on when Front door opens
trigger:
- platform: state
entity_id: binary_sensor.front_door
to: 'on'
condition:
- after: '10:00:00'
condition: time
action:
- service: homeassistant.turn_on
data:
entity_id:
- light.zooz_zen22_dimmer_v2_level
brightness_pct: 30
- service: timer.start
data:
entity_id: timer.front_door
- id: '1570648499221'
alias: auto light off Front door after 3 minutes
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.front_door
action:
service: homeassistant.turn_off
data:
entity_id:
- light.zooz_zen22_dimmer_v2_level
i have no idea how to implement #3. as of now, if someone is already in the living room, when front door opens, it will dim the light down to 30% AND turn off after 3 minutes.
there is a problem with #4 as well. the lights will switch off after 3 minutes instead of the desired 10 minutes.
The following version of your automations contains revisions:
Uses one timer (timer.living_room) and the automations set its duration (either 10 or 3 minutes, as required).
Only one automation is needed to turn off the light after the timer expires.
The automation handling the front door has an additional condition that requires the light to be off before the action is allowed to be performed.
- id: '1570209701939'
alias: auto light on living room when there is movement in living_room
trigger:
- platform: state
entity_id: binary_sensor.motion
to: 'on'
condition:
- condition: time
after: '10:00:00'
action:
- service: light.turn_on
data:
entity_id: light.zooz_zen22_dimmer_v2_level
brightness_pct: 100
- service: timer.start
data:
entity_id: timer.living_room
duration: '00:10:00'
- id: '1570211808181'
alias: auto light off living room X minutes after trigger
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.living_room
action:
service: light.turn_off
entity_id: light.zooz_zen22_dimmer_v2_level
- id: '1570648352848'
alias: auto light on when Front door opens
trigger:
- platform: state
entity_id: binary_sensor.front_door
to: 'on'
condition:
- condition: time
after: '10:00:00'
- condition: state
entity_id: light.zooz_zen22_dimmer_v2_level
state: 'off'
action:
- service: homeassistant.turn_on
data:
entity_id: light.zooz_zen22_dimmer_v2_level
brightness_pct: 30
- service: timer.start
data:
entity_id: timer.living_room
duration: '00:03:00'
i think your code is working although i have not verify all the scenarios. when reading through, it does make sense.
i still need this code in configuration.yaml correct?
timer:
living_room:
duration: '00:10:00'
i did try without declaring timer.living_room in the config file and the lights never turn off. i assumed i did not need because you wrote in auto.yaml file already.
another oddity i noticed is how the timer counts down. for example, if i walk by the motion sensor at 11:25am, timer starts countdown from 10 mins. when i walk by again at 11:28am, i still see the countdown from 11:25am. i thought the timer would reset back to 10 mins when i walk by at 11:28. at 11:36, i would see timer as active as seen here:
The timer does reset (lights go off at 11:28 + 00:10 = 11:38) but, as you’ve seen, the Lovelace UI’s presentation of the timer’s state isn’t exactly correct (a known problem). To check the current state of timer.living_room, use: Developer Tools > States