Python - Turning on device when only device code is known

Posted on
Wed Oct 30, 2013 7:52 pm
Trovan offline
Posts: 18
Joined: May 26, 2008

Python - Turning on device when only device code is known

How do I turn on a device when I only know the device code?

I'm trying to use this code as a template, but I don't think I'm on the right track with updatestateonserver. Any help?


Code: Select all
def setDeviceLight(zone, lightmsg):
   for device in indigo.devices:
      if device.address == zone:
         device.updateStateOnServer("mode", mode)

Posted on
Wed Oct 30, 2013 8:03 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Python - Turning on device when only device code is know

updateStateOnServer() is a semi-private method that plugins are only allowed to call on device types they own/define. Instead, I think you want this:

Code: Select all
indigo.device.turnOn(device)

where device can be a device instance (like you have in your loop), a device ID, or a device name.

Image

Posted on
Thu Oct 31, 2013 4:31 am
Trovan offline
Posts: 18
Joined: May 26, 2008

Re: Python - Turning on device when only device code is know

This is the error I get when it tries to set the device...

File "plugin.py", line 50, in runConcurrentThread
File "plugin.py", line 143, in dispatchMsg
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Elk Plugin.indigoPlugin/Contents/Server Plugin/elkextra.py", line 56, in setDeviceLight
<type 'exceptions.ValueError'>: ElementNotFoundError -- could not find device "C12"

Line 56 is the turnOn(zone)...

With the following code
Code: Select all
def setDeviceLight(zone, lightmsg):
   for device in indigo.devices:

      if device.address == zone:
         indigo.device.turnOn(zone)
         indigo.server.log("Turned on")

Posted on
Thu Oct 31, 2013 6:58 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Python - Turning on device when only device code is know

It looks like "zone" is the X10 address of your device, not its ID (ID is a unique internal integer assigned to every Indigo device). Instead use:

indigo.device.turnOn(device)

Or if you wanted to pass the ID (same result) it would be:

indigo.device.turnOn(device.id)

Image

Posted on
Thu Oct 31, 2013 4:08 pm
Trovan offline
Posts: 18
Joined: May 26, 2008

Re: Python - Turning on device when only device code is know

Ok. This is fixed. I'm now able to update a device based on a command sent from the Elk-M1.

I have another question....Is there a way to have a callback or something in a plugin that will alert me when a device is changed?

I want to be able to change the device status in Indigo, and have the plugin send a command out to the Elk-M1.

Thanks,

Mark

Posted on
Thu Oct 31, 2013 8:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python - Turning on device when only device code is know

If you build a plugin then you can subscribeToChanges which will call a method in the plugin each time any device changes.

If you don't want to build a full plugin you can just trigger off of any change just to the devices you care about and in the action run a script that talks to the elk.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Nov 01, 2013 6:55 pm
Trovan offline
Posts: 18
Joined: May 26, 2008

Re: Python - Turning on device when only device code is know

I setup subscribetochanges and I get zone changes in the log file, but not when I manually change an X10 zone.

What command do I use in a trigger script if I want to communicate with a plugin?

Posted on
Sat Nov 02, 2013 5:26 am
Trovan offline
Posts: 18
Joined: May 26, 2008

Re: Python - Turning on device when only device code is know

Nevermind. I found the issue.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests