Properties of a Virtual Device Group

Posted on
Thu Jun 30, 2022 8:53 am
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Properties of a Virtual Device Group

In my Indigo 2022.1 setup I've configured for each room a virtual device containing all of the physical devices in that room. Each of my rooms has multiple devices. I'm trying to figure out if those virtual devices might expose a property telling me how many of the physical devices in that group are on. I'm looking for an elegant way to answer the question *how many devices are on in the ______* so I can potentially trigger actions based on that number.

Failing that, I wonder if *folders* might help me get at this elusive number. Maybe I could make a folder for each *room*, put all the devices into their corresponding folder, and run some kind of nested loops to iterate first through the collection of folders, then through the devices within that folder?

I now somebody has an elegant idea for this !

Posted on
Thu Jun 30, 2022 9:16 am
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

I'd be willing to make a folder for each room, assign devices to that folder, then perhaps use something like "len" and "filter" to get the number of "on" devices that appear in a particular folder. Is that a thing?

Posted on
Thu Jun 30, 2022 10:43 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Properties of a Virtual Device Group

Folders are purely a UI convenience. There are no scripting or server methods that do what you want. You could write your own, but it would require scheduling a script to run often (every minute?) that iterated through all devices in the system and counted how many are on in each room (folder) and then saving that to a list of variables.

If you did it as a plugin, you could just do the complete scan once on startup, and then update the room counts by observing the device updates.

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

Posted on
Thu Jun 30, 2022 10:59 am
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

FlyingDiver wrote:
Folders are purely a UI convenience. There are no scripting or server methods that do what you want. You could write your own, but it would require scheduling a script to run often (every minute?) that iterated through all devices in the system and counted how many are on in each room (folder) and then saving that to a list of variables.


I do run a script along these lines every minute, to handle devices that were inadvertently left on. I would happily rewrite it with an outer loop iterating through all of the folders (which I know how to do) and an inner loop iterating through that specific folder's devices (which I don't know how to do).

My current device loop looks like this:
Code: Select all
for dev in indigo.devices.iter("indigo.dimmer, indigo.relay"):


Is there a way to code that with some kind of filter on folderId ?

Posted on
Thu Jun 30, 2022 11:06 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Properties of a Virtual Device Group

Not directly via an iteration. You'd have to inside the loop compared dev.folderId to see if it matches. Filtering on folderId at the iteration level is a good feature request though, so I'm adding it to my list.

Image

Posted on
Thu Jun 30, 2022 11:06 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Properties of a Virtual Device Group

No, so you would need to do the same outer loop, then examine each device, get the folderID, then increment a variable if the device is on. The code is pretty pretty straightforward.

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

Posted on
Thu Jun 30, 2022 11:10 am
jay (support) offline
Site Admin
User avatar
Posts: 18216
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Properties of a Virtual Device Group

You definitely would need a script. Here's a script that would inspect each device in your device group and count the number that are on:

Code: Select all
group = indigo.devices[707703952] # "All Accent Lights"
on_count = 0
for device_id in group.ownerProps["deviceList"]:
    if indigo.devices[int(device_id)].onState:
        on_count += 1


At the end of the script, on_count would contain the number that are on. Of course, this being a script, it will only be accurate for that exact point in time (as Joe points out), but as your request is just to ask the question how many are on, this script will tell you.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jun 30, 2022 12:40 pm
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

jay (support) wrote:
You definitely would need a script. Here's a script that would inspect each device in your device group and count the number that are on:

Code: Select all
group = indigo.devices[707703952] # "All Accent Lights"
on_count = 0
for device_id in group.ownerProps["deviceList"]:
    if indigo.devices[int(device_id)].onState:
        on_count += 1


At the end of the script, on_count would contain the number that are on. Of course, this being a script, it will only be accurate for that exact point in time (as Joe points out), but as your request is just to ask the question how many are on, this script will tell you.


This is a GREAT starting point. Thank you so much! Is there an alternative where, instead of:

Code: Select all
group = indigo.devices[707703952] # "All Accent Lights"


I could use a "for" loop that includes all the group devices?

Posted on
Thu Jun 30, 2022 12:41 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Properties of a Virtual Device Group

SearchCz wrote:
This is a GREAT starting point. Thank you so much! Is there an alternative where, instead of:

Code: Select all
group = indigo.devices[707703952] # "All Accent Lights"


I could use a "for" loop that includes all the group devices?


That's the third line in the script.

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

Posted on
Thu Jun 30, 2022 12:50 pm
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

FlyingDiver wrote:
SearchCz wrote:
This is a GREAT starting point. Thank you so much! Is there an alternative where, instead of:

Code: Select all
group = indigo.devices[707703952] # "All Accent Lights"


I could use a "for" loop that includes all the group devices?


That's the third line in the script.


I believe that the third line of code gives me all of the devices in the group I specify.

I'm talking about an iteration through all of the virtual devices that are themselves groups. SO that I don't have to specify ID# 12345, ID#67890, ID# 54321 etc.

pseudo-code like:

Code: Select all
For every GROUP device
    Set a counter to zero
    For every DEVICE in that GROUP
         increment a counter if thatDEVICE is on

Posted on
Thu Jun 30, 2022 1:05 pm
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

actually, this is pretty tight already. i can code it as a callable function and pass in the IDs of the group I want inspected and the variable I want the result stored in. that's pretty tight.

jay (support) wrote:
You definitely would need a script. Here's a script that would inspect each device in your device group and count the number that are on:

Code: Select all
group = indigo.devices[707703952] # "All Accent Lights"
on_count = 0
for device_id in group.ownerProps["deviceList"]:
    if indigo.devices[int(device_id)].onState:
        on_count += 1


At the end of the script, on_count would contain the number that are on. Of course, this being a script, it will only be accurate for that exact point in time (as Joe points out), but as your request is just to ask the question how many are on, this script will tell you.

Posted on
Thu Jun 30, 2022 1:25 pm
jay (support) offline
Site Admin
User avatar
Posts: 18216
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Properties of a Virtual Device Group

SearchCz wrote:
I'm talking about an iteration through all of the virtual devices that are themselves groups.


Code: Select all
for device_group in indigo.devices.iter("com.perceptiveautomation.indigoplugin.devicecollection.relayGroup"):
    # do the inner loop here

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jun 30, 2022 2:33 pm
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

jay (support) wrote:
SearchCz wrote:
I'm talking about an iteration through all of the virtual devices that are themselves groups.


Code: Select all
for device_group in indigo.devices.iter("com.perceptiveautomation.indigoplugin.devicecollection.relayGroup"):
    # do the inner loop here


That’s perfect !

Posted on
Thu Jun 30, 2022 6:08 pm
SearchCz offline
Posts: 172
Joined: Sep 18, 2019

Re: Properties of a Virtual Device Group

Alright, guys ! That code hit the spot !

I don't know if I shared it right, but here's the control page I was trying to build that wanted that "on" count.
Attachments
Screen Shot 2022-06-30 at 8.05.59 PM.png
Screen Shot 2022-06-30 at 8.05.59 PM.png (416.68 KiB) Viewed 1443 times

Posted on
Thu Jun 30, 2022 6:47 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Properties of a Virtual Device Group

Nice design!

Image

Who is online

Users browsing this forum: No registered users and 9 guests