I haven’t seen that changes my LED strip lights red.
I have created an automation that calls my scene. I’d like to return the lights to the previous state when the door is closed.
What’s a good method to do this?
You can create scenes on the fly and then restore back to a previous state
This script flashes my ensuite lights green which I activate if someone presses the doorbell:
script:
doorbell_flash_ensuite_light:
sequence:
- condition: state
entity_id: light.ensuite_lights
state: 'on'
- service: scene.create
data:
scene_id: ensuite_lights_snapshot
snapshot_entities:
- light.ensuite_led_strip
- light.ensuite_downlight
- service: light.turn_on
data:
entity_id: light.ensuite_downlight
brightness: 255
rgb_color: [0,255,0]
white_value: 0
- delay: '00:00:02'
- service: light.turn_off
entity_id: light.ensuite_downlight
- delay: '00:00:01'
- service: light.turn_on
data:
entity_id: light.ensuite_downlight
brightness: 255
rgb_color: [0,255,0]
white_value: 0
- delay: '00:00:02'
- service: scene.turn_on
data:
entity_id: scene.ensuite_lights_snapshot
You could incorporate a similar action in your automation
Thanks @sparkydave
Editing yours to suit, I am getting a Missing property “action” warning on line 1 next to script
script:
garage_door_open_close:
sequence:
- condition: state
# entity_id: light.ensuite_lights
entity_id: light.rope_lights
state: 'on'
- service: scene.create
data:
# scene_id: ensuite_lights_snapshot
scene_id: rope_lights_snapshot
snapshot_entities:
# - light.ensuite_led_strip
# - light.ensuite_downlight
- light.rope_lights
- service: light.turn_on
data:
# entity_id: light.ensuite_downlight
entity_id: light.rope_lights
brightness: 255
rgb_color: [255,0,0]
white_value: 0
- delay: '00:00:02'
- service: light.turn_off
# entity_id: light.ensuite_downlight
entity_id: light.rope_lights
- delay: '00:00:01'
- service: light.turn_on
data:
# entity_id: light.ensuite_downlight
entity_id: light.rope_lights
brightness: 255
rgb_color: [255,0,0]
white_value: 0
- delay: '00:00:02'
- service: scene.turn_on
data:
# entity_id: scene.ensuite_lights_snapshot
entity_id: scene.rope_lights_snapshot
Scripts don’t have an action, have you put this under automation: erroneously?
As per what Marc has said, it is likely due to where you saved the code. You can use the functions in an automation action instead of a script. I use a script because my doorbell fires off many scripts which each have particular conditions which must be met in order to run. Its my work-around for the fact that HA does not allow ‘nested’ conditions within its actions.
Also, you may need to be careful with your lights using the same code as me. Mine are odd in that the downlight is RGB and the LED strip is RGBW, hence the white value for one of them. This will depend on your particular light type
Thanks both… exactly what that problem was… I had it in the automations rather than scripts yaml.
I ran script check and got this new error
Missing property “sequence” on line 1 and Property garage_door_open_close is not allowed
Here is line 36 of my configuration.yaml
Failed config
script:
- Invalid config for [script]: [garage_door_open_close] is an invalid option for [script]. Check: script->script->script->garage_door_open_close. (See /tmp/config/configuration.yaml, line 36).
script:
garage_door_open_close:
sequence:
- condition: state
# entity_id: light.ensuite_lights
entity_id: light.rope_lights
state: 'on'
- service: scene.create
data:
# scene_id: ensuite_lights_snapshot
scene_id: rope_lights_snapshot
snapshot_entities:
# - light.ensuite_led_strip
# - light.ensuite_downlight
- light.rope_lights
- service: light.turn_on
sequence:
is not valid in an automation, only in a script. It isn’t required in an automation action
Isn’t this a script? I’m confused.
It is a script, but didn’t you put it under automation:
?
Post your actual code rather than screenshots and we can fix it up
thanks Dave… Sorry to be such a noob
I did originally put it under automation but moved to script after it was pointed out.
Here is the script as it is now under script. this is everything in my script.yaml
I am trying to get this to fire when Entity ID: binary_sensor.garage_door_sensor_open_close opens and closes
script:
garage_door_open_close:
sequence:
- condition: state
entity_id: light.rope_lights
state: 'on'
- service: scene.create
data:
scene_id: rope_lights_snapshot
snapshot_entities:
- light.rope_lights
- service: light.turn_on
data:
entity_id: light.rope_lights
brightness: 255
rgb_color: [255,0,0]
white_value: 0
- delay: '00:00:02'
- service: light.turn_off
entity_id: light.rope_lights
- delay: '00:00:01'
- service: light.turn_on
data:
entity_id: light.rope_lights
brightness: 255
rgb_color: [255,0,0]
white_value: 0
- delay: '00:00:02'
- service: scene.turn_on
data:
entity_id: scene.rope_lights_snapshot
Because it’s in script.yaml you don’t use script:
at the top. Comment that out (#) and give it a test. It should be good then. The reason I have script:
in mine is because it’s in a Package.
You need an automation that calls the below script in the action part.
Thanks Guys… Sooo close.
I’ve commented out "Script: on line 1 and set up two automations to fire the script (See below)
I set the lights to green for testing…
When the door opens, the strip lights turn red then white then red then green.
When the door closes, nothing happens
I expected the lights to stay red while the door is open and return to green (or previous state) when the door closed
automations.yaml
- id: '1593875523349'
alias: Garage Door Open Red
description: ''
trigger:
- device_id: 1d0e50dee10a4c6cbf1a19deadee6e61
domain: binary_sensor
entity_id: binary_sensor.garage_door_sensor_open_close
platform: device
type: opened
condition: []
action:
- data: {}
service: script.garage_door_rope_lights
- id: '1593876528697'
alias: Garage Door Closed Previous State
description: ''
trigger:
- device_id: 1d0e50dee10a4c6cbf1a19deadee6e61
domain: binary_sensor
entity_id: binary_sensor.garage_door_sensor_open_close
platform: device
type: not_opened
condition: []
action:
- data: {}
service: script.garage_door_rope_lights
Do I need to split this into two scripts and call one for opening and the other for closing the door?
No necessarily, but I would code it differently… What is the goal of the light control in simple terms? Do you want it to trigger on both opening and closing? In your first post it seemed you just wanted to switch on the lights to red when the door opens, then back to the previous state when the door closes…?
oh yeah… reading my original post, i wasn’t very clear at all.
In a nutshell
If the strip light is off…
When the garage door opens turn the light on and set to red.
Keep it red until the door closes then turn it off (previous state)
If the strip light is on…
When the garage door opens, change the color to red
Keep it red until the door closes the return it to the previous color (previous state)
Sorry about that Dave
Ok cool. I wouldn’t even bother with a script, just automations Something along these lines will do it:
- id: '1593875523349'
alias: Garage Door Open Red
description: ''
trigger:
- device_id: 1d0e50dee10a4c6cbf1a19deadee6e61
domain: binary_sensor
entity_id: binary_sensor.garage_door_sensor_open_close
platform: device
type: opened
condition: []
action:
- service: scene.create
data:
scene_id: scene.led_rope_light_garage_door_controlled
snapshot_entities:
- light.rope_lights
- service: light.turn_on
data:
entity_id: light.rope_lights
rgb_color: [255,0,0]
- id: '1593876528697'
alias: Garage Door Closed Previous State
description: ''
trigger:
- device_id: 1d0e50dee10a4c6cbf1a19deadee6e61
domain: binary_sensor
entity_id: binary_sensor.garage_door_sensor_open_close
platform: device
type: not_opened
condition: []
action:
- service: scene.turn_on
data:
entity_id: scene.led_rope_light_garage_door_controlled
… now that was done copy / pasting your above code and adjusting it so hopefully I haven’t made a mistake but you should get the idea of what I have tried to do. Hopefully it will just work!
The reason I used I script in my first example is simply because so many things get triggered from my doorbell (and since HA doesn’t allow nested conditions where ‘false’ logic outcomes can be skipped) I had to break things out to scripts.
Hi Stavros, I really like the way the paragraphs are highlighted in color. Please tell me how you set it up?
Thanks
Hello All, I have followed this script and it is ALMOST working exactly as I want (flash light 3 times red if my garage door opens)… however, it works ONLY when the light is already ON, but doesn’t work if the light is OFF. If the light is off, nothing happens.
I tried removing “state” but that is a required field. I also tried state: ‘on’ or ‘off’ but that didn’t change anything.
Any ideas greatly appreciated!
After some more fiddling, I just took the ‘on’ out of state, essentially leaving it null, and now all works as I wish.