Auto Company Modes for the Fingscan Plugin

Posted on
Mon Oct 17, 2016 11:19 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Auto Company Modes for the Fingscan Plugin

I reread the thread and see my mistake. You never said there were any commingled devices--looks like I inferred that. SO we don't need to worry about 'onOffState'' at all. No wonder you were confused by that bit. Sorry about that.

Code: Select all
company_devices = []  # A blank list to start with
folder_id = 1314917481  # the ID of your default folder
variable_id = 1961258112  # the ID of your tracking variable

# Loop through Indigo devices
for dev in indigo.devices.itervalues():

    # Is the device in the default folder?
    if dev.folderId == folder_id:
        try:
            # Add the device's status to the list
            company_devices.append(dev.states['status'])
        except:
            pass

# Test the list.  If any of the statuses in the list are 'Up', set the variable to 'on'.  Otherwise, set it to 'off'.
if any(x == 'Up' for x in company_devices) :
    indigo.variable.updateValue(variable_id, 'on')
else:
    indigo.variable.updateValue(variable_id, 'off')

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Oct 17, 2016 5:24 pm
johnpolasek offline
Posts: 911
Joined: Aug 05, 2011
Location: Aggieland, Texas

Re: Auto Company Modes for the Fingscan Plugin

I had read it as a request for a commented example of how to do some of these things like scan a folder and build a list based on a device state... something like:

Code: Select all
###################################################################
# put this into an action then create a trigger for each device in
# the company folder when it "has any change" execute this action.
###################################################################

#Define an empty List
company_devices = []

#Define an empty Dictionary
company_dict = {}

#Define the company folder ID
Company_folder_id = 552440476

#define the Generic folder ID
General_Folder_id = 265474036

#define the IDs of indigo variables to recieve the data
Party_Count_id = 1329706809
Party_On_id = 271576056
Party_Members_id = 750274626

On_Company_Count = 0
On_Company_Names= ""
Somebodys_not_around = "false"

#Loop through all Indigo devices
#   Cant loop through just one folder;  Have to look at what
#   devices have the FolderId State that matches the desired
#   Folder(s)
for A_dev in indigo.devices.itervalues():
   
    if A_dev.folderId == Company_folder_id:
        #The device is in the Company Folder, do whatever you want:
        #for example...
        company_devices.append(A_dev) #Add it to the company device list
        #and/or
        company_dict[A_dev.name]=A_dev.id #Add it to the company dictionary
        #and/or
        if "onOffState" in A_dev.states:  #Do whatever you want to with the
                                             #device you found
            if A_dev. states['onOffState'] == "On":
                On_Company_Count += 1 #increment the number of devices
                On_Company_Names += ", "+ A_dev.name #make a list of who's around...
            else:
                Somebodys_not_around = "true" #note if at least device  missed the party..

        #could add an elif <condition>: or else: at this level for devices that don't have an onOffState...


     #could add another if for other folders here
           

# code at this level is done after the for loop is complete.
# you can use the indigo.variable(Var_ID,value) function to load the count, name, and somebody
#   variables into Indigo (which can then trigger more actions)
indigo.variable.updateValue(Party_Count_id,str(On_Company_Count)) #Must pass strings to indigo variables
indigo.variable.updateValue(Party_On_id,Somebodys_not_around)
indigo.variable.updateValue(Party_Members_id,On_Company_Names)

#and/or you can do more processing on the list and/or dictionary
for A_dev in company_devices:
    if A_dev.states['note'] is "Samsung": #if Galaxy, sound fire alarm...
        indigo.server.speak("FIRE, EVACUATE")
        pass #and exit the loop

#and/or
# use the try/except methodology to look up a specific person in the dictionary
try:
    #very convoluted logic... If we put a MaryAnn member into the dictionary, the
    # value of that member will be the id of the indigo device that has the state
    # we are looking for.  this can fall into the except branch if
    #   there is no MaryAnn device in the company folder OR
    #   if the MaryAnn device found doesn't have an state state in it
    if indigo.devices[company_dict["MaryAnn"].value].states['onOffState'] =="On":
        indigo.server.log("MaryAnn made it")
    else:
        indigo.server.log("MaryAnn didn't show up")
except:
    indigo.server.log("something went wrong") #send an error to the log

Posted on
Tue Oct 18, 2016 4:58 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Auto Company Modes for the Fingscan Plugin

Ha. Well perhaps I should elaborate.

My previous setup had a trigger for each device arriving and leaving. I also had three triggers with conditionals for each of those devices. So every time a new company device was on my network, I had to create two new triggers and modify 3 others. So basically the improvement is me being lazy.

My hope was that I could simply look at all the devices in a folder, but since I can't do that, I believe I will go with the list of devices. So I also believe that bit of code in Dave's snippet is uncesscary at this point too since I'm manually updating that list of devices within the script.

However, I'm at a loss for the best approach. I could arbitrarily run this every 15 seconds or I could still setup a trigger each company and run it everytime there is a change in state.

Anyone have any suggestions or improvements to that end?

Also, John, I got a huge kick out of your galaxy note fire notification :)

Posted on
Tue Oct 18, 2016 5:44 am
johnpolasek offline
Posts: 911
Joined: Aug 05, 2011
Location: Aggieland, Texas

Re: Auto Company Modes for the Fingscan Plugin

Using Karl's piBeacon plugin rather than Fingscan, I have been creating a single trigger for each beacon device that on any change calls a script (from which most of the code I posted above was stolen) that scans the valid beacons folder, creates a count and concatenated string of nonexpired beacons, and sets the Home state variable to Away/Home/Bypass depending on the count of beacons and state of the Bypass variable. It also resets the Bypass variable to false if the valid beacon count becomes nonzero. And Karl has announced just yesterday that he has modified the I7 version of the piBeacon plugin to allow each beacon to be placed in up to 4 "groups" and allows any change in the group's devices to act as a trigger, which will be get my number of triggers down to 1 and require only modifying the group status of any beacon that I want to be valid or no longer valid. Given that Fingscan operates very similarly, I would expect that he's using a lot of the same code for both, which would mean the same mods will be available here as well by Thanksgivnig (2017, 2020?).

Posted on
Tue Oct 18, 2016 5:59 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Auto Company Modes for the Fingscan Plugin

Dewster35 wrote:
...since I'm manually updating that list of devices within the script.

I guess I still don't understand. If you are adding a device to Indigo and placing it in your default company folder, this bit of code:
Code: Select all
# Loop through all devices
for dev in indigo.devices.itervalues(filter="com.something.indigoplugin.fingscan"):

    # Check to see if the device is in the default company folder
    if dev.folderId == folder_id:

Will find all the devices that you've placed in the company folder on its own. I'm not sure I understand why you would have to manually modify the script when you add a new device. I've also added an untested filter to the iterator (you'll need to replace my placeholder text with the actual bundle identifier of the Fingscan plugin) that would reduce the system load a bit more.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Oct 18, 2016 7:58 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Auto Company Modes for the Fingscan Plugin

I guess I still don't understand. If you are adding a device to Indigo and placing it in your default company folder, this bit of code:

Code: Select all
#Define an empty List
company_devices = []


OK. So the script itself is populating this list? I thought I was doing that manually... this is why I haven't done any programming in two years :)

Posted on
Tue Oct 18, 2016 8:26 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Auto Company Modes for the Fingscan Plugin

Yes, the script takes care of that for you. In Python, you have to declare the list before you can do anything to it.


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Oct 18, 2016 8:30 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Auto Company Modes for the Fingscan Plugin

And thanks you for all of your help! I need to get this setup soon. It's amazing how handy it is to get a 20 second heads up for someone arriving!

Posted on
Tue Oct 18, 2016 8:59 am
johnpolasek offline
Posts: 911
Joined: Aug 05, 2011
Location: Aggieland, Texas

Re: Auto Company Modes for the Fingscan Plugin

Dewster35 wrote:
I guess I still don't understand. If you are adding a device to Indigo and placing it in your default company folder, this bit of code:

Code: Select all
#Define an empty List
company_devices = []


OK. So the script itself is populating this list? I thought I was doing that manually... this is why I haven't done any programming in two years :)


The section that populates the list is the
Code: Select all
#Loop through all Indigo devices
#   Cant loop through just one folder;  Have to look at what
#   devices have the FolderId State that matches the desired
#   Folder(s)
for A_dev in indigo.devices.itervalues():
   
    if A_dev.folderId == Company_folder_id:
        #The device is in the Company Folder, do whatever you want:
        #for example...
        company_devices.append(A_dev) #Add it to the company device list


After this for loop is complete, you can do another loop by going back to no indention... Python begins for loop and if statement blocks with a ":" and indenting the code within the block by 4 spaces and ends when the indention quits... so the if is indented 4 spaces from the for, the stuff inside the if is indented 4 spaces from the if, and what you want to do after the script has put all the devices in the company folder into the company_devices list is at the same indention as the for... and anything after a '#' is a comment for you that python itself ignores

Posted on
Tue Oct 25, 2016 5:10 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Auto Company Modes for the Fingscan Plugin

Thank you guys for this! This is SO much less cumbersome than what I had. I have it running on a schedule as of now, but plan to add triggers for each device change at a future date. :mrgreen:

Posted on
Tue Oct 25, 2016 5:41 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Auto Company Modes for the Fingscan Plugin

Glad you were able to figure something out that works for you. Indigo's scripting capability is one of my favorite features.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Dec 11, 2016 8:04 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Auto Company Modes for the Fingscan Plugin

So during testing, this worked fantastically. However after a short time, it completely stopped working. Devices would arrive on the network and it would not update the company mode variable I had designated. Some new devices did get added to that folder in the interim so perhaps that could be related to the issue?

Posted on
Sun Dec 11, 2016 8:13 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Auto Company Modes for the Fingscan Plugin

Can you please provide the exact script as you've implemented it? It will help us understand what's going on.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Dec 11, 2016 8:41 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Auto Company Modes for the Fingscan Plugin

Code: Select all
company_devices = []  # A blank list to start with
folder_id = 878200254  # the ID of your default folder
variable_id = 936521597  # the ID of your tracking variable

# Loop through Indigo devices
for dev in indigo.devices.itervalues():

    # Is the device in the default folder?
    if dev.folderId == folder_id:
        try:
            # Add the device's status to the list
            company_devices.append(dev.states['status'])
        except:
            pass

# Test the list.  If any of the statuses in the list are 'Up', set the variable to 'on'.  Otherwise, set it to 'off'.
if any(x == 'Up' for x in company_devices) :
    indigo.variable.updateValue(variable_id, 'true')
else:
    indigo.variable.updateValue(variable_id, 'false')

Posted on
Sun Dec 11, 2016 11:41 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: Auto Company Modes for the Fingscan Plugin

this compiles and seems to do the trick.. breaks the loop if it found anyUp, no need to go through all devices

Code: Select all
folder_id = 878200254  # the ID of your default folder
variable_id = 936521597  # the ID of your tracking variable

anyUp = False
# Loop through Indigo devices
for dev in indigo.devices.itervalues():

    # Is the device in the default folder?
    if dev.folderId == folder_id:
        try:
           if dev.states['status'].lower() =='up':
               indigo.variable.updateValue(variable_id, 'true')
               anyUp=True
               break   
        except:
            pass

if not anyUp:
    indigo.variable.updateValue(variable_id, 'false')


Karl

Who is online

Users browsing this forum: No registered users and 2 guests