Noob can not get simple automation to work

Been at this for a couple of hours now, but I can’t figure out why it is not working.
I’m trying to get a door sensor to turn on a light.
It looks like this:

  • id: ‘1560367756411’
    alias: Test 1
    trigger:
    • entity_id: binary_sensor.openclose_29
      from: closed
      platform: state
      to: open
      action:
    • data:
      entity_id: switch.uttag_vardagsrum
      service: switch.turn_on
  • id: ‘1560369856809’
    alias: Test 2
    trigger:
    • entity_id: binary_sensor.openclose_29
      from: open
      platform: state
      to: closed
      condition: []
      action:
    • data:
      entity_id: switch.uttag_vardagsrum
      service: switch.turn_off

I can see the state of the sensor changes when I move the pieces apart or closer.
It works when I call the service manually.

I have restarted hass.io and reloaded automations.

What am I missing

The actual state of a binary sensor is on or off. Try that in place of open or closed (on being open, off being closed)

A binary_sensor can have one of two valid states: on or off.

Change your automations to use 'on' and 'off' instead of open and closed.


Ninja’d by apmillen

For future reference, please format your code to make it easier for others to read. For example:

- id: '1560367756411'
  alias: Test 1
  trigger:
    platform: state
    entity_id: binary_sensor.openclose_29
    from: 'off'
    to: 'on'
  action:
    service: switch.turn_on
    data:
      entity_id: switch.uttag_vardagsrum

Use the formatting icon </> in the tool bar or enter three consecutive back-quotes ``` on a separate line before your code and then another three on a separate line after your code.

I had already tried on/off state several times, but I had missed I had to put the state between ’ ’
I actually used the automation-tool provided in hass.io, but I guess I messed it up somehow…

Thank you all, and I’ll keep the formatting tool in mind for further pastes of code.