This should accomplish what you’re after. It’s set for the billing cycle to reset on the 20th now, but you can change that in the variables at the top if you necessary.
This piston stores a sliding window of 1 month of consumption. It does this by storing the energy value off your HEM daily, and then subtracting the previous days energy level to get an increase for today.
The first block in the “every day at 11:59pm” section sets a “previous day” variable. This is needed to do the math that determines daily use in an array.
The first IF statement checks to see if tomorrow is the 1st of the month, meaning today is the last day of the month. If it is the last day of the month, any data previously stored in the array will be set to zero. This won’t serve any purpose for a while… but in June when there are only 30 days, it will zero out the energy stored in your array for May 31st.
The second IF statement takes the entire month and calculates consumption on the day your billing cycle ends.
I’ve tested this as much as I can by building up bogus arrays (harder than actually writing the piston!)… it should be a good start. Let it run for a bit and let me know if you’re seeing anything odd… or if you want something added to it. With the data stored in variables you should have the ability to put all kinds of stuff in your Piston State if you’d like.