Scally-H / RedReactor

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

mqtt -->> homeassistant #10

Closed nsk closed 10 months ago

nsk commented 11 months ago

hi ,

I see the information in mqtt explorer when I run the script, is it possible that the redreactor is recognized directly by homeassitant to be able to publish the data received by mqtt

thx

Scally-H commented 11 months ago

I'm pleased to say that another customer has kindly refactored the RR_MQTT client to enable you to select it as an add-on within the HAOS Homeassistant application, which you can find here:

https://github.com/mreditor97/homeassistant-addons

From memory, you'll need to add that path to the add-on search repos when using the HAOS install and it should show up as a Red Reactor add-on. From the link above you may be able to follow up with any specific questions on that repo and using it without the full HAOS install.

mreditor97 commented 11 months ago

Hi @nsk, I created a Home Assistant Add-on that automatically does all of this for you. There is also the option to run this directly within a docker container, or just natively on your OS. What operating system are your currently using?

For HASS OS. You can find instructions here: https://github.com/mreditor97/redreactor/wiki/home-assistant-os

For within a Docker container (this hasn't been tested yet, but should work): https://github.com/mreditor97/redreactor/wiki/docker

Scally-H commented 11 months ago

@mreditor97 - That's great, thanks again.

nsk commented 11 months ago

@mreditor97 running on docker "Core" version ..... I will test your script and I will give you news , in any case when I listen via home assistant the data arrives but it does not detect the redreactor ->>

Message 1 reçu sur socket.Redreactor/RedReactor/Data à 22:51 : { "RR_volts": 1.23, "RR_current": 0, "RR_charge": 0, "RR_extpwr": true, "RR_CPUTEMP": 59.4, "RR_CPUSTAT": 0, "RR_WARN": 10, "RR_VMIN": 2.9, "RR_INTERVAL": 30 } QoS: 0 - Retain: false Message 0 reçu sur socket.Redreactor/RedReactor/Service à 22:50 : online QoS: 0 - Retain: true

mreditor97 commented 11 months ago

@nsk The results that you have there are from the original version. Not my fork, which is available at https://github.com/mreditor97/redreactor

It can be installed by using pip install redreactor to install the Python package.

nsk commented 11 months ago

pip install redreactor Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple ERROR: Could not find a version that satisfies the requirement redreactor ERROR: No matching distribution found for redreactor

mreditor97 commented 11 months ago

It is available on PyPi: https://pypi.org/project/redreactor/

I think you'll have to use the standard index not the simple index?

nsk commented 11 months ago

hi, so I started from scratch with a new installation latest version raspi os, and I also installed homeassistant (supervisor), I find myself at this stage, I am not used to python virtual environments, I am testing ... is there a way to create a service so that it starts automatically when the raspi boots like I did before? thank you for the help you give me.

mreditor97 commented 11 months ago

Is there any reason why you have chosen Raspi OS over HASS OS? If you don't need Raspian, it could be worth changing to HASS OS instead.

However, it is possible to create a startup script to start the Python virtual environment on boot like you are asking. I have a systemd example script: https://github.com/mreditor97/redreactor/blob/master/extras%2Fredreactor.service

I hope this helps you get it setup

nsk commented 11 months ago

HI , there is another reason, I have a Raspbee II connected and also a Metriful MS430: Environment Sensor : https://github.com/metriful/sensor connected mounted on my raspi 4. et another question is should I clone the original repo of the redreactor or your module is completely independent of it ??

and I'm also experimenting quite a bit so I need to have access to my complete system I had already tested Hass os, but you can't do much afterwards.....maybe I'll install it later on my visionfive 2 as backup but later

mreditor97 commented 11 months ago

My repo is completely independent of the original one. However, there shouldn't be any need to clone my repo. You should be able to install it in a Python virtual environment - probably the best way for you currently.

I can take you through that process if it helps you?

Then I'd use systemd to create an automatic startup sequence - I can give you some systemd file creation pointers if it helps. The systemd file that you would be creating would look very similar to my example one at extras/redreactor.service within my repo.

nsk commented 11 months ago

I'm already looking to install your system but no redame or installation instructions on your repo, think that the people who visit are not all coders or developers a bit like me, a detailed installation procedure could be a good thing to have add

mreditor97 commented 10 months ago

I haven't had chance to create a proper wiki article for a standard system installation, usually you'd run something like this in a docker container. For now, here is some instructions on the installation process and running within a python virtual environment.

# Install Python 3, PIP and Python Virtual Environment
apt-get install python3 python3-pip python3-venv

# Create your Python Virtual Environment
python3 -m venv /var/lib/redreactor/.venv

# Install Red Reactor program into the Python Virtual Environment
/var/lib/redreactor/.venv/bin/python -m pip install redreactor

# Create your Red Reactor configuration
Configuration example: https://github.com/mreditor97/redreactor/blob/master/extras/config.yaml
Store the file (for this example) in: /etc/redreactor/config.yaml

# Run the Red Reactor program from within the Virtual Environment
/var/lib/redreactor/.venv/bin/python -m redreactor --config=/etc/redreactor/config.yaml --log=/etc/redreactor/redreactor.log

For starting on boot:

# Moving into the systemd service folder
cd /etc/systemd/systemd

# Create a redreactor.service file
nano redreactor.service

# Copy in the contents of the example file
Example: https://github.com/mreditor97/redreactor/blob/master/extras/redreactor.service
Change the user you'd like to run the program under, currently running as user redreactor

# Reload Systemd Daemon
systemctl daemon-reload

# Start the Red Reactor service
systemctl start redreactor.service

# Check the status of the Red Reactor service
systemctl status redreactor.service

# Enable the Systemd service to start on boot
systemctl enable redreactor.service

I hope this helps and gets you on your way to making it work as you'd like! I have written a more comprehensive version here within my wiki

nsk commented 10 months ago

I'm testing I'll keep you posted, thank you, Happy Merry Christmas to you

nsk commented 10 months ago

hello, happy new year thank you very much it works, Happy New Year to you

Scally-H commented 10 months ago

Happy new year to you too. @nsk glad you got it working and @mreditor97, really appreciate your help, thank you! I'll close this issue now.