Dahua IPC to MQTT App

Yes, you can. You can provide multiple events to app. You’ll receive different JSON payloads which you need to parse and adapt to your needs.

1 Like

I have managed to install AppDaemon and the DahuaMQTT app. The app seems to connect to the Dahua IP camera, but I’m receiving the below error once an event is triggered by the camera.

2019-08-02 22:05:36.847211 INFO DahuaMQTT: [192.168.1.108] Publishing MQTT. topic=cameras/1, payload={“code”: “VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-02 22:05:36.880411 INFO DahuaMQTT: Failed to parse: 400 Client Error: Bad Request for url: http://hassio/homeassistant/api/services/mqtt/publish

How should I fix the bad url requests? I’m on Hassio and Raspberry PI and over https if that makes a difference.

Is your HASS <-> AppDaemon connection configured properly?

I am seeing this over and over again in the log. Any ideas?

2019-08-06 15:09:51.083151 INFO DahuaMQTT: [192.168.0.104] OnDisconnect(Success [])
2019-08-06 15:09:51.160786 INFO DahuaMQTT: [192.168.0.104] OnDisconnect(Success [])
2019-08-06 15:09:56.093670 INFO DahuaMQTT: [192.168.0.104] OnDisconnect(Success [])

Also, when I run the wget command below to troubleshoot, I see the motion events occur, but they do not trigger an MQTT message in Home Assistant.

wget ‘http://USERNAME:PASSWORD@IP/cgi-bin/eventManager.cgi?action=attach&codes=[VideoMotion]’ -O events.log

I tried to Google, but I couldn’t find what is missing from configuration. I couldn’t find any instructions on how the set this up using https. Is there a way to configure this so that it doesn’t go over the internet? I would prefer to stay on the home network. Below my appdaemon.yaml

secrets: /config/secrets.yaml
log:
  errorfile: STDERR
  logfile: STDOUT
appdaemon:
  threads: 10
  plugins:
    HASS:
      type: hass
      ha_url: https://xxxxx.duckdns.org 
      token: <automatic created by system>
hadashboard:
  dash_url: http://127.0.0.1:5050
  dash_dir: /config/appdaemon/dashboards

if you got homeassistant installed with hassio, you shouldnt change appdaemon.yaml at all (the addon takes care of everything) if not this is not the right topic to answer your question, then please ask me in PM or ask help on our discord server.

Hi,

AppDaemon was installed via Hassio. I reverted back to the original ha_url: http://hassio/homeassistant. Rest of the appdaemon.yaml is untouched. Original problem is still valid.

if you got https in home assistant then the addon will connect to home assistant with https.
in doubt: delete your complete configuration from appdaemon, uninstall the addon and install again, and the settings should be as they need to be.
the connection from appdaemon to homeassistant is then local.(not over the internet)
and in your question you dont say what you want to setup with https. if you mean appdaemon, then there is no need because you use that on your local network.
for more information, please ask me in PM or on our discord server.

Hi Sebu, I have the same issue. Could you please share if you found a solution.

Hi,
I haven’t found a solution and I don’t know what to try next.

Hi, you should to install MQTT and create user, after that all working.

  1. Install the Mosquitto add-on with the default configuration via ‘Hass.io > ADD-ON STORE’. (Don’t forget to start the add-on & verify that ‘Start on boot’ is enabled.)
  2. Create a new user for MQTT via the Configuration > Users (manage users) . (Note: This name cannot be “homeassistant” or “addon”)
  3. Once back on-line, return to Configuration > Integrations and select configure next to MQTT .
Broker: YOUR_HASSIO_IP_ADDRESS
Port: 1883
Username: MQTT_USERNAME
Password: MQTT_PASSWORD

I don’t like one more thing…APPDaemon reinstall all this packages
{
“disable_auto_token”: false,
“system_packages”: [
“libcurl”,
“python3-dev”,
“curl-dev”,
“gcc”,
“g++”
],
“python_packages”: [
“pip==19.0.2”,
“pycurl”
]
}
every restart. What I can do with this?

that cant be helped, that is how the addons in hassio work.

Thank you, Rene.

Could you please help me with my configuration?

binary_sensor:

  • platform: mqtt
    state_topic: “home-assistant/cameras/1VideoMotion”
    name: “garden_camera”

  • platform: mqtt
    state_topic: “home-assistant/cameras/2VideoMotion”
    name: “gates_camera”

  • platform: mqtt
    state_topic: “home-assistant/cameras/3VideoMotion”
    name: “door_camera”

  • alias: binary_sensor_door_camera
    initial_state: True
    trigger:
    platform: state
    entity_id: binary_sensor.door_camera
    to: ‘on’
    condition:

    • condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_home
      action:
      service: notify.telegram
      data:
      title: ‘Send a message
      message: “Motion in front of the door !”

“VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-29 16:45:14.749690 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2VideoMotion, payload=Stop
2019-08-29 16:45:14.804947 INFO DahuaMQTT: [192.168.16.31] Publishing MQTT. topic=cameras/1, payload={“code”: “VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-29 16:45:14.848530 INFO DahuaMQTT: [192.168.16.31] Publishing MQTT. topic=cameras/1VideoMotion, payload=Stop
2019-08-29 16:45:14.891154 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2, payload={“code”: “VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-29 16:45:14.935085 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2VideoMotion, payload=Stop
2019-08-29 16:45:14.986980 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2, payload={“code”: “VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-29 16:45:15.032796 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2VideoMotion, payload=Stop
2019-08-29 16:45:15.075953 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2, payload={“code”: “VideoMotion”, “action”: “Stop”, “index”: “0”}
2019-08-29 16:45:15.126626 INFO DahuaMQTT: [192.168.16.45] Publishing MQTT. topic=cameras/2VideoMotion, payload=Stop

But I don’t get messages to Telegram…

first i must say, please use codeblocks to show yaml or logs ( 3x ` on an empty line before and after the code)

second, you will only get message to telegram if you have automations that send messages.

I finally got this working with instructions from these post. Thank you all for posts and support. So I have now AppDaemon and Mosquitto MQTT addon installed. I’ve then created the binary sensor and an automation to trigger the recording once the movement is detected.

I then installed “Gallery panel for images and videos” to access and to visualize the videos Dahua has recorder.

Last problem I’m facing is the delay from the actual movement and the recording starts. There is about 3 second on ”missing”. I don’t know where this delay is coming: MQTT receives the message, automation tigger or video recording starts.

What kind of delays are you having and any ideas on how to make it shorter?

I refer to a problem earlier in this thread.
I am having the same package missing problem.
I placed the requiremetnts.txt file wherever I could but it does not get read at startup by AD

Is there some “switch” or flag to force?

How can I installpycurl and pyad (missing)

2019-09-15 01:09:21.184125 WARNING AppDaemon: ------------------------------------------------------------
2019-09-15 01:11:19.960312 WARNING AppDaemon: ------------------------------------------------------------
2019-09-15 01:11:19.960376 WARNING AppDaemon: Unexpected error loading module: /home/reinan/.appdaemon/conf/apps/dahua_mqtt.py:
2019-09-15 01:11:19.960415 WARNING AppDaemon: ------------------------------------------------------------
2019-09-15 01:11:19.960881 WARNING AppDaemon: Traceback (most recent call last):
  File "/home/reinan/appdaemon/lib/python3.7/site-packages/appdaemon/appdaemon.py", line 2026, in check_app_updates
    self.read_app(mod["name"], mod["reload"])
  File "/home/reinan/appdaemon/lib/python3.7/site-packages/appdaemon/appdaemon.py", line 1809, in read_app
    self.modules[module_name] = importlib.import_module(module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/reinan/.appdaemon/conf/apps/dahua_mqtt.py", line 3, in <module>
    import pycurl
ModuleNotFoundError: No module named 'pycurl'

2019-09-15 01:11:19.960937 WARNING AppDaemon: ------------------------------------------------------------
2019-09-15 01:11:19.964098 WARNING AppDaemon: ------------------------------------------------------------
2019-09-15 01:11:19.964155 WARNING AppDaemon: Unexpected error loading module: /home/reinan/.appdaemon/conf/apps/home_presence_app.py:
2019-09-15 01:11:19.964193 WARNING AppDaemon: ------------------------------------------------------------
2019-09-15 01:11:19.964379 WARNING AppDaemon: Traceback (most recent call last):
  File "/home/reinan/appdaemon/lib/python3.7/site-packages/appdaemon/appdaemon.py", line 2026, in check_app_updates
    self.read_app(mod["name"], mod["reload"])
  File "/home/reinan/appdaemon/lib/python3.7/site-packages/appdaemon/appdaemon.py", line 1809, in read_app
    self.modules[module_name] = importlib.import_module(module_name)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/reinan/.appdaemon/conf/apps/home_presence_app.py", line 1, in <module>
    import adbase as ad
ModuleNotFoundError: No module named 'adbase'

2019-09-15 01:11:19.964427 WARNING AppDaemon: ------------------------------------------------------------

Hi,
I’ve been using this appdaemon without issue for a few months.
So I have or had a working setup.

Today, I can not run appdaemon with the previously discussed package configuration.

{
  "disable_auto_token": false,
  "system_packages": [
    "libcurl",
    "python3-dev",
    "curl-dev",
    "gcc"
  ],
  "python_packages": [
    "pip==19.0.2",
    "pycurl"
  ]
}

The error I get with this configuration is:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 

-----------------------------------------------------------
 Hass.io Add-on: AppDaemon
 Python Apps and HADashboard using AppDaemon 3.x for Home Assistant
-----------------------------------------------------------
 Add-on version: 4.0.3
 You are running the latest version of this add-on.
 System: Fedora 30 (Server Edition)  (amd64 / qemux86-64)
 Home Assistant version: 0.98.5
 Supervisor version: 188
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] appdaemon.sh: executing... 
[13:02:06] INFO: Updating Hass.io API token in AppDaemon with the current one...
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
v3.10.2-55-g6cecf3cc9d [http://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.2-42-g95d37f7648 [http://dl-cdn.alpinelinux.org/alpine/v3.10/community]
v20190809-2816-gc29a90ed35 [http://dl-cdn.alpinelinux.org/alpine/edge/main]
v20190809-2814-g70fcce09f3 [http://dl-cdn.alpinelinux.org/alpine/edge/community]
v20190809-2817-g1d8c4a88bb [http://dl-cdn.alpinelinux.org/alpine/edge/testing]
OK: 25321 distinct packages available
OK: 76 MiB in 33 packages
(1/2) Installing pkgconf (1.6.1-r1)
(2/2) Installing python3-dev (3.7.3-r0)
Executing busybox-1.30.1-r2.trigger
OK: 117 MiB in 35 packages
ERROR: unsatisfiable constraints:
  libcrypto1.1-1.1.1c-r0:
    breaks: openssl-dev-1.1.1d-r0[libcrypto1.1=1.1.1d-r0]
    satisfies: world[libcrypto1.1=1.1.1c-r0]
               ca-certificates-20190108-r0[so:libcrypto.so.1.1]
               python3-3.7.3-r0[so:libcrypto.so.1.1]
               libcurl-7.66.0-r0[so:libcrypto.so.1.1]
               apk-tools-2.10.4-r2[so:libcrypto.so.1.1]
               libssl1.1-1.1.1c-r0[so:libcrypto.so.1.1]
               libtls-standalone-2.9.1-r0[so:libcrypto.so.1.1]
  libssl1.1-1.1.1c-r0:
    breaks: openssl-dev-1.1.1d-r0[libssl1.1=1.1.1d-r0]
    satisfies: world[libssl1.1=1.1.1c-r0]
               python3-3.7.3-r0[so:libssl.so.1.1]
               libcurl-7.66.0-r0[so:libssl.so.1.1]
               apk-tools-2.10.4-r2[so:libssl.so.1.1]
               libtls-standalone-2.9.1-r0[so:libssl.so.1.1]
[13:02:13] FATAL: Failed installing package curl-dev
[cont-init.d] appdaemon.sh: exited 1.
[cont-finish.d] executing container finish scripts...
[cont-finish.d] 99-message.sh: executing... 
-----------------------------------------------------------
                Oops! Something went wrong.

 We are so sorry, but something went terribly wrong when
 starting or running this add-on.
 
 Be sure to check the log above, line by line, for hints.
-----------------------------------------------------------
[cont-finish.d] 99-message.sh: exited 0.
[cont-finish.d] appdaemon.sh: executing... 
[cont-finish.d] appdaemon.sh: exited 0.
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

package curl (not curl-dev) does install, but fails with missing binaries curl-config IIRC.

Any ideas? is it just me?

@dvbit, you need the config I’m referring in my post. Hopefully it works for you - let me know?
btw it goes in hass.io -> AppDaeomon -> and paste it in the Config section of webinterface.

Same here. Reported https://github.com/hassio-addons/addon-appdaemon3/issues/50

Exactly the same output on the error.

I amon home assistant not hassio but will try to put it … everywhere.
I tried already unfortunately.
@ReneTode any clue? Thanks all