kWh to Price per kWh conversion

Hey everyone,
So I hooked up my Sonoff to my Air-Conditioner and I made a dashboard for it.

just threw everything I had for inputs on the top graph then I broke them out below. But I added a KWH measurement and got to thinking it be fun to also have what that is in Dollars. So I get charged
I’m going to just call it $0.10582 per kWh.

What is the best way to do that equation as a conversion and pull it in as a dashboard widget?

There are 2 easy ways:

Create a conversion from kwh to a currency, then select that conversion on the input configuration. This will prevent the kwh measurement from being stored.

Use an Equation Function to apply an an equation to an input value (kwh measurement).

Thanks Kyle! So I started with the equation as this seemed simpler for me.

So i’ve had the AC running for a while now and if it turned out that equated to $4.25 i’d not be suprised. I think its working or at least the best I can tell! Might be fun to figure out how to check what month it is and then assign the correct formula down the road but that seems like a python script to me for some reason, I’m going to see if I can figure out the kwh to a currency part you were speaking of.

I think I configured something wrong but seem to be close.

Why not use the Energy Usage pages?

Oh good point.

So at first I gave it kWh as an input and it seemed wrong but with amps this looks right. So the AC has cost me $1.73 today and $12.21 for the week.

The bottom portion is that 0’s because I don’t have enough data?

Your graph having such a long X-axis duration suggest the majority of your graph is filled with values of 0 (or near 0). Since the calculation is based on the average for a period, your monthly average is near 0.

You can review the code at:

Interesting, Thanks for showing the code. Hard to know whats for what sometimes.

There’s an obvious room for improving the code, since you have actual non-0 values in the time frame it’s calculating. It’s all about making the right influxdb query to get an accurate Amp value to calculate kWh. Average doesn’t seem to be the most appropriate.