Hi all,
I am trying to create a light notification when someone presses the doorbell. The automation should save the current state of the light, flash it light 2 times and finally reload the initial state.
The only problem that I am facing with it is that if the light is off, my āsave stateā creating a scene doesnāt work, as it will create a blank scene and when turn the lamp on ti will be set to the notification color and brightness (red, 100%).
Is it possible to only create the scene if the lamp is on using automation or do I need to learn how to do templates and scripts?
I was trying to solve everything in just one automation. However, I got the feeling that the automation guideline is to have multiple simpler ones, for a single use case, than having just a complex one with multiple tests in it.
I ended up duplicating the automation and adding a condition check for light on in one and light of in the other.
Automation when the light is already on:
- id: 'zzzzzzzzzzz1'
alias: Flash Office Floor Lamp lights red when the doorbell is pressed (Light On)
description: Flash Office Floor Lamp lights red 2 times when the doorbell is pressed.
This will save the state of the light that is on.
trigger:
- platform: device
device_id: xxxxxxxxxxxxx
domain: nest
type: doorbell_chime
condition:
- condition: device
type: is_on
device_id: yyyyyyyyyyyyy
entity_id: light.office_floor_lamp_level_light_color_on_off
domain: light
action:
- data:
scene_id: save_state_office_floor_lamp
snapshot_entities: light.office_floor_lamp_level_light_color_on_off
service: scene.create
- scene: scene.office_floor_lamp_red
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 750
- repeat:
count: '4'
sequence:
- type: toggle
device_id: yyyyyyyyyyyyy
entity_id: light.office_floor_lamp_level_light_color_on_off
domain: light
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- data: {}
service: scene.turn_on
target:
entity_id:
- scene.save_state_office_floor_lamp
mode: single
Automation when the light is off:
- id: 'zzzzzzzzzzz2'
alias: Flash Office Floor Lamp lights red when the doorbell is pressed (Light Off)
description: Flash Office Floor Lamp lights red 2 times when the doorbell is pressed.
This doesn't save the last state as the light is off and reused the previously saved scene.
trigger:
- platform: device
device_id: xxxxxxxxxxxxx
domain: nest
type: doorbell_chime
condition:
- condition: device
type: is_off
device_id: yyyyyyyyyyyyy
entity_id: light.office_floor_lamp_level_light_color_on_off
domain: light
action:
- scene: scene.office_floor_lamp_red
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 750
- repeat:
count: '04'
sequence:
- type: toggle
device_id: yyyyyyyyyyyyy
entity_id: light.office_floor_lamp_level_light_color_on_off
domain: light
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 500
- data: {}
service: scene.turn_on
target:
entity_id:
- scene.save_state_office_floor_lamp
- type: turn_off
device_id: yyyyyyyyyyyyy
entity_id: light.office_floor_lamp_level_light_color_on_off
domain: light
mode: single