Calculate energy usage

I’m new to Homeassistant, have been using domoticz for couple of years. Now I’m trying to do the following:

I have a energysensor (aqara smart plug) that shows watt and kwh. Now I want to know how much kwh it has used, but I cant reset the kwh by code. So what I would like to do is end kwh value - start kwh value, where start is when watt > 1 and end watt > 1 (the plug uses 0,5 watt).

Now I can make custom sensors and set the watt values (start, end) and then calculate the difference and set this value in another sensor. But I found out that setting values in custom sensors is not something that is possible in Home Assistant. I found a script that can set the value of a sensor.

This all seems a little bit devious, is there a better\easier way to do this?

What do you mean by “custom sensor”?

You can make a helper sensor and then set that.

Template sensor in configuration.yaml, how do I create a helpersensor?

Settings → Devices & Services → Helpers pane → + Create Helper in lower right corner

ah tnx, I was using the configuration file for some other sensors so I thought I had to do the same for “dummy” sensors.

You could do that once and you might be able to do it still, but the GUI is just easier for this.