Need help to translate in yaml

yes, after 15min script.partyraumbeleuchtung_standby should be called.
purpuse is to act like a motion detector if someone goes into the room.

entity_id: timer.your_timer

do i have to define this before? can i use other name like partyraum_timer?

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

i get an error message: Message malformed: extra keys not allowed @ data[‘trigger’]

I have tried to make a new script. or does it have to go into configuration.yaml?

The example I posted is an automation, not a script.

If you attempt to put the automation’s code into a script, you will get the error message:

extra keys not allowed @ data[‘trigger’]

because trigger is not a valid option for a script.

ok, as an automation i get following error message:
There was an error converting to YAML: YAMLException: unacceptable kind of an object to dump [object Undefined]

Obviously you made a mistake with wherever you put the automation. However, I can’t guess what you did based on that error message.

well, that error accurs when i trie to use the yaml editor.
If i write it with notepad into automation.yaml and reload it, it is ok.

But: the state is alwas on! I can see in the log that it have been often triggered, but it never turnt to off state!
for testing i set the time to 15sec.

The state of what is on?

You do realize that the example I posted for you simply starts a timer, right? That’s all it does and nothing more.

You have to add an automation that does something (like calls a script to turn off the two lights) when the timer finishes.

alias: 'example 2'
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.partyraum_timer
action:
  - service: script.your_script

Hi, i got it running (and learning thanx to your help!):

In configuration.yaml:

timer:
  partyraum_timer:
    duration: '00:00:15'    

In Automation.yaml:

- id: '1638036241709'
  alias: Partyraum Licht voll
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.partyraum_lichtschalter_full
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: script.partyraumbeleuchtung_voll
    data: {}
  mode: single
- id: '1638036310682'
  alias: Partyraum Licht voll aus
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.partyraum_lichtschalter_full
    from: 'on'
    to: 'off'
  condition: []
  action:
  - service: script.partyraumbeleuchtung_default
    data: {}
  mode: single
  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
  alias: Partyraum_timer
  trigger:
  - platform: state
    entity_id: binary_sensor.partyraum_pir
    from: 'off'
    to: 'on'
  action:
  - service: timer.start
    target:
      entity_id: timer.partyraum_timer
    data:
      duration: 00:00:30
  alias: Partyraum_Timer_End
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.partyraum_timer
  action:
  - service: script.partyraumbeleuchtung_standby
  alias: Partyraum_Timer_Start
  trigger:
  - platform: event
    event_type: timer.started
    event_data:
      entity_id: timer.partyraum_timer
  action:
  - service: script.partyraumbeleuchtung_motion

One thing about this motion detection must be combined with the Licht an aus:
The (alias) Partyraum_timer must be only allowed if the binary_sensor.partyraum_lichtschalter is off!
EDIT: I could manage to get also this to work:

- id: '1638123705921'
  alias: Partyraum_timer
  trigger:
  - platform: state
    entity_id: binary_sensor.partyraum_pir
    from: 'off'
    to: 'on'
  condition:
  - condition: state
    entity_id: binary_sensor.partyraum_lichtschalter
    state: 'off'
  action:
  - service: timer.start
    target:
      entity_id: timer.partyraum_timer
    data:
      duration: 00:05:00
  mode: single

i am wondering why can i not define brightness values in % in the sript?

sequence:
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe1
    data:
      brightness: 30

i can only use values from 0 to 255 but not von 0% to 100%. it gives me an error if i replace values with %!

Now only the very last step is to do:
If person Wolfram and person Sabine are away, turn off the light completely(call a script.partyraumbeleuchtung_aus).

Use the brightness_pct option.

sequence:
  - service: light.turn_on
    target:
      entity_id: light.partyraum_lampe1
    data:
      brightness_pct: 30

For more information, refer to the documentation for service light.turn_on.

ahh, ok, thanks!

I am trieng to get this with the home/away get working, but the away_timer don’t start:

in configuration.yaml i have:

timer:
  partyraum_timer:
    duration: '00:00:15'    
  partyraum_away_timer:
    duration: '00:00:15'    

in auomation i have:

- id: '1638192620614'
  alias: Partyraum_away_timer
  description: ''
  trigger:
  - platform: state
    entity_id: device_tracker.wolfram_handy
    to: 'off'
  condition:
  - condition: state
    entity_id: binary_sensor.partyraum_lichtschalter
    state: 'off'
  action:
  - service: timer.start
    target:
      entity_id: timer.partyraum_away_timer
    data:
      duration: 00:01:00
  mode: single
  alias: Partyraum_Away_Timer_End
  description: ''
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.partyraum_away_timer
  condition: []
  action:
  - service: script.partyraumbeleuchtung_aus
  mode: single

is the systax correct for this:

    entity_id: device_tracker.wolfram_handy
    to: 'off'

Change this:

  - platform: state
    entity_id: device_tracker.wolfram_handy
    to: 'off'

to this:

  - platform: state
    entity_id: device_tracker.wolfram_handy
    to: 'not_home'

For more information, refer to Device Tracker States

thanx, that works.
Can i also use 2 entity_id’s? like this:

- platform: state
    entity_id: device_tracker.wolfram_handy
    to: 'not_home'
    entity_id: device_tracker.sabine_handy
    to: 'not_home'

goal is to start the timer when none of both are at home

i got something running, but does it really work with both persons?

in C it should be like this:

If (device_tracker_wolfram == not_home) && (device_tracker_sabine == not_home)
{
  if (Lichtschalter == off)
  {
    start partyraum_away_timer;
  }
}

- id: '1638192620614'
  alias: Partyraum_away_timer
  description: ''
  trigger:
  - platform: state
    entity_id: device_tracker.wolfram_handy
    from: home
    to: not_home
  condition:
  - condition: state
    entity_id: binary_sensor.partyraum_lichtschalter
    state: 'off'
  - condition: and
    conditions:
    - condition: state
      entity_id: device_tracker.sabine_handy
      state: not_home
  action:
  - service: timer.start
    target:
      entity_id: timer.partyraum_away_timer
    data:
      duration: 00:30:00
  mode: single
- id: '1638192620614'
  alias: Partyraum_away_timer
  description: ''
  trigger:
  - platform: state
    entity_id:
    - device_tracker.wolfram_handy
    - device_tracker.sabine_handy
    from: home
    to: not_home
  condition:
  - condition: state
    entity_id: binary_sensor.partyraum_lichtschalter
    state: 'off'
  - condition: state
    entity_id: device_tracker.wolfram_handy
    state: not_home
  - condition: state
    entity_id: device_tracker.sabine_handy
    state: not_home
  action:
  - service: timer.start
    target:
      entity_id: timer.partyraum_away_timer
    data:
      duration: 00:30:00
  mode: single

after some finetuning everything works fine!

does it mean that both device_tracker must be from home to not_home or one of them?
do i understand it right that “action” is only processed if all “conditions” are true?
or is it one or more of them ?

  trigger:
  - platform: state
    entity_id:
    - device_tracker.wolfram_handy
    - device_tracker.sabine_handy
    from: home
    to: not_home
  condition:
  - condition: state
    entity_id: binary_sensor.partyraum_lichtschalter
    state: 'off'
  - condition: state
    entity_id: device_tracker.wolfram_handy
    state: not_home
  - condition: state
    entity_id: device_tracker.sabine_handy
    state: not_home
  action:

If either Wolfram or Sabine leave the house, the automation is triggered. However, the condition checks if both Wolfram AND Sabine are not home (AND the binary_sensor is off). So if Sabine leaves first, the automation is triggered but the action is not executed because the conditions are not satisfied because Wolfram is still home. If Wolfram now leaves the house, all conditions are met (because Sabine has already gone) and the action is executed.

Ok, i thank you very much for the help!

I now can say the translation is SOLVED!

Would be a nice feature to HA if C## Code would be acceptable… :wink:

1 Like

c#

c o ol ! Sounds great!