Dahua IPC to MQTT App

Vscode is not req, as an aside I have it running on a pi as an addon. You need to modify apps.yaml located /config/appdaemon/apps/apps.yaml

under hello world you would add

DahuaMQTT:
  class: DahuaMQTT
  module: dahua_mqtt
  cameras:
    - host: 192.168.4.108
      port: 80
      user: username
      pass: password
      retain: true
      topic: cameras
      events: CrossRegionDetection,CrossLineDetection,VideoMotion,LeftDetection

Programming is linear, there isn’t room for extra/miss placed characters. As code executes, once it hits something it doesn’t understand everything kinda halts.

Thanks for the feed back. I cant get the code editor to work. So, If I am on the server with ssh where can I find the mentioned files? I do not have any folder named /config as far as I can see? See my file-tree on the picture. the config folder in the tree I created manually… Will copy it over to the HomeAssitant folder.

What type of installation ha os? docker? vm? When you install the appdaemon addon it should create that folder. Is appdaemon running? what do the appdaemon logs say?

System.

The deamon is running I can open it.


2022-07-14 16:51:01.331254 DEBUG AppDaemon: get_state: thread.thread-0.None None True
2022-07-14 16:51:01.332558 DEBUG HASS: Utility
2022-07-14 16:51:01.333905 DEBUG AppDaemon: set_state(): sensor.appdaemon_uptime, {'state': '2 days, 3:07:35'}
2022-07-14 16:51:01.335583 DEBUG AppDaemon: parse_state: sensor.appdaemon_uptime, {'state': '2 days, 3:07:35'}
2022-07-14 16:51:01.337067 DEBUG AppDaemon: Old state: {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:34', 'last_changed': '2022-07-14T16:51:00+02:00', 'attributes': {}}
2022-07-14 16:51:01.338501 DEBUG AppDaemon: New state: {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:35', 'last_changed': '2022-07-14T16:51:01+02:00', 'attributes': {}}
2022-07-14 16:51:01.339758 DEBUG AppDaemon: sending event locally
2022-07-14 16:51:01.341526 DEBUG AppDaemon: Util loop compute time: 19.0ms, check_config()=8.0ms, other=11.0ms
2022-07-14 16:51:01.343343 DEBUG AppDaemon: Event type:state_changed:
2022-07-14 16:51:01.344810 DEBUG AppDaemon: {'entity_id': 'sensor.appdaemon_uptime', 'new_state': {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:35', 'last_changed': '2022-07-14T16:51:01+02:00', 'attributes': {}}, 'old_state': {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:34', 'last_changed': '2022-07-14T16:51:00+02:00', 'attributes': {}}}
2022-07-14 16:51:01.345947 DEBUG AppDaemon: process_event_callbacks() admin {'event_type': 'state_changed', 'data': {'entity_id': 'sensor.appdaemon_uptime', 'new_state': {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:35', 'last_changed': '2022-07-14T16:51:01+02:00', 'attributes': {}}, 'old_state': {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:34', 'last_changed': '2022-07-14T16:51:00+02:00', 'attributes': {}}}}
2022-07-14 16:51:01.348196 DEBUG AppDaemon: thread_async loop, args={'function': <bound method ADStream.process_event of <appdaemon.stream.adstream.ADStream object at 0xb51af340>>, 'args': ({'event_type': 'state_changed', 'data': {'entity_id': 'sensor.appdaemon_uptime', 'new_state': {'entity_id': 'sensor.appdaemon_uptime', 'state': '2 days, 3:07:3

The log is showing a lot of info :slight_smile:

Then search the ha folder for appdaemon or apps.yaml, it has to be in there somewhere already.

Well I found it. Not expected it there. Lets see how to progress from here. Thanks.

So I added the dahua app into the apps folder and now it appears into the Appdaemon. Nice. Still do not see any camera related topics in mqtt so have to figure out what is missing… getting there I hope. I finally want to have the alarm from the SMD human - vehicle detection to control a light or push message. The detection works since I have some video recordings already when a person walks in camera sight. Which yaml setting should I use for that? AlarmOutput: or does SMD has a special output available? Thanks.

I have all yaml files in place but still not getting it to work. Seems that there is an error thrown from the dahua_mqtt yaml file

The beginning of that file has a commented out section that shows what needs to be placed in apps.yaml, did you modify the example in dahua_mqtt.yaml? it shouldn’t be modified, you can delete the file and just copy a new one into the directory.

I have /had that exact file in place. But generating a lot of errors. So I have included it again this is what the error log shows:

The instance that I am running this on is an older version, I’m wondering if that has something to do with it. Although the first error about ‘apps.yaml’ seems like there is a formatting error. Check your spacing and no extra spaces after entries.

If that doesn’t work try the dahua integration in hacs. Try https first it may work, if not http.

I checked the app.yaml and the dahua_mqtt.yaml with validator. The app.yaml is ok now but the dahua_yaml is not ok and seems not to apply to (newer) yaml validate rules (tabs where spacing is needed). Maybe some one who has the experience can validate the dahua_mqtt yaml on github or publish it here :).
So we can use it in newer version of HA/ Appdaemon.

The other option you mentioned is also worth while checking out. But I prefer this solution because of the mqtt publishing which I wanted to use.

dahua_mqtt is written in python, not yaml so you can’t go by a yaml validator

Your right my mistake. I now changed in into the .py but still generating errors now the problem seems to be ‘pycurl’ which can not be installed.

I have installed that manually:

pi@raspberrypi4:~ $ sudo pip install pycurl
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pycurl in /usr/local/lib/python3.9/dist-packages (7.45.1)
pi@raspberrypi4:~ $ 

So it should be available in the system. Tried to leave import pycurl out but that throws other errors depending on it.

When I start/restart appdaemon you should see the build sequence as shown below. There should be specific packages aside from pycurl that show missing. You have to add them to the list on the appdaemon config. Then you’ll need to look if the packages you add have dependencies.

Goto below to search the missing packages.

https://pkgs.alpinelinux.org/packages

For those who are still using this – i believe there are a few, Ive had numerous issues every time ive done an appdaemon update, fiddling with the packages in order to get pycurl to install.

I did a re-write late last week using the python requests module, and after ~72 hours of operating it seems to be behaving as expected.

I have mine setup via a DVR with only a single entry, so cant 100% confirm if it works with multiple standalone cameras, but if anyone is keen to test it please DM me and ill share the link

For anyone having issues after updating AppDaemon recently, I managed to get it working after updating a couple of libraries.
Check here for details. Appdaemon 0.13.0 and curl-dev

You couldnt post your AppDaemon config as i cant get mines to start anymore since last update
i tried adding the stuff from the link but it still fails
Thanks

Paul

If anyone is still using this integration, especially on a Pi4, could you post your working configuration please.

This was working for me up until a recent update, and I must admit to my shame that I didn’t notice straight away that it had stopped.

I’ve already wasted many hours trawling the web for solutions, and even tried re-installing everything, so my next best bet is to try a config that someone else knows to work.

TIA

I couldnt ever get it working, I instead wrote a different version using python requests, which doesnt have any extra requirements. Ive been using this for around 12 months and its been working fine for me.

Feel free to give that a go

1 Like