1st Automation issue

I’ve been trying to build my first simple automation and I keep getting this one error which I have no idea about.
Yaml is:

alias: Turn Office Lights On
  trigger:
    platform: state
    entity_id: binary_sensor.office_office_motion_178
    to: on

  action:
    service: light.turn_on
    entity_id: light.office_office_lights_160

- alias: Turn off Office Light
  trigger:
    platform: state
    entity_id: binary_sensor.office_office_motion_178
    to: off
    for:
      minutes: "3"
  action:
    service: light.turn_off
    entity_id: light.office_office_lights_160

The error is :
Invalid config for [automation]: expected str for dictionary value @ data[‘to’]. Got None. (See /config/configuration.yaml, line 14).

Clearly I am doing something stupid. Can someone please point me in the right direction.

The first one in your list is missing the -. Add that and put alias at the same indentation as trigger.

Thanks for the reply Jim

That is a copy and paste error the - is there and it is the same indentation as trigger, I must have accidentally deleted it when I was putting the ‘’’'s in to separate the code.

Any other thoughts

Change this:

    to: on

to this:

    to: 'on'

When quoted, it’s interpreted as a string containing the word on. Without quotes, the word on has special meaning and is handled as a variable (whose value is a boolean not a string).

Do the same for off.

For more information refer to this: YAML - Booleans

1 Like

Thanks - that sorted it, and thanks for the link too.

You’re welcome!

To close out this topic, please consider marking my post (above) with the Solution tag. It will automatically add a check-mark next to the topic’s title which indicates to other users that this topic has an accepted solution. This helps users find answers to similar questions.

It’s always the little things.

It often is, like the fact that 8 months later, the OP still has his own post marked as the Solution despite the fact it contains no solution.

1 Like

Taras
I marked my post by mistake and dont know how to take it off, but if you tell me I will. I did comment your post fixed it.

By selecting the Solution checkbox in the other post, it will automatically deselect your post because only one post in the entire thread can be the Solution post.

Screenshot_20210730-080313~2

There isn’t a solution checkbox on your response

There appears to be one on your post. Try deselecting it and see if that permits you to select the Solution checkbox of any other post. Even if you still can’t select mark another post, at least users, searching for the Solution, won’t be led to the wrong post.

Tried that at the time, and again today - cant remove the solution marker

Moved the solution tag.

1 Like