Door Contact - Automation Help - parameters?

Hi All,
I have a Zigbee Door Contact that is part of an automation that should turn on the workshop lights (a Z-Wave switch) when the door is opened.
It is the 1st time I use more than one trigger (motion sensor as well as door contact).
I don’t understand if I have missed a setting or if this is just “as it is with cheap Zigbee sensor”, but the contact sensor does not trigger half the time. With the door already open and the light manually turned off I have had instances where closing the door turned on the light.

The automation code that was generated from the HA interface is :

alias: Atelier Lights ON-Got motion
description: ""
triggers:
  - type: opened
    device_id: 66674756753029e2552385084daf786a
    entity_id: a2b1b60bb908b1c0d225069df1bbcf82
    domain: binary_sensor
    trigger: device
  - type: motion
    device_id: 8c327d6ba9af462438e4dfb3c73e1383
    entity_id: 495c8963a91e47c237c34dd6b1668a32
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - type: turn_on
    device_id: 94ff87dca5f9346db953da210cd8492e
    entity_id: c87ce9c7a1bee6f5f841dd9d409b7388
    domain: switch
mode: single

Any suggestions on testing or parameters that I might have missed would be appreciated.
Thanks.

I would avoid using devices and move to using the entity states.

Thanks I will try that.

alias: Atelier Lights ON-Got motion
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.atelier_interior_door_contact_contact
    from: "off"
    to: "on"
  - trigger: state
    entity_id:
      - binary_sensor.q_sensor_motion_detection
    from: "off"
    to: "on"
conditions: []
actions:
  - type: turn_on
    device_id: 94ff87dca5f9346db953da210cd8492e
    entity_id: c87ce9c7a1bee6f5f841dd9d409b7388
    domain: switch
mode: single

What I am not certain of is that for the contact sensor “true” indicates a closed (so door closed) and false indicates open, but when I sue the UI to build the automation it gives me the state change from “off” which would be closed to “on” open ? I am getting this correctly…so “on” would equal “false”.

I would guess that “on” means that the door is closed (so the contact sensor detects contact).

Contact sensors are sometimes quirky at state changes. For example, opening a door might trigger the contact sensor to quickly report a series like closed-open-closed-open, after which it won’t trigger again until another door action.

If that’s what’s happening, try inserting a “for:” delay on the trigger; say 1 second or so.

On is door open or motion detected. If you are unsure, you can look here, at the device class table:

1 Like

Thanks! Didn’t know this existed.

I wouldn’t go from “off” to “on” etc. Remove the from and just have the to. Door sensors can go to sleep and switch to unavailable which would stop your automation from working.

Example :

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