This is the code I use to monitor my heatpump and publish its values via MQTT. In my case, I have Home Assistant which is listening to the MQTT topic and receiving the data.
I have connected a H1-interface from Husdata (www.husdata.se) to a Raspberry Pi Zero Wireless, which runs the code. Clone the repo and create a .env-file in the repository folder which contains the below.I'm not really sure about the discovery-part of mqtt right now, I'm just testing it out.
MQTT_SERVER = "YOUR SERVER"MQTT_TOPIC = "MQTT TOPIC"
MQTT_DISCOVERY_TOPIC = "DISCOVERY TOPIC"
Install the requirements by running "pip3.12 install -r requirements.txt" The service is installed as /lib/systemd/system/heatMon.service and requires "screen" to be installed. In this way, I can always attach to my service and monitor what it does. I connect to the service with "screen -r heatMon"[Unit]
Description=HomeMate heatMon
After=multi-user.target
[Service]
Type=forking
User=pi
ExecStart=/usr/bin/screen -dmS heatMon ///python3.12 //heatMon.py
[Install]
WantedBy=multi-user.target