Compare value of temperature sensor to a variable

Posted on
Sun Mar 07, 2021 6:09 pm
tricksel offline
Posts: 13
Joined: Jul 28, 2008
Location: Delft, The Netherlands

Compare value of temperature sensor to a variable

Hi guys,

Yet another question...

I have an Aeotec Multisensor which, among others, has a temperature sensor. I have a trigger action which sends out a notification when temperature drops below a value and another when temperature rises above another value. However, these values are set "hard" in the trigger action. Would it be possible to have these values in a variable? This way, my girlfriend would be able to change these thresholds from Indigo Touch, and doesn't have to ask me to change them through the Indigo Client.

Thanks in advance,

Patrick

Love doesn't hurt. Chuck Norris does.

Posted on
Wed Mar 10, 2021 10:28 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Compare value of temperature sensor to a variable

You can do this by creating a trigger (in addition to the notification trigger you already have):

Type: Variable Changed
Variable: [SELECT THE VARIABLE THAT IS THE SOURCE TEMP]
Select the "changes" radio button (so that it fires every time the variable changes)

For the action, use the following script:

Code: Select all
notification_trigger = indigo.triggers[NOTIFICATIONTRIGGERID] # "Your current notification trigger ID here"
temp_source_variable = indigo.variables[VARTEMPSOURCEID] # "The variable ID that is the source temp here"

# Get the target temperature as an integer
target_temp = temp_source_variable.getValue(int)
# Do this test as anything other than a number will result in a value of 0
if target_temp > 0:
    # Set the state value (must be a string so we cast it to a string)
    notification_trigger.stateValue = str(target_temp)
    # Save the change to the trigger
    notification_trigger.replaceOnServer()
else:
    # Write an error to the Event Log to help debug any issues.
    indigo.server.log("Source temp variable doesn't contain a valid number greater than 0", isError=True, type="Temp Notification Sync")


Basically, whenever the variable value changes, the above trigger fires and updates the notification trigger with the value from the variable.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 10, 2021 12:25 pm
tricksel offline
Posts: 13
Joined: Jul 28, 2008
Location: Delft, The Netherlands

Re: Compare value of temperature sensor to a variable

Wow, I really should level up my Python skills, Thanks Jay!

I've made a tiny modification to your script; you've made integers of the values in the variables, I have made float's of them. This way, I don't have to use full degrees, and am able to use e.g. 19.5 degrees Celsius. For future reference of others, this means:

Code: Select all
notification_trigger = indigo.triggers[NOTIFICATIONTRIGGERID] # "Your current notification trigger ID here"
temp_source_variable = indigo.variables[VARTEMPSOURCEID] # "The variable ID that is the source temp here"

# Get the target temperature as an integer
target_temp = temp_source_variable.getValue(float)
# Do this test as anything other than a number will result in a value of 0
if target_temp > 0:
    # Set the state value (must be a string so we cast it to a string)
    notification_trigger.stateValue = str(target_temp)
    # Save the change to the trigger
    notification_trigger.replaceOnServer()
else:
    # Write an error to the Event Log to help debug any issues.
    indigo.server.log("Source temp variable doesn't contain a valid number greater than 0", isError=True, type="Temp Notification Sync")

Love doesn't hurt. Chuck Norris does.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests