Manually set sensor state -> flips back to old value

I have a binary sensor, coming from an ONVIF camera, that’s linked to intrusion detection.
The problem is that it doesn’t go to off, so I’m trying to investigate if I can manually set it to off after some time.
But while experimenting with the Developer tools > states, I notice that after I set the state to ‘off’ it flips back on always on the 43 second mark…

I verified with ONVIF Device Manager and it’s not the camera that’s sending an event, so why does it flip back on?

The binary_sensor’s state value is updated periodically by its integration. Manually setting its value is not permanent; it only lasts until the integration sets it (to something else) or when Home Assistant is restarted.

In addition, it’s a binary_sensor so its state value is normally set by its integration (you may have noticed there’s no service call to set a binary_sensor’s state).

So is there really no way to manually set it to off and keep it there, until there’s a new onvif “message” to set it on again?

This is still related to the problem here, by the way. I keep trying to get useful data from the intrusion detection.

The binary_sensor’s state value is set by its integration. Regardless of what value you use to set it manually, if the integration is using polling (and it appears that this one using a 1-minute polling interval) the integration will set the value at the next polling interval.

It’s the responsibility of the binary_sensor’s integration to set its state value and it’s clearly doing that, once a minute.

Because my camera sends the off message far too quickly (seconds) I ended up doing this:

template:
  - trigger:
      - platform: state
        to: 'on'
        entity_id: binary_sensor.mymotiondetectorrule_cell_motion_detection
    binary_sensor:
      - name: Livingroom Presence
        state: 'on'
        auto_off: "00:30:00"
        device_class: occupancy

This sensor switches off 30 minutes after the last “on” was received, if it keeps receiving “on” it will reset the 30 minute countdown.

You can use a variation of this code to make a sensor that stays in the state that you want.

EDIT: Nevermind I see I have already responded to you with this code before in the other topic. Sorry.

Yeah and the main issue remains mine doesn’t send an off signal at all… So I was hoping that by manually setting it to off, the integration would at least wait until it got a real message from the camera to turn it on again, but alas.

Btw, off-topic:
They are removing the set state option in developer tools…
https://github.com/home-assistant/frontend/pull/10321

1 Like

Wait, what, why? I’m using it constantly to test my automation triggers…

1 Like

And the dumbing down of HA continues… :roll_eyes:

1 Like