So, I’m trying to combine some automations, neaten-up, if you will. I have working automations, 2, that do this, but want to combine the 2 to 1. I tried playing with the building blocks, they seem to do what I want, but they don’t work like that.
I want to turn on a light(smartplug) upon the door sensor triggering, then turn it off after maybe 4 minutes.
The 2 automations that work are here:
- id: '1708744525201'
alias: New Front Porch Light on Door opening After sunset 2-23-24
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.lumi_lumi_sensor_magnet_aq2_87da0008_on_off
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: switch.turn_on
metadata: {}
data: {}
target:
device_id: e0f4c7d64634bd117c387dd8fcba3ad8
mode: single
This works to turn everything on.
Then, the automation to turn off:
- id: '1631584513193'
alias: Doorlamps off after 4mins turned on.
description: Doorlamps off after 4mins turned on.
trigger:
- platform: state
entity_id:
- light.fr_door_lamps_light
to: 'on'
for:
hours: 0
minutes: 4
seconds: 0
from: 'off'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- type: turn_off
device_id: da1decfe8b469feb3e5e0ec596c8cdc6
entity_id: adcf612f106de094ea6dc8d6182efef7
domain: light
mode: single
Some way to make this one, without adding a helper timer.
Thanks.
I was trying to avoid setting timers on it. It works fine standing alone, I was just looking to combine it into 1 automation. Still playing with it, thanks.
Yes, I cut and pasted your code, and my editor kicked out that the first action line had bad indentation. I pulled it back a space and the warning went away, but it didn’t work.
And, of course I found out I pasted the wrong code of mine, that came from helping someone earlier.
Sorry about that. the first code entry of mine is wrong, the second is correct.
alias: DoorLamps ON at entry after sundown 2-27-24
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.lumi_lumi_sensor_magnet_aq2_87da0008_on_off
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.fr_door_lamps_light
mode: single
Here’s the second automation … same as above except for device id cleanup…
alias: Doorlamps off after 4mins turned on.
description: Doorlamps off after 4mins turned on.
trigger:
- platform: state
entity_id:
- light.fr_door_lamps_light
to: 'on'
for:
hours: 0
minutes: 4
seconds: 0
from: 'off'
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.fr_door_lamps_light
mode: single
THIS is the correct code . Thanks to your suggestion, I cleaned up all of my config of device ids.
I just went into automations, and re-entered the action device to be an entity versus the actual device (green versus blue button).
Odd thing I noticed, all text entries are red now, not the old blue at the beginning of the line, in config.yaml. My older entries are still blue though.
Never mind about the red text comment, I figured that out. Must have fat fingered something. Extra id line with no minus, doing nothing, threw off everything below that line.