Hello,
I would like to share with you some automation that I’m using at home for the children’s bedtime, at 21:30 I dim the light and they know it’s time to go to sleep … and then at 22:00 begins the scenario of automatic light switch-off until 7:00 . It also notifies me when the light is on and off.
What happens in this scenario is that when the light is switched on, two events are triggered that activate two timers.
So you will need to configure two timers:
timer:
auto_off:
duration: 00:10:00
cancel_auto_off:
duration: 00:00:30
And then include in your configuration.yaml
automation: !include automation.yaml
which contains:
- id: Activates_automatic_light_switch_off
alias: Activates automatic light switch-off
trigger:
- platform: state
entity_id: switch.relay_switch
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: timer.cancel_auto_off
state: idle
- condition: time
after: 00:00:00
before: 07:00:00
action:
- service: notify.telegram
data_template:
title: "Child's Bedroom Light"
message: "Light has been turned on at ({{ now().strftime('%X') }})"
- service: timer.start
entity_id: timer.auto_off
- service: timer.start
entity_id: timer.cancel_auto_off
The first timer is used to automatically turn off the light after 10 minutes.
- id: automatic_light_switch_off
alias: Automatic light switch-off
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.auto_off
condition: []
action:
- service: switch.turn_off
data:
entity_id: switch.relay_switch
- service: notify.telegram
data_template:
title: "Child's Bedroom Light"
message: "Light has been turned off automatically at ({{ now().strftime('%X') }})"
The second timer is only intended to cancel the automatic switch-off if the light is switched on again in less than 30 seconds (i.e. if we switch it off and on again in less than 30 seconds).
- id: manual_light_switch_off
alias: Manual Light switch-off
trigger:
- platform: state
entity_id: switch.relay_switch
from: 'on'
to: 'off'
condition:
- condition: state
entity_id: timer.auto_off
state: active
action:
- service: notify.telegram
data_template:
title: "Child's Bedroom Light"
message: "Light has been turned off at ({{ now().strftime('%X') }})"
- service: timer.cancel
entity_id: timer.auto_off
data:
entity_id: timer.auto_off
- id: cancel_auto_switch_off
alias: Deactivate automatic light switch-off
trigger:
- platform: state
entity_id: switch.relay_switch
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: timer.cancel_auto_off
state: active
action:
- service: notify.telegram
data_template:
title: "Child's Bedroom Light"
message: "Automatic switch-off has been cancelled at ({{ now().strftime('%X') }})"
- service: timer.cancel
data:
entity_id: timer.auto_off
- service: timer.cancel
data:
entity_id: timer.cancel_auto_off
I see another use, it could be use in offices.
At 17:00 non essential lights are turned off (end of working day) but a switch or presence detector can turn it back on (there is always someone who takes longer to get out). After 10 minutes, it is switched off again, thus reminding workers that the day is over. This way we can be switching on and off automatically.
If you have to stay a long time because of overtime, you can cancel the automatic switch-off (switching off and on in less than 30 seconds)… This should be done by pressing the wall switch not by using the presence detector.
I hope you like those automation.