juanboro / cync2mqtt

Bridge Cync bluetooth mesh to mqtt
38 stars 7 forks source link

Setup as Home Assistant HACS Integration #23

Open BacchusIX opened 7 months ago

BacchusIX commented 7 months ago

Hello:

I've tried a few times install this on a RPi4 running Home Assistant OS, however failed repeatedly due to I think comes done to how HA OS handles things (e.g. there is no apt-get command).

I get: `` ➜ ~ ~/venv/cync2mqtt/bin/pip3 install git+https://github.com/juanboro/cync2mqtt .git Collecting git+https://github.com/juanboro/cync2mqtt.git Cloning https://github.com/juanboro/cync2mqtt.git to /tmp/pip-req-build-5spogq pz Running command git clone --filter=blob:none --quiet https://github.com/juanbo ro/cync2mqtt.git /tmp/pip-req-build-5spogqpz Resolved https://github.com/juanboro/cync2mqtt.git to commit 4e2190caa074da3ca aca481c8587dca1d2441478 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Collecting amqtt (from cync2mqtt==0.0.1) Using cached amqtt-0.10.1-py3-none-any.whl.metadata (1.0 kB) Collecting bleak (from cync2mqtt==0.0.1) Using cached bleak-0.21.1-py3-none-any.whl.metadata (5.3 kB) Collecting bluepy (from cync2mqtt==0.0.1) Using cached bluepy-1.3.0.tar.gz (217 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Collecting requests (from cync2mqtt==0.0.1) Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB) Collecting pycryptodome (from cync2mqtt==0.0.1) Using cached pycryptodome-3.20.0-cp35-abi3-musllinux_1_1_aarch64.whl.metadata (3.4 kB) Collecting pyyaml (from cync2mqtt==0.0.1) Using cached PyYAML-6.0.1-cp311-cp311-linux_aarch64.whl Using cached PyYAML-5.4.1.tar.gz (175 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [54 lines of output] running egg_info writing lib3/PyYAML.egg-info/PKG-INFO writing dependency_links to lib3/PyYAML.egg-info/dependency_links.txt writing top-level names to lib3/PyYAML.egg-info/top_level.txt Traceback (most recent call last): File "/root/venv/cync2mqtt/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in main() File "/root/venv/cync2mqtt/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(hook_input['kwargs']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/venv/cync2mqtt/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel return hook(config_settings) ^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires self.run_setup() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 311, in run_setup exec(code, locals()) File "", line 271, in File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/init.py", line 103, in setup return distutils.core.setup(attrs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup return run_commands(dist) ^^^^^^^^^^^^^^^^^^ File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands dist.run_commands() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands self.run_command(cmd) File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/dist.py", line 963, in run_command super().run_command(command) File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command cmd_obj.run() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 321, in run self.find_sources() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 329, in find_sources mm.run() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 550, in run self.add_defaults() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/command/egg_info.py", line 588, in add_defaults sdist.add_defaults(self) File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/command/sdist.py", line 102, in add_defaults super().add_defaults() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/sdist.py", line 251, in add_defaults self._add_defaults_ext() File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/sdist.py", line 336, in _add_defaults_ext self.filelist.extend(build_ext.get_source_files()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 201, in get_source_files File "/tmp/pip-build-env-h2vsh2bs/overlay/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 107, in getattr raise AttributeError(attr) AttributeError: cython_sources [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip. ``

I have tried to install bluepy through several different means but keep running into road blocks with it. I think I was successful installing Bluepy via the "Custom Dep Deployment" add-on but haven't gotten any further as there is no documentation with it.

I also tried loading your repository into HACS as a custom repository but get: "<Integration juanboro/cync2mqtt> Repository structure for main is not compliant"

Long story short, is it possible to build your repository into one that works with HACS; I think that might be the only way us running HA OS will be able to use it. Or if someone else has an idea what's going wrong (or what I'm doing wrong).

Either way, thanks for any assistance.

johnrosshunt commented 7 months ago

I'm not one of the developers, but I think these errors are caused by missing header files. I ran into the same problem trying to build bluepy on MacOS. Bleak is cross-platform, but I think bluepy is Linux only.

If you can't install missing packages on HAOS you can always install cync2mqtt on a different Linux machine (or virtual machine or docker container). The only requirements are a bluetooth device and network access so cync2mqtt can connect to the MQTT server that Home Assistant uses. I've been using it like this for quite some time without any problems.

juanboro commented 7 months ago

Yeah - while bleak in theory is cross platform, it's not clear how well it works outside of the linux Bluez ecosystem. Although I would think it should be able to be brought up on HA OS on a raspberry Pi (it works fine on raspberry pi os/Debian). I'll take a look into HAOS more. Can you run docker containers on HAOS? That might be an option to run the docker config. The config I runs is in a docker container on a tiny pizero2-w separate from HA which is running on a docker container on a x86 ubuntu machine (like @johnrosshunt mentions).

juanboro commented 7 months ago

I'll look into https://developers.home-assistant.io/docs/add-ons/publishing - prebuild containers for HAOS.

BacchusIX commented 7 months ago

Yeah - while bleak in theory is cross platform, it's not clear how well it works outside of the linux Bluez ecosystem. Although I would think it should be able to be brought up on HA OS on a raspberry Pi (it works fine on raspberry pi os/Debian). I'll take a look into HAOS more. Can you run docker containers on HAOS? That might be an option to run the docker config. The config I runs is in a docker container on a tiny pizero2-w separate from HA which is running on a docker container on a x86 ubuntu machine (like @johnrosshunt mentions).

Yeah I was surprised also at some of the stuff that doesn't work on HAOS; I guess I was under the impression that it was a very lite version of like Debian or something (I believe it's Buildroot Linux), so I kind of threw me off a bit when I couldn't get apt-get and such to work. My understanding is that HAOS was sort of designed to do everything from inside the home assistant frame work, but I've been finding that has some inherit limitations in not everything is necessarily designed to work within HA and those of us that aren't experts in this stuff it's hard to find work arounds. I'm not sure about Docker/ or virtual machines on HAOS, I'll maybe take a look into this as well.

I do agree though that this should work on HA OS on a Pi. I have BT integrations that work; so wouldn't there have to be BlueZ loaded then? I also got Bluepy to load (I think) via the Custom Dep Deployment add-on. It's quite possible I'm just not putting the pieces together right; as I've said, I'm far from an expert in this stuff.

I appreciate you looking into it though.

juanboro commented 7 months ago

I can get it to build in HAOS now. But I have other problems:

  1. It's unclear on how to expose addon_configs
  2. I don't know why it can't find run.sh exec /run.sh: no such file or directory
b8y-oss commented 5 months ago

Thanks for all of the hard work here. How is this looking?

I'm currently running this as a custom Docker container alongside Home Assistant on a Raspberry Pi 5. For my build, I started with the Docker create and built the image inside of Alpine64. Happy to help if I can.

juanboro commented 5 months ago

I'll take a look at where I left off again soon (been busy with other non smart-home priorities right now). Where I was running into trouble with the docker container as a home assistant addon was with dealing with how to access/edit configuration files like the mesh yaml file in the flow.

I also want to investigate getting this all to run in micropython and also add a mini-web interface to allow doing all the setup (which might also integrate into the HA addon system better). If the micropython part can be done - it would allow running on super cheap pizero-w or esp32 boards as well as standard python environments with the existing code.

juanboro commented 4 months ago

An update here --- instead of going the HACS integration route -- I'm investigating writing a custom component that directly works with HA without MQTT in the middle. This would have the advantage of using the bluetooth components in HA directly - which in addition to the client OS bluetooth stack where they use bleak - also supports the ESP-home bluetooth proxy - which should allow for far less finicky bluetooth mesh connections.

elliotmatson commented 3 months ago

Do you need any help with this? I don't have a whole lot of Python experience, but I do have a 30+ bulb mesh, and 4 ESPhome BT proxies, I'm happy to help test!

juanboro commented 2 months ago

Right now - I just need to find time to work on this. Ideally - the local mesh connectivity can be integrated into this: https://github.com/nikshriv/cync_lights ... I'd like to work on hopefully a branch that I can PR into there.