Problem with automation that uses a door sensor to toggle lights that is triggering every hour

Hi,

I have an Aqara door sensor (magnetic) that switches on the light when the door opens and switches off when closed. A timer switches off the light after 5 minutes when the door is left open.

I made the automation that toggles the light based on the sensor state, and another automation that switches off the light after 5 minutes is the door is left open.

The problem I have is that the automation triggers every hour circa and switches on the light if the door is open, I guess because the Aqara sensor is sending maybe a status check, but not sure about it.

I am new to automation and learning, so I think something is worn in my automation, can you guys help me find the problem?

alias: Closet lights
description: 
trigger:
  - platform: state
    entity_id: binary_sensor.openclose_32
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.openclose_32
            state: 'on'
        sequence:
          - type: turn_on
            device_id: c7b365cafcaa11eab3a0056b040f18c8
            entity_id: light.dimmable_light_40
            domain: light
            brightness_pct: 100
      - conditions:
          - condition: state
            entity_id: binary_sensor.openclose_32
            state: 'off'
        sequence:
          - type: turn_off
            device_id: c7b365cafcaa11eab3a0056b040f18c8
            entity_id: light.dimmable_light_40
            domain: light
    default: []
mode: single

Here’s my understanding of the problem you’ve described:

The door is opened, the light is turned off automatically after 5 minutes, the door is left open, and then about an hour later the light is turned on again.

Do I have that right?

I suspect this binary_sensor has attributes, perhaps like “battery level” or “signal strength”, and when it periodically transmits an update causes the State Trigger to trigger.

From the documentation for State Trigger:

State trigger

Fires when the state of any of given entities changes. If only entity_id is given trigger will fire for all state changes, even if only state attributes change.

To prevent the State Trigger from triggering due to changes in the binary_sensor’s attributes, you must make the trigger very specific.

alias: Closet lights
description: 
trigger:
  - platform: state
    entity_id: binary_sensor.openclose_32
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.openclose_32
    from: 'on'
    to: 'off'
condition: []
action:
## etc ##
3 Likes

Stupid me not RTFM!
Thanks for your help.

1 Like