First, notice that your two IF blocks are identical (both are looking to see if the calculation is > 0, so both will fire):
- Code: Select all
if (RoomTemp - RoomHighSetpoint) > 0: # Difference is greater than 0, so turn on the device
indigo.speedcontrol.setSpeedIndex(731663956, value=3) # turns fan to High
if (RoomTemp - RoomHighSetpoint) > 0: # Difference is greater than 0, so turn on the device
indigo.speedcontrol.setSpeedIndex(731663956, value=2) # turns fan to Med
So it will only set to Medium if the difference is > 0 (because the first IF sets it to High, but then the second identical test sets it to Medium). I think that's likely just a copy/paste error - you forgot to change it to less than.
Here's a tweaked script that will log the results of your calculations to the Event Log window and will avoid the double IF problem which was somewhat obscuring what the problem was:
- Code: Select all
# Get the temperature value from the sensor and get the setpoint value from the setpoint device.
RoomTemp = indigo.devices[1770450782].sensorValue # ID of the Temperature device
RoomHighSetpoint = indigo.devices[1254352989].brightness # ID of the variable setpoint
# Log the values and the calculation results:
calculation_result = RoomTemp - RoomHighSetpoint
indigo.server.log("{} - {} = {}".format(RoomTemp, RoomHighSetpoint, calculation_result))
#calculate the difference and check to see if it is greater or equal to 0
if (calculation_result) > 0: # Difference is greater than 0, so turn on the device
indigo.speedcontrol.setSpeedIndex(731663956, value=3) # turns fan to High
elif (calculation_result) < 0: # Difference is LESS than 0, so turn on the device
indigo.speedcontrol.setSpeedIndex(731663956, value=2) # turns fan to Med
Not tested, but it should be close. There is a bit of a hole in your logic though - if the value is exactly 0 nothing happens (maybe that's where you turn the fan off in another elif block).