Snapshot and Restore

Posted on
Sat Dec 30, 2023 10:28 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Snapshot and Restore

I used to use the Scene Toggle plugin to take a snapshot of device states and restore them but sadly that is no longer an option.

Is there a more Indigomatic snapshot and restore capability?

Here's what I'm looking to do:

1 - User or schedule sets house_mode to indicate the cleaners are here to clean the house (variable change) and triggers the action
2 - Indigo takes a snapshot of all the current device states (mostly lights and fans)
3 - Indigo turns on all the lights in the house
4 - Trigger sees that the cleaners have left (variable change) and restores the state using the snapshot in #2

Posted on
Mon Jan 01, 2024 5:36 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Snapshot and Restore

I'm going to try to roll my own. Is this the best way to get this information? I know there are filters in the documentation when using len() but they failed for me without len()

I'm going to start with just switches and dimmers:

Code: Select all
>>> for dev in indigo.devices:
...   if (dev.subType == "Switch" or  dev.subType == "Dimmer"):
...     if (dev.subType == "Switch"):
...       print(f"{dev.name} : {dev.subType} : {dev.onState} : {dev.id} ")
...     else:
...       print(f"{dev.name} : {dev.subType} : {dev.brightness} : {dev.id} ")

Posted on
Wed Jan 03, 2024 10:43 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Snapshot and Restore

Slightly more efficient since the filtering would take place on the server:

Code: Select all
for device in indigo.devices.iter("indigo.relay, indigo.dimmer"):
    if (isinstance(dev, indigo.DimmerDevice)):
        # do dimmer stuff here
    else:
        # do relay stuff here


Also, you want to test the class instance of the device rather than subType (which may not be exactly accurate).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jan 03, 2024 12:31 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Snapshot and Restore

strangely this only retuned Timer devices

Posted on
Wed Jan 03, 2024 3:18 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Snapshot and Restore

That's really odd since timer devices aren't either.

When I run this in an interactive shell:

Code: Select all
>>> for device in indigo.devices.iter("indigo.relay, indigo.dimmer"):
...     if (isinstance(device, indigo.DimmerDevice)):
...         print(f"{device.name} is a dimmer")
...     else:
...         print(f"{device.name} is a relay")
...


I get this:

Code: Select all
000 KeypadLinc is a dimmer
009 - Plug-In Appliance Module's name is a relay
010 - Smart Fan was here is a dimmer
038 - Lamp Module (AD130) is a dimmer
automatic door is a relay
bestätigt für explicaría por qué está léger problème sûr  c'è is a relay
Device Group Brightness >= 50% All On is a relay
Device Group Brightness On Relay On All On is a relay
Device Group Brightness On Relay On Any On is a relay
FanLinc - Light is a dimmer
Fortrezz Siren is a relay
Fortrezz Strobe is a relay
Generic X10 Appliance Module is a relay
HS-WD200+ is a dimmer
Hue Bulb is a dimmer
Hue Testing Bulb is a dimmer
Insteon Dimmer is a dimmer
Insteon On/Off (back door in alexa) is a relay
Kasa Dual #1 is a relay
Kasa Dual #2 is a relay
Kasa Plug is a relay
LZW36-SN Dimmer is a dimmer
LZW36-SN Fan is a dimmer
office outlet is a relay
Office Siren is a relay
outdoor-module is a relay
Simple Virtual On/Off is a relay
SwitchLinc Dimmer is a dimmer
Virtual On/Off Device w/ Manual State is a relay
Virtual On/Off Device w/ Var Status is a relay
ZEN30 Dimmer is a dimmer
ZEN30 Relay is a relay
ZEN32 is a relay
ZEN77 Dimmer is a dimmer


I have several timers and they aren't in the list.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jan 03, 2024 8:23 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Snapshot and Restore

My fault. I think you had a typo in your first script that I should have caught.

How can I filter out virtual devices?

Posted on
Fri Jan 05, 2024 2:05 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Snapshot and Restore

Which virtual devices? If you want to skip all devices from the Virtual Devices interface you can just check the pluginId:

Code: Select all
for device in indigo.devices.iter("indigo.relay, indigo.dimmer"):
    if device.pluginId != "com.perceptiveautomation.indigoplugin.devicecollection":
        if (isinstance(device, indigo.DimmerDevice)):
            print(f"{device.name} is a dimmer")
        else:
            print(f"{device.name} is a relay")

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 05, 2024 5:22 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Snapshot and Restore

Excellent. The last step is to filter out disabled devices. device.enabled == False but this disabled device is coming back

Code: Select all
batteryLevel : None
blueLevel : None
brightness : 0
buttonConfiguredCount : 0
buttonGroupCount : 0
configured : True
defaultBrightness : 100
description :
deviceTypeId : bondBridge
displayStateId : brightnessLevel
displayStateImageSel : DimmerOff
displayStateValRaw : 0
displayStateValUi : 0
[color=#FF0040]enabled : True[/color]
energyAccumBaseTime : None
energyAccumTimeDelta : None
energyAccumTotal : None
energyCurLevel : None
errorState :
folderId : 248442714
globalProps : MetaProps : (dict)
     com.flyingdiver.indigoplugin.bondhome : (dict)
          address : 192.168.1.206 (string)
          token : fd5b9d4919622779 (string)
greenLevel : None
id : 359596630
lastChanged : 2022-11-10 11:12:20
lastSuccessfulComm : 2022-11-10 11:12:20
ledStates : []
model : Bond Home Bridge
name : Bond Home
onBrightensToDefaultToggle : False
onBrightensToLast : False
onState : False
ownerProps : com.flyingdiver.indigoplugin.bondhome : (dict)
     address : 192.168.1.206 (string)
     token : fd5b9d4919622779 (string)
pluginId : com.flyingdiver.indigoplugin.bondhome
pluginProps : emptyDict : (dict)
protocol : Plugin
redLevel : None
remoteDisplay : True
sharedProps : com.indigodomo.indigoserver : (dict)
states : States : (dict)
     bondid : ZZCJ10166 (string)
     brightnessLevel : 0 (integer)
     devcount :  (string)
     fw_date : Wed Aug 11 21:00:02 UTC 2021 (string)
     fw_ver : v2.21.4 (string)
     location : Guest Bedroom (string)
     make : Olibra (string)
     model : BD-1000 (string)
     name : Ryan’s Bond Bridge (string)
     onOffState : off (on/off bool)
     uptime_s : 4792452 (integer)
subModel :
subType :
supportsAllLightsOnOff : False
supportsAllOff : False
supportsColor : False
supportsOnState : True
supportsRGB : False
supportsRGBandWhiteSimultaneously : False
supportsStatusRequest : True
supportsTwoWhiteLevels : False
supportsTwoWhiteLevelsSimultaneously : False
supportsWhite : False
supportsWhiteTemperature : False
version : None
whiteLevel : None
whiteLevel2 : None
whiteTemperature : None

Posted on
Sun Jan 07, 2024 2:20 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Snapshot and Restore

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'])


############################################################################


Posted on
Mon Jan 08, 2024 1:26 pm
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Snapshot and Restore

Those devices are all implemented as either a relay or dimmer device. You'll need to filter out whatever you don't want somehow (based on plugin id or device type id or something).

A better solution I think would be to put all the excluded plugin IDs in a list and then just make sure that the device doesn't belong to any of those:

Code: Select all
##########################################################################
# Take the snapshot

import json

EXCLUDED_PLUGIN_IDS = [
    "com.perceptiveautomation.indigoplugin.devicecollection",
    "com.ryanbuckner.indigoplugin.samsungtv",
    "com.flyingdiver.indigoplugin.bondhome",
    # Continue to add plugin ids to exclude here
]

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 not in EXCLUDED_PLUGIN_IDS 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'])


############################################################################

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jan 08, 2024 1:48 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Snapshot and Restore

Thanks Jay. One thing I couldn't figure out was how to exclude ENABLED devices in DISABLED plugins. In the device, enabled = True (because the comm enabled checkbox is checked) ) even though the client shows it as disabled because the plugin is not enabled.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests