Monday, 5 October 2026

Adding a MQTT device to RPi4 running Home Assistant

So yesterday (Sun 4th Oct 2026) I shutdown cottage laptop which was running Home Assistant in a docker container and installed a Home Assistant image on the a RPi4 (was muc in Kilnageer).

Things went well but now I would like to create some devices of my own based on their MQTT topics.

I can access the RPi HA at http://192.168.1.188/home/overview

And yesterday I added to it three air sensors but not sure of their status.

So what I need is HA Discovery. This video explains: https://www.youtube.com/watch?v=s7SKzYWNVS8

And in fact the https://github.com/jesseklm/sungrowmodbus2mqtt code running on sionnach (192.168.1.153) already has a https://github.com/jesseklm/sungrowmodbus2mqtt/blob/master/ha_discovery.py file.

So let's try using it!

(Mon 5th Oct 2026)

21:07 What is sionnach running currently...


(base) coderdojo@rhubarb:~$ !ssh
ssh -X pi@192.168.1.153
pi@192.168.1.153's password: 
Linux sionnach 6.12.93+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.93-1+rpt1 (2026-06-12) aarch64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.
Last login: Mon Oct  5 20:23:58 2026 from 192.168.1.191
pi@sionnach:~ $ 
pi@sionnach:~ $ date
Mon  5 Oct 21:09:24 IST 2026
pi@sionnach:~ $ sudo systemctl status pollSungrowInverter.service 
● pollSungrowInverter.service - Sungrow Hybrid Inverter Eth0 Modbus Monitor
     Loaded: loaded (/lib/systemd/system/pollSungrowInverter.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-10-05 16:09:11 IST; 5h 0min ago
   Main PID: 3146639 (python3)
      Tasks: 1 (limit: 8743)
        CPU: 24.825s
     CGroup: /system.slice/pollSungrowInverter.service
             └─3146639 /usr/local/bin/python3 /home/pi/sungrowmodbus2mqtt/sungrowmodbus2mqtt.py
Oct 05 16:09:11 sionnach systemd[1]: Started pollSungrowInverter.service - Sungrow Hybrid Inverter Eth0 Modbus Monitor.
Oct 05 16:09:12 sionnach python3[3146639]: 2026-10-05 16:09:12,041 - INFO - starting SungrowModbus2Mqtt v1.0.36.
Oct 05 16:09:12 sionnach python3[3146639]: 2026-10-05 16:09:12,155 - INFO - mqtt disconnected.
Oct 05 16:09:12 sionnach python3[3146639]: 2026-10-05 16:09:12,248 - INFO - modbus connected.
Oct 05 16:09:18 sionnach python3[3146639]: 2026-10-05 16:09:18,169 - INFO - mqtt connected.
pi@sionnach:~ $ cd sungrowmodbus2mqtt/
pi@sionnach:~/sungrowmodbus2mqtt $ ls
background_tasks.py         config.yaml.2026_09_17  modbus_handler.py  sungrowmodbus2mqtt.py
config.py                   config.yaml.backup      mqtt_handler.py    typescript_1_got_returned_values.txt
config.sh10rt.example.yaml  Dockerfile              __pycache__        uv.lock
config.sh20t.example.yaml   ha_discovery.py         pyproject.toml
config.yaml                 LICENSE                 README.md
pi@sionnach:~/sungrowmodbus2mqtt $ head config.yaml
mqtt_server: "192.168.1.150"
mqtt_port: 1883
mqtt_username: pi
mqtt_password: 2016TolaPark!
mqtt_topic: sungrowmodbus2mqtt/
ip: 169.254.12.12 # ip of Sungrow LAN-Port
slave_id: 0x01
update_rate: 2 # pull rate in seconds
pi@sionnach:~/sungrowmodbus2mqtt $ 


What does this MQTT publish?






No comments:

Post a Comment