cyrils / renogy-bt

Python library to read Renogy compatible BT-1 or BT-2 bluetooth modules using Raspberry Pi.
GNU General Public License v3.0
76 stars 27 forks source link

installing directly in HA #24

Open Abudinka opened 10 months ago

Abudinka commented 10 months ago

I am running a Raspi4 B with native installation of HA.

It seems like there is no easy way to build libscrc on that machine. I was wondering if anybody could supply a binary for that or one could get rid of the dependency, so we could run this script on native HA?

cyrils commented 10 months ago

I've removed libscrc dependency.

Abudinka commented 10 months ago

well now iam dealing with missing dbus, probably gonna look at Issue #12 and google a bit.

edit: i am indeed running into the same issues as @marcuslib did, now something about 'gi' - no idea what this is

could go with the nested docker, but not sure if i like it. overhead seem a bit unnecessary. but a new HA/debian based raspi installation seem overkill as well.

cyrils commented 10 months ago

Were you able to resolve the issue? May be installing dbus-python will help

Abudinka commented 10 months ago

unfortunately no, terminal says dbus is installed, but wont find it when running the script.

when i finally got dbus out of the way, its complaining about gi instead

i dont know if the script some kind of raspberry exclusive, but couldnt make gatt work with ubuntu either

marcuslib commented 10 months ago

I got it to work in the end by installing HA in docker and then had to install python within a VM. To run it i then had to create a service to run the python script, it will also check if its running and if not run it, as I did find it took a few times to run the script for it to pickup the BT-1.

Abudinka commented 10 months ago

I got it to work in the end by installing HA in docker and then had to install python within a VM. To run it i then had to create a service to run the python script, it will also check if its running and if not run it, as I did find it took a few times to run the script for it to pickup the BT-1.

yes, i noticed. But i dont want to move HA back to docker. I used to use docker, but couldnt use addons, so i switched to native.

I dont really understand why gatt is behaving the way it does. maybe we can dockerize the whole thing to make it easier? i tried something along the lines, but ran into the very same issues. plus you need some way to expose bt to the docker.

I will most likely try a different ble interface and clone the renogy logic, dont know tbh

Abudinka commented 8 months ago

update: since the SoC supplied by the bluetooth is not accurate, so there is no need to implement it in HA for me

didi767 commented 8 months ago

@Abudinka is there a guide on how to implement this in HA? I'm not an expert, but I was planning to install Ubuntu and then HA on my orange pi zero 3. Im sure it would be an adventure to figure this out, but if you have any clear steps on how to achieve it that would be awesome. At first i thought about going with the RS485 method until I saw that we can actually interpret the BL2, which is amazing!

Abudinka commented 8 months ago

sorry cant help here, as i said i dropped attempting renogy bluetooth communication since there is nothing to gain for me. if available i recommend using the home assistant raspberry pi image directly instead of using ubuntu. initially i used ubuntu and HA docker, but it has some drawbacks like no addon support. switched to raspberry pi 4B and used the HA image available in Raspberry Pi Imager.

lbeckingsale commented 7 months ago

I'd still be interested in getting this to work directly in HA. I'll have a tinker with it and see if I can work it out.

cruscio commented 7 months ago

Ran into Module 'dbus' not found on headless Raspberry PI. Something in all of this fixed it:

pip3 install --user -r requirements.txt
sudo apt-get install python3-dbus
sudo apt install libdbus-1-3 libdbus-1-dev
sudo apt-get install libglib2.0-dev
sudo apt install python3-pydbus
python3 -m pip install --user dbus-python

And then I ran into

  File "/home/cruscio/.local/lib/python3.12/site-packages/gatt/gatt_linux.py", line 13, in <module>
    from gi.repository import GObject
ModuleNotFoundError: No module named 'gi'

Which should be fixed by running

pip3 install --user PyGObject

But that fails ... So then:

sudo apt install libcairo2 libcairo2-dev
pip3 install --user PyGObject

Another new failure. Log says to install libgirepository1.0-dev

sudo apt install libgirepository1.0-dev
pip3 install --user PyGObject

Finally! The PyGObject install worked, though it might have been easier to install libgtk2.0-dev (which a stackoverflow post for libglib2.0-dev mentioned

And now I get

ModuleNotFoundError: No module named 'requests'

./facepalm

pip3 install --user requests

ANNNNND finally ...

python3 ./example.py config.ini
INFO:root:Init BatteryClient: BT-TH-XXXXXXXX => XX:XX:XX:XX:XX:XX
INFO:root:Adapter status - Powered: True
INFO:root:Starting discovery...

Couple thoughts:

  1. @cyrils - It seems a few requirements are missing from requirements.txt (not complaining. I definitely appreciate all the work you've shared here. Just wanted to call out that it may be worth adding all the requirements to requirements.txt :) )
  2. I don't understand why there are so many things (glib2, cairo, GObject) that seem tied to GTK in a non-gui application...? (maybe this has something to do with accessing BT?)

Now if only I could figure out how to discover my battery info without needing to dismantle my battery box to muck with the daisy chain. (Bluetooth logging while running the android app shows chatter in wireshark, but I'm not smart enough to decipher it :( )

Anyway - I hope this helps others with similar issues.

cyrils commented 7 months ago

Hm.. I think the gatt library uses these for some reason. A regular raspberry pi image includes all of these by default, never tested it over headless image. Doesn't hurt to include them into requirements.txt though.

And unfortunately the app does not show the device id. Currently the only way to get the individual Ids is to connect one device at a time. However you can try some usual suspects for batteries:

33, 34, 35.. series
48, 49, 50..
97, 98..
247, 248..