Shelly EM returning 0 value and energy readings resettig

I have a Shelly EM energy monitor which is posting data to a MQTT server to use with Home Assistant, around twice a day there is a value of zero being submitted for the total energy used which is causing the new energy dash board to show the full amount of KWH used to be the daily total rather than the difference for the day.
The code I am using to create the sensor is :

- platform: mqtt
  name: Loft Shelly Workbench Total
  state_topic: "shellies/shellyemloft/emeter/1/total"
  value_template: "{{ (value  | float /1000) | round(3)  }}"
  unit_of_measurement: kWh   
  scan_interval: 300

The template sensor used by the energy dashboard is

- platform: template
  sensors:  
    energy_shelly_oven:
      device_class: energy
      friendly_name: "Energy Shelly Loft Oven"
      attribute_templates:
        state_class: total_increasing
        device_class: energy
      unit_of_measurement: 'kWh'
      value_template: "{{ states('sensor.loft_shelly_oven_total') | float | round(3) }}"
      icon_template: mdi:mdi-current-ac  

Does anyone know why this could be happening and how to fix it?

I use the core Shelly integration with my EM and do not have this issue.

The problem you are experiencing is the |float filter converting the state unavailable to 0.

If you don’t want to use the core integration you can fix this with an availability template in your sensor and an availability topic and payload in your mqtt sensor.

Thank you for the suggestion, I will remove all my MQTT entities and use the core Shelly integration to see if it solves the issue.