Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Assistant - how to? #32

Open
OrakelDelphi opened this issue Mar 11, 2023 · 2 comments
Open

Home Assistant - how to? #32

OrakelDelphi opened this issue Mar 11, 2023 · 2 comments

Comments

@OrakelDelphi
Copy link

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?

@OrakelDelphi
Copy link
Author

OrakelDelphi commented Mar 11, 2023

Okay, i found something - i answer to my own question:

  1. 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"}

  2. In your config.yaml uste topicroot: camera-alerts

  3. 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'
  1. Adjust these parameters to your debug output from mosquitto_sub at the 1. step because every cam or NVR maybe reports with different values.

  2. 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.

@OrakelDelphi
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant