Need a little help understanding YAML syntax

Hi all,

I have some automations that appear to have been built originally in the UI, but I am trying to make them a bit more reliable. I want to re-write them without the Device IDs, but having a little trouble. Anyone mind giving me some pointers here?

- alias: Front Entry Light on when door unlocked
  description: ''
  trigger:
  - platform: device
    device_id: 8f42afe329a0f0739acba765f6ddd1f2
    domain: lock
    entity_id: lock.front_door
    type: unlocked
  condition:
  - condition: device
    type: is_on
    device_id: c08e0f19918bf4d855c35a74e46416eb
    entity_id: light.front_porch_lights
    domain: switch
    
  - condition: state
    entity_id: light.downstairs_lights
    state: 'off'
    
  action:
  - type: turn_on
    device_id: 4bf2dbcce8d891b846ef60cee5e5328e
    entity_id: light.front_entry_lights
    domain: switch
  mode: single

Thank you!
-David

That first one is a state trigger for lock.front_door. Check Developer tools → States to see what that entity state is when unlocked.

The second one is a state condition, as you’re using already, for light.front_porch_lights being in the state on.

The last is a service call for light.turn_on on light.front_entry_lights.

The UI editor can build all of that for you, so you can then look at the YAML.

Here’s how I’d write that. You’ll need to have a look in Developer Tools / States to see what the actual state of the lock is (perhaps 'on' instead of 'unlocked'?).

- alias: Front Entry Light on when door unlocked
  id: UUID4_HERE
  trigger:
    - platform: state
      entity_id: lock.front_door
      to: 'unlocked'
  condition:
    - condition: state
      entity_id: light.front_porch_lights
      state: 'on'
    - condition: state
      entity_id: light.downstairs_lights
      state: 'off' 
  action:
    - service: light.turn_on
      entity_id: light.front_entry_lights

I put ids in my automations to allow assigning it to an area.

Thank you, @Tinkerer !!!

@Troon - how do you generate you UUIDs? Thank you!!

I use this site:

https://www.uuidgenerator.net/

but that’s just for convenience and consistency. The id just has to be a unique string.

Hi @Troon - I got this updated, but I am still not getting the front entryway lights to turn on when the conditions are met. Any thoughts as to what might be preventing this from triggering?

 alias: Front Entry Light on when door unlocked
  id: 265984b7-5651-4bc9-ab05-c9d749052301
  trigger:
    - platform: state
      entity_id: lock.front_door
      to: 'unlocked'
  condition:
    - condition: state
      entity_id: light.front_porch_lights
      state: 'on'
    - condition: state
      entity_id: light.downstairs_lights
      state: 'off' 
  action:
    - service: light.turn_on
      entity_id: light.front_entry_lights

I confirmed that ‘unlocked’ is the correct state of the lock is ‘unlocked’. My front porch lights and entryway lights are switches that I have set as lights in my configuration - they work correctly as lights when controlled from HA, so I don’t think that’s the issue. The light.downstairs_lights is a group, but again, it seems to work correctly when controlled through HA. Not sure where my issue is.

Any thoughts would be greatly appreciated!

Thanks,
David

How? Did you use Developer Tools / States? Could you post a screenshot like this, but for your lock?

Do the lights come on if you manually execute the automation, which bypasses trigger and condition? (Configuration / Automations / Run Actions).

Does the automation show that it has been triggered (same screen as above)? If it does, you can use the image button to see what happened.

Take a look at the debug UI for the automation.

never seen that, where can we find that button?
btw, now we’re on the developer-tools/state, what does the refresh button next to the Set state button do ? Hovering it doesnt show a tooltip, nor does clicking it have an effect…

Schermafbeelding 2021-06-09 om 10.54.31

In the automations screen.

1 Like

a yes, forgot about that, thought Troon was talking about the dev-tools/state page, sorry…

1 Like

@Troon I figured out the issue…I mistyped the entryway light entity name. It seems to work now!!

Thank you so much for the help!

-David

1 Like