Updating existing devices with a new custom state

Posted on
Fri Jan 03, 2020 1:35 pm
ZachBenz offline
Posts: 163
Joined: Feb 08, 2014

Updating existing devices with a new custom state

In my plugin, I would like to modify a device in Devices.xml to add a new custom state. When I do this, existing instances of the device already defined in Indigo don't have this custom state, causing errors when I try to update the new state.

I've tried to overcome this by updating the device in deviceStartComm, only to discover that the "states" attribute for a device is read-only - e.g. if I try something like:

Code: Select all
      if ("lastMotionEventId" not in indigoDevice.states):
         replacementStates = indigo.Dict()
         replacementStates = indigoDevice.states   # Make a copy to edit
         replacementStates["lastMotionEventId"] = "FOOBAR"
         indigoDevice.states = replacementStates
         indigoDevice.replaceOnServer()
         self.debugLog("Added new custom state lastMotionEventId to existing device %s" % indigoDevice.name)


The following error is produced:

Code: Select all
   Ring Error                      exception in deviceStartComm(Front Door): the attribute "states" is read-only on this instance


What is the correct way to migrate existing devices to support the newly added state? Do I need to programmatically create a whole new device object to replace the existing one?

ZachBenz's Plugins: RingForIndigo

Posted on
Fri Jan 03, 2020 1:44 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Updating existing devices with a new custom state

https://wiki.indigodomo.com/doku.php?id ... vice_class

replaceOnServer()
stateListOrDisplayStateChanged()


Sent from my iPhone using Tapatalk Pro

Posted on
Fri Jan 03, 2020 1:54 pm
ZachBenz offline
Posts: 163
Joined: Feb 08, 2014

Re: Updating existing devices with a new custom state

Got it, thanks for the pointer!

ZachBenz's Plugins: RingForIndigo

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests