Dahua IPC to MQTT App

Hello there!

Recently I upgraded my home security surveilance to Dahua cameras. What I needed is to detect movement and do some home automation, so I wrote AppDaemon APP which polls Dahua camera events and translates it to MQTT messages. If you’re interested, feel free to use and modify it. You can find it in my repository:

8 Likes

Hi, great stuff: could you tell more - in Hassio can I place it to custom_components folder or need to add appdaemon add-on first? Thanks!

appdaemon apps always need appdaemon. (in your case the addon)

Do I need some required packages (system or python) for that app? I am totally new to appdaemon… configured it well in apps.yaml but log gives me error about pycurl module…
added “pycurl” to appdaemon but it seems extra packages are required…
Could you please list all required packages?

In the same directory as apps.yaml, create file requirements.txt put pycurl, and every other missing module (if any) separated by new line. If you have any issues with runing this app - let me know!

added pycurl to requirements.txt in apps folder
removed pycurl from appdaemon settings (cant add it anyway duу to config-curl error in log)

2019-02-12 15:12:18.201234 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/dahua_mqtt.py 2019-02-12 15:12:18.209238 WARNING AppDaemon: ------------------------------------------------------------ 2019-02-12 15:12:18.210014 WARNING AppDaemon: Unexpected error loading module: /config/appdaemon/apps/dahua_mqtt.py: 2019-02-12 15:12:18.210756 WARNING AppDaemon: ------------------------------------------------------------ 2019-02-12 15:12:18.226466 WARNING AppDaemon: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 2026, in check_app_updates self.read_app(mod["name"], mod["reload"]) File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1809, in read_app self.modules[module_name] = importlib.import_module(module_name) File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/config/appdaemon/apps/dahua_mqtt.py", line 49, in <module> import pycurl ModuleNotFoundError: No module named 'pycurl' 2019-02-12 15:12:18.227241 WARNING AppDaemon: ------------------------------------------------------------ 2019-02-12 15:12:18.227926 WARNING AppDaemon: Removing associated apps: 2019-02-12 15:12:18.228754 WARNING AppDaemon: DahuaMQTT

Could you please look at appdaemon log after restart? You should see lines something about installing pycurl.

log:
[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 v1.6.0 Python Apps and HADashboard using AppDaemon 3.x for Home Assistant From: Community Hass.io Add-ons By: Franck Nijhof <[email protected]> ----------------------------------------------------------- armhf / HassOS 2.8 / HA 0.86.4 / SU 143 / stable ----------------------------------------------------------- [cont-init.d] 00-banner.sh: exited 0. [cont-init.d] 01-log-level.sh: executing... Log level is set to INFO [cont-init.d] 01-log-level.sh: exited 0. [cont-init.d] 02-updates.sh: executing... INFO: You are running the latest version of this add-on [cont-init.d] 02-updates.sh: exited 0. [cont-init.d] 20-init-configuration.sh: executing... [cont-init.d] 20-init-configuration.sh: exited 0. [cont-init.d] 21-compiled-dir.sh: executing... [cont-init.d] 21-compiled-dir.sh: exited 0. [cont-init.d] 30-auto-token.sh: executing... INFO: Updating Hass.io API token in AppDaemon with the current one... [cont-init.d] 30-auto-token.sh: exited 0. [cont-init.d] 31-ha-url.sh: executing... [cont-init.d] 31-ha-url.sh: exited 0. [cont-init.d] 50-compiled-symlink.sh: executing... [cont-init.d] 50-compiled-symlink.sh: exited 0. [cont-init.d] 80-system-packages.sh: executing... [cont-init.d] 80-system-packages.sh: exited 0. [cont-init.d] 81-python-packages.sh: executing... [cont-init.d] 81-python-packages.sh: exited 0. [cont-init.d] done. [services.d] starting services [services.d] done. 2019-02-12 17:19:32.651399 INFO AppDaemon Version 3.0.2 starting 2019-02-12 17:19:32.653967 INFO Configuration read from: /config/appdaemon/appdaemon.yaml 2019-02-12 17:19:32.660354 INFO AppDaemon: Starting Apps 2019-02-12 17:19:32.677914 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin 2019-02-12 17:19:33.320528 INFO AppDaemon: HASS: HASS Plugin Initializing 2019-02-12 17:19:33.322475 INFO AppDaemon: HASS: HASS Plugin initialization complete 2019-02-12 17:19:33.324756 INFO Starting Dashboards 2019-02-12 17:19:33.370736 INFO API is disabled 2019-02-12 17:19:33.399745 INFO AppDaemon: HASS: Connected to Home Assistant 0.86.4 2019-02-12 17:19:35.196974 INFO AppDaemon: Got initial state from namespace default 2019-02-12 17:19:37.398905 INFO AppDaemon: Reading config 2019-02-12 17:19:37.460727 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified 2019-02-12 17:19:37.461702 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified 2019-02-12 17:19:37.464923 INFO AppDaemon: App 'hello_world' added 2019-02-12 17:19:37.466262 INFO AppDaemon: App 'DahuaMQTT' added 2019-02-12 17:19:37.469825 INFO AppDaemon: Adding /config/appdaemon/apps to module import path 2019-02-12 17:19:37.494839 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/hello.py 2019-02-12 17:19:37.606576 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/dahua_mqtt.py 2019-02-12 17:19:37.616104 WARNING AppDaemon: ------------------------------------------------------------ 2019-02-12 17:19:37.617123 WARNING AppDaemon: Unexpected error loading module: /config/appdaemon/apps/dahua_mqtt.py: 2019-02-12 17:19:37.618092 WARNING AppDaemon: ------------------------------------------------------------ 2019-02-12 17:19:37.638575 WARNING AppDaemon: Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 2026, in check_app_updates self.read_app(mod["name"], mod["reload"]) File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1809, in read_app self.modules[module_name] = importlib.import_module(module_name) File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/config/appdaemon/apps/dahua_mqtt.py", line 49, in <module> import pycurl ModuleNotFoundError: No module named 'pycurl' 2019-02-12 17:19:37.649132 WARNING AppDaemon: ------------------------------------------------------------ 2019-02-12 17:19:37.650328 WARNING AppDaemon: Removing associated apps: 2019-02-12 17:19:37.651569 WARNING AppDaemon: DahuaMQTT 2019-02-12 17:19:37.653484 INFO AppDaemon: Initializing app hello_world using class HelloWorld from module hello 2019-02-12 17:19:38.300631 INFO hello_world: Hello from AppDaemon 2019-02-12 17:19:38.308415 INFO hello_world: You are now ready to run Apps! 2019-02-12 17:19:38.311881 INFO AppDaemon: App initialization complete

appdaemon settings: should I add something here? Tried “pycurl” only - failed (dependences needed?)

{
  "log_level": "info",
  "system_packages": [],
  "python_packages": []
}

I am getting exactly the same like here:

What OS your AppDaemon runs in? Is this docker container?

HassOS 2.8
docker… seems I am damned like other hassos users)

you dont add it to appdaemon.yaml (because then AD wont startup anymore)
you need to create a file in the directory apps (or in the config dir, i am not sure which would work) that is called requirements.txt
and that need to contain:

{
  "log_level": "info",
  "system_packages": [],
  "python_packages": ["pycurl"]
}

after that you restart AD and see if anything else is needed (by looking at the log)

and please if you present logs, do it as codeblock, because what you presented now is not really readable

I could not find codeblock - tried to - sorry!
Please check external link in one of my previous message to somebody forum topic - I am getting exact same errors when I add “pycurl” to appdaemon settings. Think it is common HassOS (Hassio) problem…

on top of any forum you find a link how to use codeblocks.

i did read that link and i know most people have trouble activating such things.
it can be done. but you need to do as i said.

you get the error when you dont add pycurl in the right way.
so again:

@Velly Did you get this to work? I’m trying to set it up now. Have the Hass.io AppDaemon add-on so pycurl can be configured in there?

With the following config:

{
  "log_level": "info",
  "system_packages": [],
  "python_packages": [
    "pycurl"
  ]
}

image

I get this error:

Collecting pycurl
  Downloading https://files.pythonhosted.org/packages/e8/e4/0dbb8735407189f00b33d84122b9be52c790c7c3b25286826f4e1bdb7bde/pycurl-7.43.0.2.tar.gz (214kB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "/tmp/pip-install-9n9b9ru_/pycurl/setup.py", line 223, in configure_unix
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
        restore_signals, start_new_session)
      File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: 'curl-config': 'curl-config'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-9n9b9ru_/pycurl/setup.py", line 913, in <module>
        ext = get_extension(sys.argv, split_extension_source=split_extension_source)
      File "/tmp/pip-install-9n9b9ru_/pycurl/setup.py", line 582, in get_extension
        ext_config = ExtensionConfiguration(argv)
      File "/tmp/pip-install-9n9b9ru_/pycurl/setup.py", line 99, in __init__
        self.configure()
      File "/tmp/pip-install-9n9b9ru_/pycurl/setup.py", line 227, in configure_unix
        raise ConfigurationError(msg)
    __main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory: 'curl-config': 'curl-config'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-9n9b9ru_/pycurl/
You are using pip version 10.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
FATAL: Failed installing package pycurl
[cont-init.d] 81-python-packages.sh: exited 1.
[cont-finish.d] executing container finish scripts...
[cont-finish.d] 50-compiled-symlink.sh: executing... 
[cont-finish.d] 50-compiled-symlink.sh: exited 0.
[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.

it needs to be done like i suggested in the last 2 postings.
however i think thats only step 1.
its very well possible that pycurl depends on more libs, but that can be found out by reading the logs after restart.

but its probably also case sensitive and i just did a lookup with google and the package is called pycURL

so the requirements.txt needs to be:

{
  "log_level": "info",
  "system_packages": [],
  "python_packages": ["pycURL"]
}

saw your log @xbmcnut

so it seems pip needs to be upgraded somehow.

maybe with

 {
  "log_level": "info",
  "system_packages": [],
  "python_packages": ["pip", "pycURL"]
}

or

{
  "log_level": "info",
  "system_packages": [],
  "python_packages": ["--upgrade pip", "pycURL"]
}

Thanks! I’ll try that now.

@ReneTode

{
 "log_level": "info",
 "system_packages": [],
 "python_packages": ["pip", "pycURL"]
}

gave me

Requirement already satisfied: pip in /usr/lib/python3.6/site-packages (10.0.1)
You are using pip version 10.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

and

{
  "log_level": "info",
  "system_packages": [],
  "python_packages": ["--upgrade pip", "pycURL"]
}

gave me

ERROR: You must give at least one requirement to install (see "pip help install")
You are using pip version 10.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
FATAL: Failed installing package --upgrade

Can I upgrade PIP on HassOS through CLI?

i am in the dark when it comes to hassio and its possibilities.
but commandline probably wont work, because you need to upgrade a docker.

probably you need something like [“pip 19.0.2”]
but i dont know what exactly needs to be used for version dependencies.