manipulating and assigning values to indigo variables

Posted on
Thu Mar 05, 2020 5:35 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

manipulating and assigning values to indigo variables

I'm using Phidget temperature sensors and a single board computer to monitor frost conditions in a remote house. From time to time, the phidgets webservice fails and the temperatures cease to be monitored. I would like to send myself an email to notify myself of this condition so that I can restart the webservice. To catch this condition, schedule a script to run every hour, and test for changes in the outside temperature:
- if there is no change in the outside temp, increment a counter by '1';
- else, change the value of variable temp-previous to equal temp-current.
In Indigo, if the counter variable reaches, say 5, trigger an email to check the webservice.

The script below fails at line 6 because I am unable to modify the indigo variable. I'm guessing the other 3 lines which modify variables would also fail.


Code: Select all
counter = indigo.variables[900799422].getValue(int) #web service test = number hours temp has not changed
dev = indigo.devices[1969337208] #outside temp device value
outTemp_crnt = int(dev.states["temperature"]) #current outside temp variable value
outTemp_prev = indigo.variables[1778324840].getValue(float) #previous outside temp variable value

if outTemp_crnt != outTemp_prev:
   indigo.variable.updateValue(900799422, value = 0) #reset webservice test counter to 0
   indigo.variable.updateValue(1778324840, value = outTemp_crnt) #assign current temp to previous temp
   
else:
   counter = counter + 1
   indigo.variable.updateValue(900799422, value = outTemp_crnt) #increment counter value by 1


Posted on
Thu Mar 05, 2020 5:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: manipulating and assigning values to indigo variables

Indigo variables only accept strings - so just cast the values to strings:

Code: Select all
counter = indigo.variables[900799422].getValue(int) #web service test = number hours temp has not changed
dev = indigo.devices[1969337208] #outside temp device value
outTemp_crnt = int(dev.states["temperature"]) #current outside temp variable value
outTemp_prev = indigo.variables[1778324840].getValue(float) #previous outside temp variable value

if outTemp_crnt != outTemp_prev:
   indigo.variable.updateValue(900799422, value="0") #reset webservice test counter to 0
   indigo.variable.updateValue(1778324840, value=str(outTemp_crnt)) #assign current temp to previous temp
   
else:
   counter = counter + 1
   indigo.variable.updateValue(900799422, value=str(outTemp_crnt)) #increment counter value by 1

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Mar 05, 2020 6:41 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: manipulating and assigning values to indigo variables

Thanks.

Posted on
Thu Mar 05, 2020 6:56 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: manipulating and assigning values to indigo variables

New issue: stings/integers/floating point.
The temp sensor precision is a tenth of a degree. If the script always rounds down when converting the floating point value to an 'integer' string, the logic will sense a change in temp when it might not have occurred.
I don't think my modification in the 'if' line solve this issue.
Thoughts or suggestions?

Code: Select all
counter = indigo.variables[900799422].getValue(int) #web service test = number hours temp has not changed
dev = indigo.devices[1969337208] #outside temp device value
outTemp_crnt = int(dev.states["temperature"]) #current outside temp variable value
outTemp_prev = indigo.variables[1778324840].getValue(float) #previous outside temp variable value

if outTemp_crnt * 10 != outTemp_prev * 10: #if current temp has changed,
   indigo.variable.updateValue(900799422, value = "0") #reset webservice test counter to 0
   indigo.variable.updateValue(1778324840, value = str(outTemp_crnt)) #assign current temp to previous temp
   
else: #current tempt has not changed - increment counter value by 1
   counter = counter + 1
   indigo.variable.updateValue(900799422, value = str(counter))

if counter > 8:
   counter = 0
   indigo.variable.updateValue(900799422, value = "0") #reset webservice test counter to 0
   

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests