Page 1 of 1

Get Plugin to Response to change in Variable?

PostPosted: Mon Feb 12, 2018 7:14 pm
by GlennNZ
Hi all,

Thanks for helping as I am struggling with triggering a plugin with a (external) variable change. What is the best way to achieve this?
eg. motion sensed by external camera - RestfulAPI post to Indigo - to change indigo variable. But need running Plugin to see this change and respond.

Options:
- subscribetoChanges() ?is there a specific variable subscribetoIncoming() or does the devices one cover both or just devices.
Would seem quite process heavy for the simple task that is needed.

- Check variable for change within Plugin every second and then trigger if changed?
Probably fairly low-level impact ?

Or is there another way of achieving this which is essentially a external event (via RestfulAPI) triggering a Plugin.

Thanks - I'll have a look at some plugins that probably face the same issue to get some ideas...

Glenn

Re: Get Plugin to Response to change in Variable?

PostPosted: Mon Feb 12, 2018 7:26 pm
by Colorado4Wheeler
Try

Code: Select all
indigo.variables.subscribeToChanges()


Each group has its own. I’ve not tried it with variables but I think that will work.

Re: Get Plugin to Response to change in Variable?

PostPosted: Mon Feb 12, 2018 7:42 pm
by GlennNZ
Colorado4Wheeler wrote:
Try

Code: Select all
indigo.variables.subscribeToChanges()


Each group has its own. I’ve not tried it with variables but I think that will work.


Wow - thanks for the tip - that be great if works.

The other option I was thinking (before your better solution) was whether we can change a Plugin devices custom state via RestfulURL (presume we can - but haven't tested)
& if we can, and then do so - is the device Plugin notified at all (I presume not - unless checking dev.states regularly?)

Glenn

Re: Get Plugin to Response to change in Variable?

PostPosted: Mon Feb 12, 2018 7:47 pm
by Colorado4Wheeler
I know a total API rewrite is underway, so maybe soon. It’s not too hard to write an http server and just roll your own API for your needs.

Re: Get Plugin to Response to change in Variable?

PostPosted: Wed Feb 14, 2018 10:53 am
by jay (support)
The current REST API doesn't know about custom states. We are working on a REST overhaul for sometime this year.

And, in the interests of security, I'm not sure that a random API call should be able to change a state directly. We don't provide UI to do that either. Rather, we recommend that the developer expose actions to perform actions that typically result in state changes. The user could then create an action group to do perform the action and execute that through the API.