Automation condition if binary_sensor.washing_machine_door is still closed

Hi,

I’m running the ‘Home Connect’ integration from Bosch/Siemens and my Washing Machine has the entity
binary_sensor.washing_machine_door enabled.

As I often oversee the native push notifications I’d like to setup a Home Assistant automation with a condition that checks what the last state was of the door (open or closed). If closed, it should send a push notification.

As I’m not a savvy programmer I’m using ChatGPT to create some automations. It suggested the following automation as a test:

trigger:
  - platform: event
    event_type: test_door_notification
condition:
  - condition: template
    value_template: >-
      {% set two_minutes_ago = now() - timedelta(minutes=2) %}

      {% set history = states.history('binary_sensor.washing_machine_door',
      start=two_minutes_ago, end=now()) %}

      {{ history | selectattr('state', 'eq', 'off') | list | length > 0 }}
action:
  - service: notify.mobile_app
    data:
      message: TEST
      title: Test

When I run the automation it always sends the notification, which should not be the case. I already changed the state to ‘Closed’, ‘closed’, ‘Open’ and ‘open’ but this does not change anything.

Can someone help supply a test automation where the condition checks if the door was closed the last 15 minutes?

Thanks in advance!

Please don’t. It was trained on old and now out of date information.

1 Like

I know :sweat_smile:. But in some cases it did help me well :-).

Try


  - condition: template
    value_template: >-
      {% set door = 'binary_sensor.washing_machine_door' %}
      {% set history = states[door].last_changed %}
      {{ states(door) == 'off' and now() - history > timedelta(minutes=15) }}

Sorry for my stubbornness, but after the latest chatGPT update (it can browse for update content) it came up with the following automation (which works!):

automation:
  - alias: "Washing Machine Door Notification"
    trigger:
      - platform: state
        entity_id: binary_sensor.washing_machine_door
        to: 'off'  # Assuming 'off' represents closed and 'on' represents open
    condition:
      - condition: template
        value_template: >
          {% set last_changed = as_timestamp(states.binary_sensor.washing_machine_door.last_changed) %}
          {% set now = as_timestamp(now()) %}
          {{ (now - last_changed) <= 900 }}  # 900 seconds equals 15 minutes
    action:
      - service: notify.mobile_app_your_device
        data:
          message: "Washing machine door was opened in the last 15 minutes."