Reset HEM on specific days


#1

1) Give a description of the problem

I’m trying to build on Nezmo’s sample piston to add the ability to reset the HEM on specific days of the month when my billing cycle ends and the new one starts. I’m also adding the ability to differentiate cost based on summer usage or not
So far, I have got the cost per kWh but it is not totally accurate as I would like it to start at the beginning of the summer month’s billing cycle not on the 1st day of the month Also would like to reset the physical device in ST when the cycle resets

2) What is the expected behaviour?

Calculate energy usage and reset at the start of the billing cycle
Reset physical devices in SmartThings
Adjust costPerkWH based on time of year
Upcoming billing cycle end dates are 5/19, 6/16, 7/2, 8/18, 9/15, 10/20, 11/17, 15/15
To the best of my understanding the cycles runs 4 Tuesdays for 2 months then it’s the 5th Tuesday the 3rd month

3) What is happening/not happening?

Trying to add date in the if statement but no variable for date.
**4) Post a Green Snapshot of the piston![image|45x37]


5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)


#2

I do some similar stuff but I use separate pistons to write the data to a thingspeak account. I have pistons that write data to graph hourly, daily, monthly and a daily total. In our area power cost is fixed and does not vary so that makes calculating cost easy. I also have a piston that resets the HEM on midnight of the 29th as that is when my power company reads my meter. This is my reset piston, it also writes my monthly total to my graph, not sure it helps you or not.


#3

Tagging @Nezmo


#4

I use a separate piston to reset my energy devices each month. It does require I update the reset date each month but it certainly could be enhanced to be smarter.


#5

Thanks @Nezmo.
I was able to use your piston as the basis for me to create a piston that will reset on the days my billing cycle changes. I’m learning quickly as the concepts are similar to my Java programming classes I did years ago.
I suppose this is not the cleanest way I could do it as I could probably create an arraylist with the cycle end dates each month and use a for loop to iterate through the list instead of using switch cases. The concept is there in my head but I don’t know how to implement it.

Now however I’m thinking of taking this one step further and try to figure out how to have the variable changes here also change the reset date on my piston with the gauges so those reset as well.


#6

@Terminal
I like your implementation on messages with total kWh usage. I’m going to add that to my piston as well.


#7

@Nezmo or anyone else for that matter.
Have you seen this happen?
I used your gauges/ tiles piston to create gauges for my home energy usage . I added a 6th gauge (Billed) with billed costs which include a flat rate my electricity provider adds to the monthly bill.

I then created 2 duplicate pistons but deleted the variable representing the flat fee as well as the 6th gauge however even though my duplicate pistons have no reference to the 6th gauge ( Billed ), the gauge is still showing up.


HEM piston showing 6th tile/gauge details in the piston.


Duplicate piston created for chest freezer but with all reference to billed Costs removed.

Thoughts


#8

You can send a one time command to Clear piston tile #6.

pic


Note: After running that line, the dashboard tile may take about 10 seconds to update.


#9

@WCmore Sadly that didn’t work. Did I put my command in the wrong place in the piston?


#10

I did not look at your code, but that line just has to execute once.

I usually drop it in a new location block, (outside of any IFs)… Then Save and Test… After it succeeds, I’ll go back and delete the block.


#11

@Wcmore Thanks It worked the first time. It just didn’t clear the tile immediately in the dashboard. Checked later and it had moved. Thanks again


#12

Sweet! I will edit my previous post to mention that.


#13

Nice! If it works then awesome. Yes, I look for the most efficient solution when I can but sometimes it’s just good to get your results no matter how.

I chose to put my resets in a separate piston as it resets more than just the HEM.

You can also look at using global variables for things like your price per kWh if you use it in more than one piston. Then you only have a single point of maintenance when that external factor changes.


#14

Yes I’m going to do just that for the billing cycle dates especially. It’s easy now because i’m just duplicating pistons but I imagine come 2021 when i have to update the 12 variables per piston that uses it, it’ll quickly multiply.


#15

Was looking at your piston I realized they are doing 28 and 35 day billing cycles. It runs 28 days twice and then a 35. So you could try and use that and just count days and reset. You might could make it so you don’t have to manually update the billing cycle dates. This being the leap year they had to change something, so you would have to figure out how they handle that as well. Maybe they always have the first billing day of the year at the same time and so that one billing cycle will change every 4 years. If so that would make it easy to track. Just reset every year on that day and then start counting.