Tuya Digital Energy Meter add to Energy Dashboard

Hi.
I have installed a Tuya Energy meter (one with a clamp) and I have installed this on my outgowing power from one of my Solar invertors (old one without network).

So far its great I can see in the Tuya app the power generated from that array and in HA I am able to see the live power being generated.

What I have tied to do is create an energy meter that will read from this so I can add it to my Energy Dash board, but so far I can not get this right.

This is what I have so far:

  - sensor:
      - name: "Growatt Solar Import"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.current_energy_generation') }}"

But all it appears to do is match like for like what “‘sensor.current_energy_generation’” is showing, it isnt growing into a total number.

I also tried changing the state_class to just be “total” but it just grew and blew out to a huge number within hours.

Once I do get this working do I need to use an automation to reset it back to zero each night?

Any help on this would be awesome.

Cheers!

sensor.current_energy_generation has a unit of Wh indicating it is an energy sensor, not a power sensor.

Go to Developer Tools → States, copy the attributes of this sensor from the left column and post them here.

Also post a screenshot of this sensor’s history graph.

If this device is doing something stupid like reporting “instantaneous energy” or energy per minute your best course of action would be to calculate the energy yourself by multiplying the current and voltage sensors to get power in a template sensor, then integrating the power with the Riemann Sum approximation sensor to get energy.

Hi Mate.

This is the attributes it returns:

raw_state: 61.8
unit_of_measurement: Wh
device_class: energy
friendly_name: Current Energy Generation

Being this is a Local Tuya intergration I can change this from Energy to Power if needed if that helps.

Please also post

Sorry missed that part

Ugh Tuya!

That is not an energy sensor. So why does it have the unit Wh?

What’s the maximum power output of your solar inverter?

If it is 1kW then that appears to be a power sensor with the wrong unit.

It is an energy sensor from my understanding, my Invertor has a max of 2kw. All this is doing is reading the output from the invertor back to my “grid”. This is what it shows in the Tuya app if that helps.

Being a local tuya item I imported it myself so it is very possible I have set wrong data :slight_smile:


Nope. Energy is not an instantaneous reading like that. It accumulates. Power is an instantaneous reading.

Your unit is wrong. It should be W not Wh.

Your Tuya app is showing a power graph (or it could be energy total per hour, it has no y-axis units so it is not easy to determine) and an energy total in the number above it.

ok I have adjusted the sensor to be W now so it shows as this:
image

Would that make a differnce to the energy sensor I have made:

  - sensor:
      - name: "Growatt Solar Import"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total_increasing 
        state: "{{ states('sensor.current_energy_generation') }}"

Delete that energy sensor you do not need it.

Add this to your home assistant configuration.yaml file:

homeassistant:
  customize:
    sensor.current_energy_generation:
      state_class: total_increasing

Merge it with any existing configuration. You likely have homeassistant: in there already.

Ok I did that but its not showing as an option in the dashboard.

Did you restart after making the changes?

Yup I did

This is what it looks like now

Ugh. Not sure what I was thinking. I got that wrong sorry. Delete this:

  customize:
    sensor.current_energy_generation:
      state_class: total_increasing

Your sensor still has the wrong device class:

image

The device_class should be power, not energy.

And its state_class should be measurement.

And its friendly name should include Power not Energy.