Need help to translate in yaml

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

What kind of entities have you created to represent Wolfram, Sabine, Partyraum_Lichtschalter, Partyraum_Lichtschalter_full, Partyraum_PIR, timer, etc?

Have you already created a script called script.partyraumbeleuchtung?

Wolfram & Sabine is “person” with device tracker ping
Partyraum_Lichtschalter,
Partyraum_Lichtschalter_full
Partyraum_PIR are binary sensor

scripts are called as prevousli described

For a timer i also need help, don’t know where and how to do that.

Have you tried to create an automation with any of the entities you mentioned or are you asking for someone to write the whole thing for you?

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.

You are correct, I made a mistake and have fixed the example.

it doesn`t turn off the lights, doesn’t call the script standby!
I wonder of this:

Diese Entität (“script.1637660997291”) hat keine eindeutige ID that is the info about the script “Partyraumbeleuchtung Standby”

The info about the script “Partyraumbeleuchtung Default” is this:

Diese Entität (“script.partyraumbeleuchtung_default”) hat keine eindeutige ID

both scripts are the same except brightness values for the lamps:

alias: Partyraumbeleuchtung Default
sequence:
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe1
    data:
      brightness: 72
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe2
    data:
      brightness: 72
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe3
    data:
      brightness: 64
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe4
    data:
      brightness: 72
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe5
    data:
      brightness: 72
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe6
    data:
      brightness: 64
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe7
    data:
      brightness: 72
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe8
    data:
      brightness: 72
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe9
    data:
      brightness: 64
  - service: light.turn_on
    target:
      entity_id: light.partyraum_flammen
    data:
      brightness: 255
  - service: light.turn_on
    target:
      entity_id: light.partyraum_bild
    data:
      brightness: 255
  - service: light.turn_on
    target:
      entity_id: light.partyraum_dartscheibe
    data:
      brightness: 32
  - service: light.turn_on
    target:
      entity_id: light.partyraum_spiegelkugel
    data:
      brightness: 0
mode: single

alias: Partyraumbeleuchtung Standby
sequence:
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe1
    data:
      brightness: 30
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe2
    data:
      brightness: 30
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe3
    data:
      brightness: 0
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe4
    data:
      brightness: 0
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe5
    data:
      brightness: 0
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe6
    data:
      brightness: 0
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe7
    data:
      brightness: 30
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe8
    data:
      brightness: 30
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe9
    data:
      brightness: 0
  - service: light.turn_on
    target:
      entity_id: light.partyraum_flammen
    data:
      brightness: 255
  - service: light.turn_on
    target:
      entity_id: light.partyraum_bild
    data:
      brightness: 255
  - service: light.turn_on
    target:
      entity_id: light.partyraum_dartscheibe
    data:
      brightness: 0
  - service: light.turn_on
    target:
      entity_id: light.partyraum_spiegelkugel
    data:
      brightness: 0
mode: single

this works:

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 'script.1637660997291'}}
    data: {}
mode: single

But how can i get rid of this script name script.1637660997291 and why is it a number?

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:

Screenshot from 2021-11-28 11-19-37

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!

where can i rename them?

Go to Developer Tools > States, enter script in the “Filter entities” field. The underlines names it shows represent the entity_id of each script.

Screenshot from 2021-11-28 11-37-17

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”.

Screenshot from 2021-11-28 11-41-57

i renamed the scriptes in the script.yaml (before your post) , now they are with the right names.

the automation look like this but doesn’ work:

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 'script.partyraumbeleuchtung_standby'}}
    data: {}
mode: single

when i start the script manually they work.
I also restarted HA.

That’s good news.

The from and to have incorrect values:

They should be lists:

    from: ['off', 'on']
    to: ['on', 'off']

However, that not your fault. If you are using the Script Editor, it automatically changes a list to a string of comma-separated items. It’s a bug.

Try this format and see if the Script Editor leaves it undisturbed or converts it improperly:

    from:
      - 'off'
      - 'on'
    to:
      - 'on'
      - 'off'

the editor makes it like this:

    from:
      - 'off'
      - 'on'
    to: 'on,off'

but it works

Glad to hear it.

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.

thank you very much!

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.

This should help you get started. It starts a 15-minute timer when the binary_sensor changes state from off to on.

alias: example 1
trigger:
  - platform: state
    entity_id: binary_sensor.partyraum_pir
    from: 'off'
    to: 'on'
action:
  - service: timer.start
    target:
      entity_id: timer.your_timer
    data:
      duration: '00:15:00'

What do you want to happen when the timer finishes counting down 15 minutes? Call a script?