Window state change automation not triggering

Hey,

I’ve been trying to create an automation, which sends a push notification to me when the window is opened.
My automation:

- id: test
  alias: test
  trigger:
    platform: state
    entity_id: binary_sensor.window_sensor
  action:
   service: notify.notify
   data_template:
     message: >
        test
        {% if is_state('binary_sensor.window_sensor', 'on') %}
          on
        {% else %}
          off
        {% endif %}

I didn’t include an from or to because I want a notification for all state changes.
The state changes correctly, but the automation never gets triggered, even though the automation is enabled.

Maybe I am just blind right now but this looks to me like a simple automation, which should be triggered?

I hope that someone spots the mistake I made.
Thanks in advance!

are you getting errors in the log? Your spacing is off in the action, but that shouldn’t make a difference. Also, you can simplify this and remove the if statement. I don’t think any of those issues are going to fix the automation not firing:

  - id: test
    alias: test
    trigger:
      - platform: state
        entity_id: binary_sensor.window_sensor
    action:
      - service: notify.notify
        data_template:
          message: "test {{ trigger.to_state.state }}"

Hey,

there were no errors in the log so far.
I just replaced on and off in the template. Actually, there are different words. But I replaced my automation with yours for testing purposes. Sadly, it still doesn’t trigger.

So, something must be wrong with your binary_sensor. That should work. What’s the state of the sensor?

I forgot to mention that it is a xiaomi window/door sensor.

Still no fix. Tried an example automation from the docs, but it doesn’t work either.

Is there a reason why you used binary_sensor.window_sensor in your automation when the actual entity_id of the sensor is binary_sensor.door_window_sensor_158d0001c1fba1?

1 Like

actually, no. That might have been the issue. Thanks!!