I'm sorry to ask such a basic question, but I'm struggling writing a basic phython script that will set the brightness of a Dimmer device to the value of a variable. Can someone show me some example code?
Thank you!
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
# Define the IDs for the variable and device
variableId = VARIDHERE
deviceId = DEVICEIDHERE
# Get the variable object
try:
myVar = indigo.variables[variableId]
except:
indigo.server.log(u"Variable id %i doesn't exist." % variableId)
# Next, we need to turn it into an integer value and make sure
# it's in the appropriate range (0-99). We'll use a try block
# and log an error if the value can't be turned into an
# integer or if it's out of range
try:
# Convert the value to an int - it will throw if it can't
newBrightness = int(myVar.value)
# Throw if it's not in range
if newBrightness not in range(101):
raise Exception
except:
indigo.server.log(u"Variable value is either not an integer or not from 0-100.")
return
# We now know newBrightness is an integer from 0-100. Set the value and
# catch any exceptions which most likely means the device isn't a dimmer.
try:
indigo.dimmer.setBrightness(deviceId, value=newBrightness)
except:
indigo.server.log(u"Device id %i is not a dimmer." % deviceId)
Users browsing this forum: No registered users and 2 guests