States for binary door sensor

I have a Telldus binary Zwave door sensor. I want to check if the door is open, or initially only to count how many times it is opened. Following automation:

  triggers:
    - trigger: event
      event_type: state_changed
      event_data:
        entity_id: binary_sensor.ytterdora_sensor_state_door_window
        to: "on"
  actions:
    - action: counter.increment
      target:
        entity_id: counter.antallytterdor

Without the to: “on”, it works nicely, but I get two increments for every time the door is opened and closed. But with the to: “on” it doesn’t work. I have tried “On”, “Open”, “open”, “Opened” and “opened”, but it just doesn’t work.
If I check the sensor state, it indeed shows “on”, but if I check the entity, it shows “Open”, so the sensor appears a bit messy. If I change the sensor state to “on” under Developer tools, it doesn’t work either (but it works without the to: “on”)
Any suggestions.on how to check the state correctly?

trigger is not “event” but “state”

triggers:
    - trigger: state
      entity_id: binary_sensor.ytterdora_sensor_state_door_window
      to: "on"

A state_changed event does not contain the data parameter to, hence why the automation will never trigger. As already mentioned, do not use an event trigger, use a state trigger.

Thanks to both of you, that did it!

1 Like