Control light based on time of day boolean, motion ánd wake/sleep boolean. Can’t get it to work completely!
Hi all! I really appreciate your help on an automation I’ve been struggling with.
So the situation is:
- There’s a kitchen light: light.licht_keuken.
- There are 3 binary sensors created using the ToD (Time of Day) platform: binary_sensor.dag, binary_sensor.avond & binary_sensor.nacht (day, evening & night).
- There’s an automation that toggles Time of Day input booleans based on the ToD binary sensors: input_boolean.dag, input_boolean.avond & input_boolean.nacht.
- There’s an automation that entrains the Time of Day input booleans so that only one at a time can be active.
- There’s a wake/sleep input boolean that’s triggered when I tell Google goodnight: input_boolean.wake_sleep.
- There are 2 lighting scenes: Keuken dag & Keuken nacht (this one makes the light red).
- There’s a PIR in the kitchen: binary_sensor.pir_04_keuken_presence.
What I want to achieve is the following:
- When input_boolean.dag turns on in the morning I want the light to turn on using scene Keuken dag.
- I want the light to remain on until OR input_boolean.nacht is turned on (at 23h) OR input_boolean.wake_sleep is turned on (= sleep) when I decide to go to bed early.
- When the light is off AND input_boolean.wake_sleep is on (= sleep) AND motion is detected by binary_sensor.pir_04_keuken_presence, I want the light to turn on scene Keuken nacht.
- IF input_boolean.wake_sleep is not triggered (= wake), BUT input_boolean.nacht is on AND motion is detected by binary_sensor.pir_04_keuken_presence I want the light to turn on scene Keuken dag.
- When input_boolean.nacht is on AND there’s no more motion detected I want the light to turn of after 5 minutes.
What’s working?
- Step 1: in the morning the light turns on
- Step 2: partially; toggling input_boolean.wake_sleep to on makes the light turn off BUT toggling input_boolean.nacht doesn’t turn the light on, more on that in a second.
- Step 3: motion in the kitchen turns on scene Keuken nacht when input_boolean.nacht is on AND input_boolean.wake_sleep is on.
What doesn’t work?
- Step 2: when input_boolean.wake_sleep is not triggered (so I’m still awake) and input_boolean.nacht is turned on the light stays on (while it should turn of) BUT when only when motion is detected it turns off (?!)
- Step 4: related to step 2; in stead of turning on, the light turns off when input_boolean.wake_sleep is off (= wake), input_boolean.nacht is on AND motion is detected by binary_sensor.pir_04_keuken_presence.
I’ve made an automation using the choose option. You can find it here:
alias: Keuken verlichtingdescription: ''trigger: - platform: state e - Pastebin.com
When checking the trace I notice that when input_boolean.wake_sleep is off, input_boolean.nacht is on AND motion is detected the light turns off (using option 3). But motion isn’t a condition in this option.
What it should do is be turned off just because input_boolean.nacht is turned on, not because of motion. So now it stays on even after 23h until motion is detected.
And it should turn back on when motion is detected AND input_boolean.wake_sleep is off AND input_boolean.nacht is on (when I’m still awake after 23h and grabbing a drink).
You’ll probably going to tell me to use NodeRed, but I’m not ready for that yet
Hope you can check my automation to see what’s wrong!
Thanks in advance.
alias: Keuken verlichting
description: ''
trigger:
- platform: state
entity_id: input_boolean.dag
to: 'on'
- platform: state
entity_id: input_boolean.avond
to: 'on'
- platform: state
entity_id: input_boolean.nacht
to: 'on'
- type: motion
platform: device
device_id: 56629fe7fb3b03879235bcf6c3a7b3a8
entity_id: binary_sensor.pir_04_keuken_presence
domain: binary_sensor
- type: no_motion
platform: device
device_id: 56629fe7fb3b03879235bcf6c3a7b3a8
entity_id: binary_sensor.pir_04_keuken_presence
domain: binary_sensor
for:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.dag
state: 'on'
sequence:
- scene: scene.keuken_dag
- service: input_boolean.turn_off
target:
entity_id: input_boolean.wake_sleep
data: {}
- conditions:
- condition: state
entity_id: input_boolean.avond
state: 'on'
- condition: state
entity_id: binary_sensor.wake_sleep
state: 'off'
sequence:
- scene: scene.keuken_dag
- conditions:
- condition: state
entity_id: input_boolean.nacht
state: 'on'
for:
hours: 0
minutes: 0
seconds: 0
- condition: state
entity_id: input_boolean.wake_sleep
state: 'off'
sequence:
- type: turn_off
device_id: ea091450ba657bf78026f06245589129
entity_id: light.licht_keuken
domain: light
- conditions:
- condition: state
entity_id: input_boolean.nacht
state: 'on'
- condition: state
entity_id: input_boolean.wake_sleep
state: 'off'
- type: is_motion
condition: device
device_id: 56629fe7fb3b03879235bcf6c3a7b3a8
entity_id: binary_sensor.pir_04_keuken_presence
domain: binary_sensor
- condition: device
type: is_off
device_id: ea091450ba657bf78026f06245589129
entity_id: light.licht_keuken
domain: light
sequence:
- scene: scene.keuken_dag
- conditions:
- condition: state
entity_id: input_boolean.nacht
state: 'on'
- condition: state
entity_id: input_boolean.wake_sleep
state: 'on'
- type: is_motion
condition: device
device_id: 56629fe7fb3b03879235bcf6c3a7b3a8
entity_id: binary_sensor.pir_04_keuken_presence
domain: binary_sensor
sequence:
- scene: scene.keuken_nacht
- conditions:
- type: is_no_motion
condition: device
device_id: 56629fe7fb3b03879235bcf6c3a7b3a8
entity_id: binary_sensor.pir_04_keuken_presence
domain: binary_sensor
for:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- condition: state
entity_id: input_boolean.wake_sleep
state: 'off'
- condition: state
entity_id: input_boolean.nacht
state: 'on'
sequence:
- type: turn_off
device_id: ea091450ba657bf78026f06245589129
entity_id: light.licht_keuken
domain: light
- conditions:
- type: is_no_motion
condition: device
device_id: 56629fe7fb3b03879235bcf6c3a7b3a8
entity_id: binary_sensor.pir_04_keuken_presence
domain: binary_sensor
for:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- condition: state
entity_id: input_boolean.wake_sleep
state: 'on'
sequence:
- type: turn_off
device_id: ea091450ba657bf78026f06245589129
entity_id: light.licht_keuken
domain: light
default: []
mode: single
Trace:
UI screenshot: https://i.imgur.com/7sRqOwj.png