I am new to automations via YAML - most if not all are done via GUI so far.
I have door sensor
smart plug
speaker
I would like achieve the following in one automation:
trigger: when door sensor is open
script #1 : when the door sensor is open for more than 30 seconds then call service tts.google_translate_say
script #2 : when the door sensor is open and is after sunset turn on smart plug for 10 minutes and then turn off
Additionally I’m just wondering if there needs to be a condition for each sript in case the script is still running? For example, door sensor has been opened, script #2 has turned on the switch. Now, I close the door and open again - does it mean the script #2 will try to run again and it would fail as the switch is already on?
I’d do it in multiple automations. Merging them gains nothing but complexity.
When the door is open for 30 seconds, TTS
one of:
a. When door opens after sunset, turn on the smart plug and start a ten minute timer
b. When the door opens after sunset, turn on the smart plug, wait for the door to be closed then start a ten minute timer
c. When the door opens after sunset, if the smart plug is off, turn on the smart plug, wait for the door to be closed, then start a ten minute timer
When the timer expires turn off the smart plug
These will give you slightly different results:
a. Keeps the light on until ten minutes after the door was last opened, even if the door is still open
b. Keeps the light on until the door has been closed for ten minutes
c. Keeps the light on for ten minutes after the door was first opened, regardless
Two automations like Tinkerer said is probably your best bet. However, you may be able to use Trigger ID’s to accomplish this. I haven’t tested this, but I think this may work:
alias: When door opens call 2 scripts
description: ''
mode: single
trigger:
- type: opened
platform: device
device_id: 1ccfb18afed239187e96d8ececfefe06
entity_id: binary_sensor.front_door_sensor_ias_zone
domain: binary_sensor
- platform: state
entity_id: binary_sensor.front_door_sensor_ias_zone
for:
hours: 0
minutes: 0
seconds: 30
id: OpenFor30Seconds
to: opened
from: closed
- platform: sun
event: sunset
offset: 0
id: OpenAfterSunset
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: OpenFor30Seconds
sequence:
- service: tts.cloud_say
data:
entity_id: media_player.living_room_home
message: Door is opened for 30 seconds!
- conditions:
- condition: trigger
id: OpenAfterSunset
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.corner_lamp_on_off
- condition: state
entity_id: switch.corner_lamp_on_off
for:
hours: 0
minutes: 10
seconds: 0
- service: switch.turn_off
data: {}
target:
entity_id: switch.corner_lamp_on_off
default: []