Plugins - can you subscribe to a device?

Posted on
Mon Aug 07, 2017 11:12 am
Rich offline
Posts: 2
Joined: Aug 07, 2017

Plugins - can you subscribe to a device?

Hello, first time posting, so I hope its to the correct area. :)

I've been looking at the plugins documentation, and several examples, both in the SDK and third party developers, however couldn't find an example of what I was looking for.

Can you subscribe to a device?

In the new scripts with Indigo 7.0 SDK it demonstrates new subscriber / broadcaster behaviour, however it seems to depend on a script continuously looping to detect whether or not a change has occurred since it last ran, then broadcasting it to anything that's listening.

In the 'Sensor.indigoPlugin' example it notes:
'If the sensor broadcasts out changes (or is just 1-way), then this runConcurrentThread() method can be deleted.'

The specific context is I'd like a motion sensor (type - FGMS001) to inform me when its triggered. I'd like to minimise the overhead by having a subscriber that gets told when somethings occurred, rather than having to continuously poll for it, I would assume it would also improve response times.

Is this possible? If so how? And is there any documentation that I've missed?

Thanks for looking,
Rich

Posted on
Mon Aug 07, 2017 3:06 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Plugins - can you subscribe to a device?

It's not clear from your post - are you writing a plugin or doing something in "user space"?

If you're writing a plugin, you call "indigo.devices.subscribeToChanges()" to tell Indigo what devices you want change notifications for, then implement the callback for it:

Code: Select all
    def deviceUpdated(self, origDev, newDev):
        indigo.PluginBase.deviceUpdated(self, origDev, newDev)

#  look at devices parameters to see if they match the device you're interested in



No polling required.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Aug 07, 2017 3:09 pm
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Plugins - can you subscribe to a device?

The new publish/subscribe is really just an IPC mechanism between plugins.

What you're looking for is to subscribe to device changes. Then implement the deviceUpdated method (described in the plugin.py section under device specific methods) in your Plugin object, watch for the device(s) you're interested in, and do whatever.

[EDIT] @FlyingDiver beat me to it, but as my post has links to the docs, I'll leave it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Aug 08, 2017 7:16 am
Rich offline
Posts: 2
Joined: Aug 07, 2017

Re: Plugins - can you subscribe to a device?

Much appreciated, thank you for your fast replies!

I'll give it a go and feedback later in the week.

My intention is to use the plugin to track movement in the house, to say turn a light on. My current understanding is that a plugin is the only way to be notified of a event happening (without running a concurrent thread and checking), and then manage the response.

Posted on
Tue Aug 08, 2017 11:26 am
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Plugins - can you subscribe to a device?

If you've got very complex triggering events and actions, then a plugin is definitely an option. Simple interactions like a motion sensor going off and turning on a light is a very simple trigger. Even a group of motion sensors is pretty simple by creating a device group with them in it then using that state as the trigger.

Maybe a more complete description of what you're trying to do would identify solutions that don't require writing a plugin...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests