I have a clamp sensor on my power usage, and a readout of generation from my sma inverter.
But currently it adds them to gether for the home usage, where as i need to create a virtual sensor that takes the clamp reading and minuses the solar output to get what is being taken from or fed back to the grid…
How can i do that??? (PS, complete noob new to Home Assistant)
Ok, ive gotten closer… see code below. My issue now is that it expects a positive for grid consumption…
so on a day that i have exported more then i have used, the virtual sensor is negative… i need to work out the maths etc to only count up not down. and then create another one that does the opposite for sold back to the grid…
ORRR, if its negative to only report zero as a rule???
OK, worked out a solution. The devices also create sensors for Watts (power).
So by doing the same maths equations i can work out the instantaeous power being consumed from the grid or sent back to the grid. I then used the Integration - Riemann sum integralto create a energy sensor for both and then used that in the energy tab for solar to grid and power used from grid…
Took some googling and sooo many reloads, but i got it and so far happy, not sure of the accuracy, but a good overlook…