Scally-H / RedReactor

Sample code for the Raspberry Pi Red Reactor UPS and technical documentation
20 stars 1 forks source link

Home Assistant #5

Closed nsk closed 1 year ago

nsk commented 1 year ago

Hello how to integrate into home assistant my node-red works in a docker container how to send the information to see the dashboard on homeasisstant

Scally-H commented 1 year ago

I am not sure I fully understand your question, but if you mean to run our RR_MQTT client in Docker then I expect that to be possible. It will need to be able to access the I2C interface for battery information, and communicate via the python MQTT library to your MQTT broker's IP address. I am not sure if it needs any other access rights (maybe to get CPU status info?). You should maintain the TXD pin configurations as defined in our manual to ensure this is configured during boot.

Presumably your Homeassistant client can subscribe to the same topics as published by RR_MQTT to your NodeRED system. The RR_MQTT JSON data structure is described in our GitHub RR_MQTT folder, so you can extract the data from there into Homeassistant.

I hope that helps, but let me know if you mean something different.

Scally-H commented 1 year ago

Thinking some more about putting RR_MQTT into a docker container, I wonder if it really makes sense because it has to be able to trigger a shutdown on low battery. Being inside a virtual machine means you have to circumvent the default protections of the VM and enable access to these system commands.

I created a docker image, with e.g. python:3.10-slim-buster , and a python requirements file:

paho-mqtt==1.6.1
PyYAML==6.0
pi-ina219==1.4.0

and enabled access to I2C when running the image

docker run --device /dev/i2c-1 image_name

then I can see RR_MQTT reporting the battery status to an externally hosted broker but this image doesn't have sufficient control of shutdown/reboot - you will need a more complete OS image inside the docker container and/or extend the VM's control over the Pi itself to achieve that. Likewise, this image can't run vcgencmd to access CPU voltage throttling and temperature status, so you may need to start from a Debian image and expand from there, or have access to systemctl.

I'd be happy to hear of a Dockerfile and run configuration that deals with these issues and add it to this repository.