Help configuring energy

I give up trying by myself. It’s been 3 days constantly trying different things but I can’t find the solution. But I bet it is a very simple thing for you guys.

I’m trying to get the nice energy graph to work with the total power from my house. I can get this graph working just fine with ESPHOME using the ADS1115 like this:

> sensor:
>   - platform: ads1115
>     multiplexer: 'A0_GND'
>     gain: 2.048
>     name: "ADS1115 Channel A0-GND"
>     ads1115_id: ads1115_0 
>     update_interval: 2s
>     id: sens0
> 
>   - platform: ct_clamp
>     sensor: sens0  #adc_sensor
>     name: "Measured Current 0"
>     update_interval: 2s
>     sample_duration: 700ms
>     accuracy_decimals: 5  
>     id: ampere_ct1
>     device_class: current
>     unit_of_measurement: A  
>     filters:
>       - lambda: |-
>           if (x < 0.0040) return {0};
>           float rs = 22.2;
>           return {rs * x};
> 
>   - platform: template
>     name: "Puissance"
>     lambda: |-
>       if ( id(ampere_ct1).state <0) {
>         return 0;
>       }
>       return( 120 * id(ampere_ct1).state);
>     accuracy_decimals: 2
>     update_interval: 5s
>     state_class: measurement
>     device_class: power
>     unit_of_measurement: "W"
>     id: ac_puissance
> 
>   - platform: total_daily_energy
>     name: "Total Daily Energy"
>     power_id: ac_puissance
>     filters:
>         - multiply: 0.001
>     unit_of_measurement: kWh
>     device_class: energy
>     restore: False
>     state_class: total_increasing

This is working fine for my coffee machine. This is using the platform “total_daily_energy” in the energy card as expected. What I want to do is to bring the total wattage from my already existing system that I built several years ago (which is working already perfectly good after many many fine tuning). So I added a POST tcp line in my old system to bring the actual running wattage in home assistant. For now, it is coming in a counter. Like this;

I understand that I would need to bring this wattage into a usage kwh. I used an INTEGRAL HELPER to accumulate the usage. Like this:

This helper seems to be doing its right calculation. But since it is not a device_class = energy and not either a state_class = total_increasing, and it doesn’t have any unit_of_measurement, then it is not available to the energy card.

I tried so many different things, but I couldn’t get it right. What am I missing?

I’m confused what is counter.energie. Is it watts? kWh?

Why is it a counter? Seems like an odd domain.

Ideally you could get:

  • A sensor, device_class: power, state_class: measurement of current consumption in Watts or Kilowatts
  • A riemann sum integral of that sensor, which would give you an energy sensor with the correct unit, device_class, and state_class.

Not sure why I used a counter. I think at the beginning it was a place I could send a number from my old system.

Can you give me a sample of how to create the sensor you suggested? I’m new to HA and I dontknow how to create a sensor without an actual device.

Please explain to me what data is coming in. Is it power (W) or energy (Wh)? How does it get updated?

It comes in Power (W). It is updated every second or 2.

You can make a template power sensor like so (keeping the counter for now):

Helpers → Create Helper → Template → Sensor.

State template should be I think: {{ states('counter.energie') }}
Unit of measurement: W
Device Class: power
State class: measurement

This will give you a sensor with the power measurement.

Create a riemann sum from this sensor. Once it updates once, it should have the correct properties for energy dashboard.

Ok great, I’ll try this tonight. Thanks

OK, That works!!! Haaaa Thank you so much…
It seems simple when you know it. :wink:
Just have to figure out how to get rid of all the deleted sensors that appears when I go to select a NEW CONSOMPTION. They are only ghosts. They have been deleted but they keep appearing.

Thanks again !

ha! All clean now. I went in DEVELOPPER TOOLS, STATISTICS, and pressed the FIX ISSUE beside the sensor. Thanks

@karwosts One more question, In this scenario, is it normal that the riemann sum sensor keeps incrementing for ever? I’m afraid that it will eventually crash when it gets over its limit.

Yes that’s normal. There is no limit.

1 Like