[ANSWERED]How to set a variable with the result of an operat

Posted on
Thu Mar 09, 2017 1:12 pm
Will offline
Posts: 7
Joined: Jul 19, 2015
Location: Madrid, Sapin

[ANSWERED]How to set a variable with the result of an operat

Hello,
I'm trying to create a variable that contains the difference between the outdoors temperature and the in house temperature in order to decide whether I switch on the heating system:

delta_temp = inhouse_temp - outdoors_temp

I will create this as a trigger when either the outdoors ot the indoors temperature changes and then I will execute an script in Python to set the delta_temp value.

The problem is that I know nothing about Python...... :-(

Could you help me with this simple question?

Many thanks.

Guillermo.

Posted on
Fri Mar 10, 2017 9:54 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to set a variable with the result of an operation

There's not enough information to fully answer your question since we don't know where you're getting inhouse_temp and outdoors_temp. Are they device states? Variables?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Mar 10, 2017 12:42 pm
Will offline
Posts: 7
Joined: Jul 19, 2015
Location: Madrid, Sapin

Re: How to set a variable with the result of an operation

Hello Jay, thanks for your response.
"inhouse_temp" and "outdoors_temp" are both variables that store the value of temperature sensors placed inside and outside home respectively. This variables are updated via a "Trigger", as well as the difference between them (delta_temp) should be, each time either sensor value change. Then another trigger based on the change of this "delta_temp" will decide whether to switch on or off the heater depending on certain conditions.

Guillermo.

Posted on
Fri Mar 10, 2017 5:44 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to set a variable with the result of an operation

Ok, so something like this should work:

Code: Select all
inhouse_temp = float(indigo.variables[12345].value) # insert ID of inhouse_temp variable
outdoors_temp = float(indigo.variables[54321].value) # insert ID of outdoors_temp variable
temp_difference = inhouse_temp - outdoors_temp
indigo.variable.updateValue(98765, value=temp_difference)  #insert ID of your delta_temp variable


Right-click on the variable in the Variables Window to copy the ID of the variable.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Mar 12, 2017 2:17 am
Will offline
Posts: 7
Joined: Jul 19, 2015
Location: Madrid, Sapin

Re: How to set a variable with the result of an operation

Hello Jay,
many thanks for the response.
this code worked but I had to change it slightly in the fourth line due to an error received while trying to run it.

inhouse = float(indigo.variables[388313023].value) # insert ID of inhouse_temp variable
outdoor = float(indigo.variables[1288399788].value) # insert ID of outdoor_temp variable
delta = inhouse - outdoor
indigo.variable.updateValue(932135071, str(delta)) #insert ID of delta_temp variable

Thanks again.

Guillermo.

Posted on
Sun Nov 03, 2019 1:33 pm
Will offline
Posts: 7
Joined: Jul 19, 2015
Location: Madrid, Sapin

Re: [ANSWERED]How to set a variable with the result of an op

Hello Jay,
Could you please give me a hand with a Python code? Just give a syntactically correct version of the following snippet:

Code: Select all
salon = bool(indigo.variables[1557076559].value) # insert ID of Termost_salon_CFH variable
guille = bool(indigo.variables[1471718955].value) # insert ID of Termost_Guille_CFH variable
libre = bool(indigo.variables[91898717].value) # insert ID of Termost_libre_CFH variable
global = (salon OR guille OR libre)
indigo.variable.updateValue(1505457529, str(global))  #insert ID of CFH_global variable

It is a simple operation: I want to calculate the logical value of a variable as the result of the OR of three variables (a virtual Boiler actuator)
Kind regards,

Guillermo.

Guillermo.

Posted on
Sun Nov 03, 2019 1:46 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: [ANSWERED]How to set a variable with the result of an op

Hi Guillermo,

Glancing over your snippet it looks very close. You need to use lowercase 'or' and not 'OR' though:

Code: Select all
global = (salon or guille or libre)

If that doesn't work then describe what error you are seeing.

Image

Posted on
Sun Nov 03, 2019 5:13 pm
FlyingDiver online
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: [ANSWERED]How to set a variable with the result of an op

global is a Python keyword. Pick a different name for that variable.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests