[No Longer Maintained] Energy Cost Calculator

You wouldn't happen to be logging to something like influx would you?

I have four instances of this app running across two different hubs with 22 devices and haven't had a single instance like that. I'd need to see trace logging to figure out where it's going awry but digging back through them would be painful without some external logging.

No, I am not. For now I will just see how often it happens.

I am running two instances of the app, this one and another that just has my whole house HEM attached. The other instance with one device did this as well. I didn't take a screenshot of it, should have I guess

The apps just reset yesterday so I have 28Kwh for today and it had a huge cost listed. Like this one I recalculated and it was right again. I turned on logging for the single device app and I will see if it happens again.

1 Like

I appreciate it. The hard part will be narrowing the logs down to when it jumped the abnormal amount.

Welp...I had it happen to me today. Unfortunately, it was an app instance I didn't have logging enabled.

I can see that for some reason, the total cost for "yesterday" is 2869 along with last week being 4784. Bonkers.

Thankfully, since I've optimized the way this thing runs...a one liner will get me a raw dump of everything if this happens again.

After some more testing...the optimization is a pretty solid 66% reduction in CPU time:

2 Likes

Happened again to me this afternoon, but on the instance that has all the individual devices. It was also a different device. So I enabled logging on that one as well.

1 Like

I'm still waiting for a re-occurrence. Hopefully one of us catches it here soon.

INPUT NEEDED:
I'm trying to think of the best way to get the data that's in the app to elsewhere within the system. Right now, variable links are the only way to do so.

The problems:

  • Hub variables don't scale very well, in part because they can't automatically be created so the user must make each one and then link them.
  • I thought about dumping the table data into a variable to display the table in a dashboard tile. Hub variables are limited to <256 characters and the table it definitely bigger than that.
  • I thought about creating a child device with an attribute for the table (like @thebearmay has done with the Hub info driver) but, again, the table is too large and parts of the HTML are blocked by the Dashboards app itself.
  • I could create a child virtual device that correlates to each "row" in the table, but, again, this doesn't scale very well.
  • I could create a child virtual device that houses an attribute for each table entry. I think this would be the most cumbersome to code (if it's even possible) and would likely result in a disaster of a device page.

So, I'm looking to see if anyone has any other ideas. No matter how far fetched, I'm open to ideas. Never know what might trigger the "ah-ha" moment.

1 Like

The other method I've used is to write the data out to the local file system, and use a link to it for the display. The other advantage this gives you is the ability to open it in its own window/tab.

2 Likes

Could you point me to one of your apps/drivers that employs that?

hubitat/webScraper.groovy at main · thebearmay/hubitat · GitHub uses the old Local File Methods code to write to the file system (about line 105), but it wouldn't take much to convert it to use the new built-in methods.

2 Likes

I have 0.4.8 and am getting this error when I open the app:

If I comment out line 486, the app opens.
image

1 Like

Somebody doing major programming and the Treadmill is being neglected.Can you fix the program so it looks like I'm actually using my treadmill...even if I'm not :laughing:

1 Like

Replace 481-486 with this:

		//Get energy values for each device.
		todayEnergy = device.todayEnergy.toDouble().round(3)
		thisWeekEnergy = device.thisWeekEnergy.toDouble().round(3)
		thisMonthEnergy = device.thisMonthEnergy.toDouble().round(3)
		lastWeekEnergy = device.lastWeekEnery ?: 0
		lastWeekEnergy = lastWeekEnergy.toDouble().round(3)
		lastMonthEnergy = device.lastMonthEnergy ?: 0
		lastMonthEnergy = lastMonthEnergy.toDouble().round(3)

Pretty sure I fixed that in the upcoming update.

1 Like

I finally caught it. It shows the Crawlspace exhaust fan at a cost of $13.13, but only .241KWH which should be $0.03. The last screenshot shows where it went wrong. Not sure why. The log is filtering all lines containing Crawlspace exhaust fan. It shows the energy going to 125kWH, not sure where it is getting that from. I checked the device logs and it is not reading a value that high.

1 Like

So that is super weird since the log entry saying "current energy is 125" is showing what Hubitat thinks the current value is directly off the device. Meaning I'm not applying any logic there that could be going wrong.

So, now my question is, do you have any devices with an energy reading of that value? Can you also check the events list from the device page (unless you also checked there when you looked at it's logs)?

Only thing close is my whole home energy reading which is currently at 116.97kWh.
That is close to the voltage level the exhaust fan is reading. The levels shown in the screenshot of the chart, 1.143 was the correct energy reading for the device at that time. It is currently 1.169 as shown below.

1 Like

Just found another issue. For some reason the total energy for the month and week for my whole house is wrong. I reset the devices on the 28th, the current total energy on my whole house HEM at the time I took the screenshot below was 182.933 kWh. It shows 302.863kWh, even the weekly shows a total greater than the current reading on the device, 274.163kWh. It was correct initially, but somewhere it went wrong. I just went through and checked the total energy on all my individual devices and the monthly total energy matches the total energy level shown on the device.

[edit]Also just realized, that this week and this month should be equal. I reset on the 28th, which was Tuesday, so there has been no new week started yet. I see the same on the other instance I am running. Some of the weekly amounts match the monthly, but most do not. At this point they all should. I will post the screenshot of the individual below as well

Could there be an option added to reset the monthly total to match the device total?

Below is a snippet of the log from the earliest I currently have. It already shows this week energy at 268.027 and the energy meter total is currently at 176.753

1 Like

I think we're operating under different definitions for a week.

From the app's perspective, a week is Sunday-Saturday. This is regardless of the date. I don't think there's much value to only looking at a week within the context of a given month. I could be wrong and there's some use-case I'm not thinking of though. My initial thoughts is that I would want to see day over day, week over week, and month over month.

With the above in mind, the anomaly I see is the monthly value. In this case, I would expect it to be less than the weekly value. Also the fact that you don't have a value for previous month.

For the HEM instance, can you PM me a screenshot of the status page (gear icon in the upper right-hand corner of the app) along with a copy/pasta of the "Application State" table?

Sorry I was looking at the current months calendar. The 28th was Friday, so I was just wrong on that one.

Had not really noticed that, since I knew that value was not valid I hadn't really paid attention. I reset everything in that table just before the month reset but there should have been a small amount I think.

1 Like

It looks like this app instance (and probably both) missed the monthly reset job. Did you happen to change the monthly reset day to 28 after the 28th for these two apps? The other option I can think of was that the hub was powered off at monthly reset time. From there...we get into the realm of bugs.

The reset occurs after your reset. I reset at 12:05AM. The hub was not powered off.

I wondered if that might be an issue. My groovy coding abilit y is limited but from looking through your code, and I believe you mentioned, that if the current energy was less than last reading it would assume a reset and start over.

I made a slight change in your code. I set the months totals to the device value. In my case that is what I always want. It seems to be working. All my months totals are currently correct. How it is going to effect the daily and weekly amounts is yet to be seen. From what I can gather from the code once the next weekly and daily reset occurs these changes should not effect them.

I changed two lines in the updateDeviceEnergy() sub.

From
device.thisMonthEnergy = thisMonth
To
device.thisMonthEnergy = currentEnergy

and

From
state.thisMonthTotal = thisMonthTotal
To
state.thisMonthTotal = currentEnergy

Just as I typed the above and was about to post, I remembered that I had to do a hub restore. I am trying to remember exactly when I did it. It might have been since the monthly reset, I thought it was before, but maybe not. That could explain what happened.

For now I will use my update and see how it goes.

1 Like