I still need a way to filter the relays down to lights and fans. My list is pulling back virtual devices, TVs, even disabled plugins like Bond Home
Here's what I'm using currently
- Code: Select all
##########################################################################
# Take the snapshot
import json
relList = []
dimList = []
# cycle through deveices and save the state values of relays and dimmers
for device in indigo.devices.iter("indigo.relay, indigo.dimmer"):
if device.pluginId != "com.perceptiveautomation.indigoplugin.devicecollection" and device.pluginId != "com.ryanbuckner.indigoplugin.samsungtv" and device.pluginId != "com.flyingdiver.indigoplugin.bondhome" and device.enabled:
if (isinstance(device, indigo.DimmerDevice)):
dimList.append({'id': device.id, 'name': device.name, 'brightness': device.brightness })
else:
relList.append({'id': device.id, 'name': device.name, 'state': device.onState })
# save the dimmer list to a variable
indigo.variable.updateValue(1322749870, value=json.dumps(dimList))
# save the relay list to a variable
indigo.variable.updateValue(581444171, value=json.dumps(relList))
############################################################################
# Restore from snapshot
# retrieve dimList
dimRestore = json.loads(indigo.variables[1322749870].value)
# retrieve relList
relRestore = json.loads(indigo.variables[581444171].value)
# restore the state of relays
for relay in relRestore:
if relay['state']:
indigo.device.turnOn(relay['id'])
else:
indigo.device.turnOff(relay['id'])
# restore state of dimmers
for dimmer in dimRestore:
indigo.dimmer.setBrightness(dimmer['id'], value=dimmer['brightness'])
############################################################################