Visual Editor warning on an Automation

How might I improve the syntax of this automation, so that the Visual Editor warning message goes away?

Many thanks!

- id: '16111xxxxxxxxxx9'
  alias: Porch Lights PIR
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.porch_pir_motion
    to: 'on'
  - platform: state
    entity_id: binary_sensor.porch_pir_motion
    to: 'off'
    for: 0:05:00
  condition:
  - condition: template
    value_template: '{{ trigger.to_state.state == ''off'' or is_state(''sun.sun'',
      ''below_horizon'') }}'
  action:
  - service: light.turn_{{ trigger.to_state.state }}
    entity_id:
    - light.porch_1
    - light.porch_2
  mode: single

Put entity_id in target

service: ....
target:
  entity_id: ...

you could id the triggers and use choose for the action:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: binary_sensor.media_motion
    id: to_on
    to: 'on'
  - platform: state
    entity_id: binary_sensor.media_motion
    id: to_off
    to: 'off'
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: to_on
          - condition: device
            device_id: ''
            domain: ''
            entity_id: ''
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.hallway
      - conditions:
          - condition: trigger
            id: to_off
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.hallway
    default: []
2 Likes

Many thanks @AllHailJ - sorry for the delay in replying.

I have re-done the Automation and the Visual Editor now contains no errors, but I am not sure that I fully understand what I have written - or if it is correct. Have I got it right?

I have highlighted the section that confuses me below with # marks - but the # marks are not there in my automations.yaml file (obviously :sweat_smile: )

What I want is for the lights to come on for 5 mins every time the PIR is activated, then go off.

Many thanks - much appreciated !

- id: '16xxxxxxxxxx9264'
  alias: Porch Lights PIR (Test)
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.porch_pir_motion
    to: 'on'
    id: to_on
  - platform: state
    entity_id: binary_sensor.porch_pir_motion
    to: 'off'
    for: 0:05:00
    id: to_off
  condition: []
  action:
  - choose:
#    - conditions:
#      - condition: trigger
#        id: to_on
#      sequence:
#      - service: light.turn_on
#        target:
#          device_id:
#          - porch_light_1
#          - porch_light_2
        data:
          brightness_pct: 50
    - conditions:
      - condition: trigger
        id: to_off
      sequence:
      - service: light.turn_off
        target:
          device_id:
          - porch_light_1
          - porch_light_2
    default: []
  mode: single

No problems with delaying in your response. The forum is not a help desk.

You have identified each trigger. Triggers are executed with OR so this or that. The ID lets the program know which trigger set the automation in motion.

In the actions you pick choose and the condition is the trigger and then you have an action.

Trigger if
 TriggerID one or
 TriggerID two
Action
 Choose
   if TriggerID One
   Then Do Actions I want with Trigger ID one
   Else
   if TriggerID Two
   Then Do Actions I want with Trigger ID Two
   Else
    Do a default action  

So in your automation you say:

If may PIR goes to on ( to_on )  Run Actions 
Choose Action is_on
  Turn on the light
End automation

When PIR goes to off (to_off) for 5 minutes Run Actions
  Choose Action is_off
     Turn off the light
End automation

Also the mode single means only run once and do not queue up multiple runs.

Hope this helps with your understanding.

1 Like

Again - many thanks; I had got it in to my head that the lights needed to come on for 5 minutes after a PIR activation, but AIUI what you have shown is that the lights come on until the PIR has NOT been activated in the previous 5 minutes. A subtle difference, but I now understand.

Happy New Year! :ok_hand: