Publish data from rpi-power-monitor to MQTT
Building on the amazing work at https://github.com/David00/rpi-power-monitor/wiki, this script will export data from influx and send it to an MQTT server. My specific use case for this is to bring the data into Home Assistant, but this could certainly used for many other purposes.
You'll need to install the InfluxDB and Mosquitto clients that the script uses.
apt-get install influxdb-client mosquitto-clients
Copy the powermon-mqtt.sh script to /home/pi
Edit the cron tab with the command "crontab -e" and enter the example below, substituting your MQTT server and prefix. If your server uses authentication, edit the script and update the variables.
Example cron tab:
* * * * * /home/pi/powermon-mqtt.sh [mqtt-server] [mqtt-prefix]
This can be added to Home Assistant as an MQTT sensor, such as:
- platform: mqtt
name: "Powermon CT 0"
state_topic: "powermon/ct_0/power"
icon: mdi:electron-framework
unit_of_measurement: 'W'
- platform: mqtt
name: "Powermon Power Home"
state_topic: "powermon/home_load/power"
icon: mdi:electron-framework
unit_of_measurement: 'W'
You can also add an integration sensor which will add this power source to the Energy Grid.
- platform: integration
source: sensor.powermon_power_home
name: powermon_energy_spent
unit_prefix: k
round: 6