8 independent scripts + triggers + variable generation shoul

Posted on
Mon Aug 20, 2018 9:25 am
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

8 independent scripts + triggers + variable generation shoul

I wrote a series of scripts to make a Switchboard for dynamically choosing which camera feed refreshing images are rotated in which control page (as I use separate pages for each room), and I am trying to figure out where to start making it a plugin.

Use case:
Jane is in kitchen, and wants to select the front door and back yard to rotate every 10 seconds.
Jack is in the office, monitoring two sleeping children, but he wants to see the backyard too.

It works, but it’s pretty Rube Goldberg.

-I use Indigo Variables for user-entered parameters for clients (e.g. the respective Control Pages for different rooms, “Clients”) and “Sources” (cameras). The Indigo Variables are of the schema addClient, addSource, addSourceToClient, delSourceFromClient

-Whenever a Client or Source is added (via an Action Group that runs a script), an Action Group script generates Indigo Variables for each potential connection (e.g. SOURCE_CLIENT: “backyard_den”, “baby_iphone”). These add up fast. The Indigo Variables Store booleans for whether Client is using Source as one of it’s sources that are rotated in a refreshing image.

-The plugin “Group Event Listener” monitors the Indigo Variables and tracks if a value changes. If there is a change, an Action Group script modifies the main data source (in json, also in an Indigo Variable) that determines who is subscribed to whom.

-A schedule that runs every 10 sec calls an Action Group that cycles through each Source for each Client.

So... I use Variables, Action Groups, Triggers, and a Schedule. I think this is begging to be done in a plug-in, but I’m not sure which sample plugin is a good start, ESPECIALLY for monitoring for changes. Below are some snapshots to give you an idea of the final implementation.

Image
Image


Sent from my iPhone using Tapatalk

Posted on
Tue Aug 21, 2018 5:14 pm
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: 8 independent scripts + triggers + variable generation s

I've created a little plugin that illustrates how to monitor for variable changes. It'll get added to the SDK the next time we rev it, but in the meantime here's the plugin.py file (it's not huge):

Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
####################
# Copyright (c) 2018, Perceptive Automation, LLC. All rights reserved.
# http://www.indigodomo.com

try:
    import indigo
except:
    pass

# Note the "indigo" module is automatically imported and made available inside
# our global name space by the host process. However, to avoid lots of error
# highlighting by many IDEs we added the import above which usually fixes it.

################################################################################
class Plugin(indigo.PluginBase):
    ########################################
    def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
        super(Plugin, self).__init__(pluginId, pluginDisplayName, pluginVersion, pluginPrefs)
        self.debug = True

    ########################################
    def startup(self):
        self.logger.debug(u"startup called -- subscribing to variable changes")
        # Subscribe to all variable changes
        indigo.variables.subscribeToChanges()

    def shutdown(self):
        self.logger.debug(u"shutdown called")

    ########################################
    def variableCreated(self, var):
        '''
        This method is called whenever a new variable is created.

        :param self: Your plugin instance
        :param var: The variable that has been created
        :return: No return value required
        '''
        # You must call the superclass method
        super(Plugin, self).variableCreated(var)
        self.logger.debug(u"variableCreated called for variable '{}': value: {}".format(var.name, var.value))
        # Do your stuff

    def variableUpdated(self, origVar, newVar):
        '''
        This method is called every time a variable is changed in any way (name, value, etc). Your
        plugin will likely need to inspect the variable to see if it's one you're interested in. You
        can compare the previous value to the new value if you need to.

        :param self: Your plugin instance
        :param origVar: An instance of the indigo.Variable object as it was before the change
        :param newVar: An instance of the indigo.Variable object as it is currently (after the change)
        :return: No return value required
        '''
        # You must call the superclass method
        super(Plugin, self).variableUpdated(origVar, newVar)
        self.logger.debug(u"variableUpdated called")
        self.logger.debug(u"old name: {}, old value: {}".format(origVar.name, origVar.value))
        self.logger.debug(u"new name: {}, new value: {}".format(newVar.name, newVar.value))
        # Do your stuff

    def variableDeleted(self, var):
        '''
        This method is called every time a variable is deleted. Since your plugin
        will likely depend on only specific variables, you'll want to make sure that
        you take the appropriate action when a variable that it depends on is deleted.

        :param self: Your plugin instance
        :param var: An instance of the indigo.Variable object that has been deleted
        :return: No return value required
        '''
        # You must call the superclass method
        super(Plugin, self).variableDeleted(var)
        self.logger.debug(u"variableDeleted called for variable '{}': value: {}".format(var.name, var.value))
        # Do your stuff

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Aug 22, 2018 8:28 am
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: 8 independent scripts + triggers + variable generation s

Thank you Jay,
I imagine this could be easily modified to monitor device state changes as well?


Sent from my iPhone using Tapatalk

Posted on
Wed Aug 22, 2018 9:42 am
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: 8 independent scripts + triggers + variable generation s

Absolutely - you subscribe to device changes the same way, and the method calls are listed in the plugin.py method chart.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 14 guests