Negative energy reading on the first day of each month

Hi All, I am new to this Home Assistant so I am just finding my feet. On my energy dashboard, I have a negative value on the first day equal to the total energy of the last month. I have no idea how to change this and would appreciate


some assistance. I am certain that it is an easy fix.

Sounds like a problem with monthly resetting. How are you handling that?

I’m not handling it hence the post. I’m certain that it is a simple fix but do not have the knowledge on how to correct it.

Where does this data come from?
Maybe data provider zeroes out previous month by adding negative from previous.

Handling it depends on how it effect you.

Maybe adding that value back will be enough to zero it out. Or maybe set limit to input data that will ignore negatives

Data is from a sonoff clamp meter.
POW Ring Smart Power Meter | POWCT - SONOFF Official
I would like to have a clean start to each month. Is there away of adding the amount on the 1st of the month to counter it or just a way to force a zero at the beginning of each month.

How would i set a limit to ignore negatives?

From the image in your original post, it looks as if you are using a sensor entity (POWCT Energy Month) that resets to zero every month. You need one that increases continually.

The problem is to do with a wrong state_class on your sensor, combined with the fact that it resets. The resetting itself is not per se bad, but it is when it does not match the state class.

  1. Is the sensor you use one you created yourself (e.g. via a template) or from n integration?
  2. Can you show the entity you use in the developer tools?
1 Like

@Edwin_D is already going in the right direction, but to fix your history got to developer tools, statistics and click on the graph icon of the entity. Then you either can look for Outliers or set the time and date to the 1st of March (you max need to cycle through multiple time settings to find the right one). If you see a negative value simply set it to 0.

For the state_class you need to read this Energy Dashboard shows odd entry on graph after midnight - #5 by karwosts
If none of this applies to your sensor, use customize.yaml to overwrite the state_class.

I have the same issue and here is how I fixed it.

You need an input number which records the maximum value from your meter;
an automation to detect when the clamp meter resets; and the logic in the sensor to output the correct increasing value to the energy dashboard.

Here is the input number YAML - in my case in an input_number.yaml file, itself defined in the configuration.yaml.

Input number code.

# Helper to store accumulated resets #
energy_reset_accumulator:
 name: Energy Reset Accumulator
 min: 0
 max: 1000000
 step: 0.01
 unit_of_measurement: kWh

Here is the meter detection code with my meter defined. If the to_state (where we are going, numerically) is less than the from_state, where we are then do the action of writing into the input number. This code goes in the automations.yaml file.

- alias: Detect Energy Meter Reset
  trigger:
  - platform: state
    entity_id: sensor.dcc_sourced_smart_electricity_meter_usage_today
  condition:
  - condition: template
    value_template: '{{ trigger.to_state.state | float(0) < trigger.from_state.state
      | float(0) }}'
  action:
  - service: input_number.set_value
    data:
      entity_id: input_number.energy_reset_accumulator
      value: '{{ states(''input_number.energy_reset_accumulator'') | float(0) + trigger.from_state.state
        | float(0) }}'
  id: 5fe338089901445e8134440addc296f8

The energy source sensor code. This goes in the template.yaml file.

# Meter Electricity #
- sensor:
  - name: "Electricity Meter Energy"
    unique_id: "0139b869-dc74-45da-9cea-f8fd098f21db"
    unit_of_measurement: "kWh"
    icon: mdi:lightning-bolt    
    state_class: total_increasing
    device_class: "energy"
    state: >
      {% set current = states('sensor.dcc_sourced_smart_electricity_meter_usage_today') | float(0) %}
      {% set reset_accumulator = states('input_number.energy_reset_accumulator') | float(0) %}
      {{ current + reset_accumulator }}

In case you have not separated your configuration here is the post on that and what my configuration.yaml file looks like.

### Includes ###
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template: !include template.yaml
sensor: !include sensor.yaml
sql: !include sql.yaml
input_number: !include input_number.yaml