Problem with adding sensor states numbers

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.

guage-card-2

guage-card

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 }

It’s probably due to epsilon error and nothing you can do to avoid it but there’s something you can do to mitigate it (convert the value to a string). Refer to this post:

{{ '{:.3f}'.format(value) }}

Hi, thanks for the reply.
I tried what you suggested, but it doesnt work. There is no errors when I CHECK CONFIGURATION.
This is what I put

"total":{{ "{:.3f}".format( (trigger.payload_json.ENERGY.Today | float) + (states("sensor.hotwater_cumulative_total") | float) ) }} 

What I don’t understand is that the 2 numbers I am trying to add are to 3 decimal points anyways.
I have tried without rounding which didn’t make any difference.

EDIT: Maybe it is working. The first update didnt work but the 4 after have.

Let it run for awhile and then report back if you do or don’t see values with many decimal places.

If you wish, you can also write the template this way:

"total":{{ "{:.3f}".format([trigger.payload_json.ENERGY.Today, states("sensor.hotwater_cumulative_total")] | map('float') | sum) }}