Calculating power cost using utility meter

you can share the code?
I want to calculate the current usage of 8-9 sensors
THANK YOU

I believe I am calculating the cost correctly and I see my sensor showing this

However when I add this entity to my dashboard it is negative. Rookie mistake or…?

Any thoughts?