I have a sonoff POW2 to control my hotwater heater.
The POW sends power usage via MQTT to homeassistant, where I add todays total to the cumulative total from yesterday to get the total usage.
But I am getting lots of zero’s appended to the end of the total that I cant fix.
Sensor that holds the cumulative total says:
Entity
sensor.hotwater_cumulative_total
State
8.544
The mqtt message from the POW
12:24 - tele/tasmota_9BDF5A/SENSOR {"Time":"2021-08-16T12:24:01","ENERGY":{"TotalStartTime":"2021-08-05T04:47:39","Total":2.903,"Yesterday":0.000,"Today":2.903,"Period":0,"Power":0,"ApparentPower":0,"ReactivePower":0,"Factor":0.00,"Voltage":0,"Current":0.000}}
The automation that adds the numbers and republishes it to the senors
action:
- service: mqtt.publish
data_template:
topic: "hotwater"
retain: true
payload: '{"updated":"{{ now().strftime("%H:%M") }}","power":{{ trigger.payload_json.ENERGY.Power }},"current":{{ trigger.payload_json.ENERGY.Current }},"voltage":{{ trigger.payload_json.ENERGY.Voltage }},"today":{{ trigger.payload_json.ENERGY.Today }},"total":{{ ((trigger.payload_json.ENERGY.Today | float) + (states("sensor.hotwater_cumulative_total") | float) | round(3)) }} }'
The mqtt messages which results
12:24 - hotwater {"updated":"12:24","power":0,"current":0.0,"voltage":0,"today":2.903,"total":11.447000000000001 }
I would like it rounded to 3 decimal places to display in a gauge card.
What have I done wrong ?
EDIT: Just noticed it doesnt happen all the time. It sometimes displays correct and other times it doesnt.
The two recent mqtt messages, first one total with lots of zero, second one correct:
12:42 - tele/tasmota_9BDF5A/SENSOR {"Time":"2021-08-16T12:42:01","ENERGY":{"TotalStartTime":"2021-08-05T04:47:39","Total":3.559,"Yesterday":0.000,"Today":3.559,"Period":84,"Power":2554,"ApparentPower":2566,"ReactivePower":247,"Factor":1.00,"Voltage":246,"Current":10.413}}
12:42 - hotwater {"updated":"12:42","power":2554,"current":10.413,"voltage":246,"today":3.559,"total":12.103000000000002 }
12:46 - tele/tasmota_9BDF5A/SENSOR {"Time":"2021-08-16T12:46:01","ENERGY":{"TotalStartTime":"2021-08-05T04:47:39","Total":3.726,"Yesterday":0.000,"Today":3.726,"Period":83,"Power":2515,"ApparentPower":2524,"ReactivePower":215,"Factor":1.00,"Voltage":245,"Current":10.323}}
12:46 - hotwater {"updated":"12:46","power":2515,"current":10.323,"voltage":245,"today":3.726,"total":12.27 }