Similar functionality as described here, but I can’t do anything in the configuration.yaml file as the device was added via the UI (if I understood correctly).
My Hikvision camera never sends an event when motion is no longer detected (unlike my doorbell), so I’d like to reset the binary sensor after 10 seconds or so.
Thanks for your reply.
That seems like a possible solution. I’ve been reading through that thread, have enabled python_scripts, created the folder and now I need to find the latest version of that script.
Why isn’t this part of HA?
Then I need to create an automation that triggers that script, 10 seconds after movement was detected?
Because the alternative way which doesn’t require adding anything to HA, is still perfectly possible, creating a templated binary sensor in YAML and using the autooff delay (which is what I intend to do, because my camera’s motion sensor goes off after about 2 seconds, but I want to use it for identifying that the house is occupied).
template:
- trigger:
- platform: state
to: 'on'
entity_id: binary_sensor.mymotiondetectorrule_cell_motion_detection
binary_sensor:
- name: Livingroom Motion
state: "{{ on }}"
auto_off: "00:15:00"
device_class: motion
Replace with your actual motion detector from your camera, and replace the auto_off with how long you want to wait for the sensor to turn off. - Mine here is set to 15 minutes.
Oh, so if I understand correctly you are using the camera’s motion sensor to trigger another binary sensor with the auto_off settings (not off_delay like the MQTT binary sensor).
and here it is doing exactly what I wanted - I triggered the bedroom camera motion ONCE and then left and 15 minutes later, it changed to clear. (Note I am using device_class: occupancy instead of device_class: motion, that’s why it has different text to motion)
So I tried to implement this, but it’s not working as intended.
This is the template:
template:
- trigger:
- platform: state
to: 'on'
entity_id: binary_sensor.myfielddetector1_field_detection
binary_sensor:
- name: Hikvision garage human detected
state: 'on'
auto_off: 10
device_class: motion
The new binary sensor indeed resets after 10 seconds, but because the trigger doesn’t change (the Hikvision camera only sends “IsInside: true” events, not “false”), the new binary sensor doesn’t go to on after the first time.
These are the ONVIF events the Hikvision camera is sending:
- platform: state
entity_id: binary_sensor.myfielddetector1_field_detection
This will make it trigger not just on state change, but also when the attributes change, which should include last changed. But this is probably going to come with some downsides.
I have been doing some more testing and have also enabled normal motion detection in the camera.
Those events also send a “false” message when motion ends, unlike the fielddetector (called “intrusion detection” by Hikvision).
I use motion detection instead of intrusion detection
I file a bug report at Hikvision, asking them to fix this, but I’ll be barking up a very big tree
invest in an NVR, like blue iris and let that do all the detection and send events to HA… Although I must say the human detection on board the camera is spot on, I’ve had one false positive in months of usage.
I’ll probably do 1 and 2 for now. My goal was to do 3 anyway, once I’ve bought a server.
Well if nothing else, you at least know what you can do if you have a sensor that reports off, far too quickly for you.
I plan to go down route 3 too, because car headlights driving along the road outside the house set off the motion detection, especially in the bedroom - which is clearly no good for the occupancy detection.
Going to have a play tonight, but I am thinking using NodeRed with the onvif nodes contrib ( https://github.com/bartbutenaers/node-red-contrib-onvif-nodes ) may be a way to sort your problem, because we then send an MQTT message to Home Assistant, and your motion detector could be an MQTT sensor instead. With NodeRed we have more logic available so we can do stuff like send an OFF message from NodeRed after x number of seconds.
I installed it last night in docker, but now I need to find a way to have it talk to HA. All guides are focusing on installing node-red via the add-on store, which I don’t have in HA container.
You can either create a long lived access token and communicate with Home Assistant that way, or the way I do it on all the other machines - is just use MQTT and create an MQTT sensor in my Home Assistant YAML.
@mobile.andrew.jones, I’ve been experimenting with the onvif nodes in Node-Red and have now filtered out the event message coming from the camera when intrusion is detected. I’m sure I can devise something that acts as a boolean sensor, going on when that message arrives and off after x seconds. Next step is to convert this to an MQTT message that HA can understand.
Quick question though, as I’m new to MQTT. Am I correct I need an MQTT broker like Mosquitto?
The alternative is using websocket? And that’s where the access tokens come into play? I have these nodes installed: node-red-contrib-home-assistant-websocket (node) - Node-RED
If you could give me those pointers, I will be able to figure it out, thanks.