Help w Accumulated data from a constantly updated variable

Posted on
Tue May 05, 2020 5:31 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

Help w Accumulated data from a constantly updated variable

I have an TED energy monitor that updates every 2 seconds with usage in kWh, I then write this to a variable. I wanted to use Grafana to display a bar chart showing last 30 days, with a bar for each day of total usage in kWh, which I figured out how to do this way:

Code: Select all
#! /usr/bin/env python

tedMeter = indigo.devices[1097796114]
tedTotalUsed = tedMeter.energyAccumTotal
indigo.variable.updateValue(587587693, value=str(tedTotalUsed))


However, now I also want to display the cost per day, also in Grafana. The problem is I need to read from my cost variable (also updated every 2 seconds), and the energy.AccumTotal only works on devices, not variables. I need to use my Indigo calculated cost variable, because it is derived from the usage * rate (I have several Indigo schedules to manage this), and the rate changes multiple times a day. Unfortunately TED doesn't natively support the complicated TOU plan I have with SDGE.

Hoping someone can point me in the right direction on how to query one variable and write it to another variable, but accumulation style, and then reset it at midnight. I'm guessing this would require a Python script, but not really sure the best way to do this. Or if there is a better way to do this, I am open.

Thanks,

Chris

Posted on
Thu May 07, 2020 4:33 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Help w Accumulated data from a constantly updated variab

Hi Chris,

Indigo variable values are always stored as unicode strings, but when reading them out you can specify if you want them as int or float. Example:

Code: Select all
var1 = indigo.variables[1234]
var2 = indigo.variables[4567]
newValue = var1.getValue(float) + var2.getValue(float)

# You can then stuff the new value back into one of the variables (var2 in this example):
indigo.variable.updateValue(var2, unicode(newValue))

# And if you want to reset the other variable back to 0:
indigo.variable.updateValue(var1, u"0.0")

Image

Posted on
Thu May 07, 2020 6:57 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

Re: Help w Accumulated data from a constantly updated variab

This works great.

Of course the number quickly gets huge, but because it is a cost per hour value that gets sampled every 2 seconds.

So I had to divide by 1800, and the number is perfect now, ready for Grafana.

Thank You Matt!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests