oh my god, this is exactly the setup i want to do in my bathroom because the lights turn off when i shower i dont want to put a 5 minute delay on a bathroom light…
thanks for posting
I’m suddenly interested in your light.tree_top
entity!
If interested, I have further refined this automation. Also I have another automation with the same switch and a hold action that turns of another full set of lights as a whole house night on/off.
- id: Bathroom_motion
alias: Bathroom motion
trigger:
############# maybe remove this to prevent excess triggers
# - platform: state
# entity_id: binary_sensor.motion_sensor_158d0001644ca3
# from:
# - 'on'
# to:
# - 'off'
- platform: state
entity_id: binary_sensor.motion_sensor_158d0001644ca3
from:
- 'off'
to:
- 'on'
- platform: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d0001e5f29e
click_type: "single"
# - platform: event
# event_type: xiaomi_aqara.click
# event_data:
# entity_id: binary_sensor.switch_158d0001e5f29e
# click_type: "double"
mode: single
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
- condition: time
after: '06:00:00'
before: '23:00:00'
- condition: state
entity_id: timer.bathroom_motion_short
state: 'idle'
sequence:
- service: light.turn_on
entity_id: group.bathroom_lights
data:
brightness: 254
- service: timer.start
entity_id: timer.bathroom_motion_long
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == 'on' }}"
- condition: state
entity_id: timer.bathroom_heat_tag
state: 'idle'
- condition: state
entity_id: input_boolean.notify_bathroom_tag
state: 'off'
- condition: time
after: '23:00:00'
before: '06:00:00'
sequence:
- service: light.turn_on
entity_id: light.bathroom_1,light.toolbox,light.sink,light.tree_top,light.lamp1
data:
brightness: 15
- service: timer.start
entity_id: timer.bathroom_motion_short
###################### test ##################
########## 1 click to turn off lights at night and finish short timer ##########
- conditions:
- condition: state
entity_id: timer.bathroom_motion_short
state: 'active'
- condition: state
entity_id: timer.bathroom_motion_long
state: 'idle'
- condition: state
entity_id: binary_sensor.switch_158d0001e5f29e
attribute: last_action
state: single
# - condition: template
# value_template: "{{ trigger.to_state.state == 'on' }}"
- condition: time
after: '23:00:00'
before: '06:00:00'
sequence:
# - service: light.turn_off
# entity_id: light.bathroom_1,light.toolbox,light.sink,light.tree_top,light.lamp1
- service: timer.finish
entity_id: timer.bathroom_motion_short
########## Single press to start short timer and turn on lights at night ##########
- conditions:
- condition: state
entity_id: timer.bathroom_motion_short
state: 'idle'
- condition: state
entity_id: timer.bathroom_motion_long
state: 'idle'
- condition: time
after: '23:00:00'
before: '06:00:00'
- condition: state
entity_id: binary_sensor.switch_158d0001e5f29e
attribute: last_action
state: single
sequence:
- service: light.turn_on
entity_id: light.bathroom_1,light.toolbox,light.sink,light.tree_top,light.lamp1
data:
brightness: 15
- service: timer.start
entity_id: timer.bathroom_motion_short
###################################################
- id: Bathroom_long_timer_expired
alias: Bathroom long timer expired
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.bathroom_motion_long
condition:
condition: template
value_template: >
{{ not is_state('timer.bathroom_heat_tag','active') }}
action:
- service: light.turn_off
entity_id: group.bathroom_lights
- id: Bathroom_short_timer_expired
alias: Bathroom short timer expired
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.bathroom_motion_short
action:
- choose:
- conditions:
- condition: time
after: '06:00:00'
before: '23:00:00'
sequence:
- service: light.turn_off
entity_id: group.bathroom_lights
- conditions:
- condition: time
after: '23:00:00'
before: '06:00:00'
sequence:
- service: light.turn_off
entity_id: group.bathroom_lights,light.tree_top,light.sink,light.lamp1