Bulb energy electic meter integration occasionally send spurious zero reading which messes up energy integration stats

I have Home Assistant energy integration linked to my Bulb energy electricity meter via SmartThings.

state_class: total_increasing
unit_of_measurement: kWh
friendly_name: Bulb Energy Meter Energy Meter
device_class: energy

Although it claims to send an every increasing total, it does occasionally give zero readings before resuming the total.

Poking in the db shows this:

select e.event_id, e.time_fired, s.state
from states s
join events e on (s.event_id = e.event_id) 
where s.entity_id = 'sensor.bulb_energy_meter_energy_meter'
and e.time_fired between '2021-10-28 10:10:00' and '2021-10-28 10:30:00'
order by e.time_fired
event_id|time_fired             |state  |
--------+-----------------------+-------+
  155828|2021-10-28 10:11:33.665|364.752|
  155836|2021-10-28 10:12:34.486|364.753|
  155841|2021-10-28 10:13:31.462|364.756|
  155852|2021-10-28 10:14:31.630|364.761|
  155893|2021-10-28 10:17:26.620|0.0    |    <----  ???
  155932|2021-10-28 10:19:31.032|364.765|
  155944|2021-10-28 10:20:23.509|364.769|
  155957|2021-10-28 10:21:22.368|364.772|
  155981|2021-10-28 10:22:20.462|364.773|
  155988|2021-10-28 10:23:18.421|364.774|
  155999|2021-10-28 10:24:16.388|364.777|
  156008|2021-10-28 10:25:15.517|364.78 |
  156015|2021-10-28 10:26:15.421|364.783|
  156025|2021-10-28 10:27:13.436|364.785|
  156035|2021-10-28 10:28:12.713|364.786|
  156043|2021-10-28 10:29:10.420|364.787|

Consequently, HA’s energy integration thinks I used ~350 kWh today
image

Any ideas on how I can:

  • Stop this from happening again?
  • Fix the historical data that the energy integration is using? Is it sourcing data from the state table or has it already aggregated it elsewhere?

I have the same issue with bulb via smartthings. Did you solve this?

I was thinking to make a template sensor which uses the reading from the bulb sensor but also uses the availability template to mark itself as unavailable if the reading is zero.

This thread describes how I propose to avoid the issue with the bulb sensor using a template and how to amend the existing statistics to try and correct them - How to fix statistics data (e.g. energy data)?