Page 1 of 1

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

PostPosted: Thu Mar 09, 2017 1:12 pm
by Will
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.

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

PostPosted: Fri Mar 10, 2017 9:54 am
by jay (support)
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?

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

PostPosted: Fri Mar 10, 2017 12:42 pm
by Will
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.

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

PostPosted: Fri Mar 10, 2017 5:44 pm
by jay (support)
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.

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

PostPosted: Sun Mar 12, 2017 2:17 am
by Will
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.

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

PostPosted: Sun Nov 03, 2019 1:33 pm
by Will
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.

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

PostPosted: Sun Nov 03, 2019 1:46 pm
by matt (support)
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.

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

PostPosted: Sun Nov 03, 2019 5:13 pm
by FlyingDiver
global is a Python keyword. Pick a different name for that variable.