Open OrakelDelphi opened 1 year ago
Okay, i found something - i answer to my own question:
To debug: just use mosquitto_sub to subscripte to the mosquitto broker running on the hassio.
Example: mosquitto_sub -d -u username -P password -h ip_of_home_assistant_server -t 'camera-alerts/#'
You can also subscribe to '#' -> its a wildcard for all topics! mosquitto_sub you can run on every linux system by installing it for example with apt-get install mosquitto-clients
Example output:
{"Address":"0x12345678","Channel":2,"Descrip":"","Event":"MotionDetect","SerialID":"myNVR-ID","StartTime":"2023-03-12 00:23:04","Status":"Start","Type":"Alarm","ipAddr":"192.168.1.75"}
In your config.yaml uste topicroot: camera-alerts
Create a mqtt.yaml
a) edit configuration.yaml -> add a line with
mqtt: !include mqtt.yaml
b) create a file mqtt.yaml and insert the binary_sensor configuration:
binary_sensor:
- name: "NVR"
state_topic: "camera-alerts/yourdeviceID/MotionDetect"
device_class: "motion"
value_template: '{{value_json.Status}}'
payload_on: 'Start'
payload_off: 'Stop'
Adjust these parameters to your debug output from mosquitto_sub at the 1. step because every cam or NVR maybe reports with different values.
No need to restart ha, just go to Developer tools, Yaml, Check configuration and if okay, klick on reload MQTT-Entities.
The new sensor with the given name (example NVR) should appear. Without motion status is unknown. If motion appeares it must change.
ToDo: create other sensor type. I use a NVR with 3 cams (channels). So i need 3 sensors for 3 different channels. And my NVR is flapping with the MotionDetect. It seems, that every second motion is detected a Alarm is created. I'am still debuging.
Update: Sensor definition in mqtt.yaml that works for me:
sensor:
- name: "NVR"
state_topic: "camera-alerts/myNVR-ID/MotionDetect"
value_template: '{{value_json.Channel}}_{{value_json.Status}}'
Value is Channel + _ + Start or Stop (0_Start, 0_Stop, .... 2_Start, 2_Stop).
Create work, but how to integrate exactly into home assistant. I have a running docker image and it receives a lot of messages with "MotionDetect" and "EventStop". At the Mosquitto broker log i see a new client connection. But what to do next to get sensors or trigger an automation?