Hi, i want to set an automation but i need help for the right syntax in yaml.
Can someone translate this to yaml?
if (Wolfram is home or Sabine is home)
if (Partyraum_Lichtschalter == on)
if (Partyraum_Lichtschalter_full == on)
run script "Partyraumbeleuchtung Full"
else
run script "Partyraumbeleuchtung Default"
endif
else
if (Partyraum_PIR == on)
run script "Partyraumbeleuchtung Motion"
start timer 10min.
else
if (timer == 0)
run script "Partyraumbeleuchtung Standby"
endif
endif
else
run script "Partyraumbeleuchtung Aus"
endif
i have tried to make an automation,
turn on/off the Lights with the switch works.
But can it be all code in one automation?
Now i have an automation to turn the lights on and a seperate automation to turn it off.
Would like to have it all in one…
alias: Partyraum Licht an
description: ''
trigger:
- platform: state
entity_id: binary_sensor.partyraum_lichtschalter
from: 'off'
to: 'on'
condition: []
action:
- service: script.partyraumbeleuchtung_default
data: {}
mode: single
alias: Partyraum Licht aus
description: ''
trigger:
- platform: state
entity_id: binary_sensor.partyraum_lichtschalter
from: 'on'
to: 'off'
condition: []
action:
- service: script.1637660997291
data: {}
mode: single
name each trigger with an id, e.g. id: to_on, or even just the script name. Then use the choose to call each script based on the trigger.id. i.e. "{{ trigger.id == 'to_on' }}" as your choose condition.
alias: Partyraum Licht an aus
description: ''
trigger:
- platform: state
entity_id: binary_sensor.partyraum_lichtschalter
from: ['off', 'on']
to: ['on', 'off']
condition: []
action:
- service: "script.partyraumbeleuchtung_{{ 'default' if trigger.to_state.state == 'on' else 'standby'}}"
data: {}
mode: single
You could also use a simpler State Trigger, without the from and to options. However, by including the desired states it won’t trigger due to a state-change caused by a change from/to unavailable or unknown.
EDIT
Correction. Wrong script was called when binary_sensor is off.
shouldn’t it be named as Partyraumbeleuchtung Standby instead of _lichtschalter ?
The script for turning off the light is called Partyraumbeleuchtung Standby.
It’s difficult to understand what you want because in your first example you use script.1637660997291 to turn off the lights when the binary_sensor is off:
but then later you told me:
So what is the name of the script you created that turns off the lights? Is it script.1637660997291 or script.partyraumbeleuchtung_standby?
If it’s script.1637660997291 but you don’t like that name and want it to be script.partyraumbeleuchtung_standby then just rename it.
Or have you created two scripts, one named 1637660997291 and the other partyraumbeleuchtung_standby?
this is how it looks, but in the info there is that number.
I named all scripts with the Alias to the human Text, don’t know why some scripts have such numbers!
Go to Developer Tools > States, enter script in the “Filter entities” field. The underlines names it shows represent the entity_id of each script.
Notice that the first script’s entity_id is script.1627221957315 but its name is “toggle_two_switches”. If I look in Configuration > Scripts, it appears as “toggle_two_switches”.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.
At the side of the Lightswitch there is a little switch for turning on all lamps to 100% (9x 7W LED)
the automation for this mode is easy and works.
But how can i start a timer of 15min. when the entity partyraum_pir toggles from off to on?
With this i want to turn on 2 Lamps (call a script) only if the Lightswitch is off.