Turn off virtual device only if it's on

Posted on
Tue Sep 24, 2019 10:56 am
jmdraper offline
Posts: 103
Joined: Sep 11, 2014
Location: Surrey, UK

Turn off virtual device only if it's on

There must be an elegant way to do this but I cannot think what it is: suggestions please!

I have a bunch of virtual devices set up for 'radios' around my house. The radio source is VLC running on my server and tuned to an internet radio station. The virtual device on/off action groups take care of connecting / disconnecting speakers using AirFoil etc. to make the individual 'radios' come on and off. Because I have one radio source, I have a counter variable which is incremented and decremented by the virtual device action groups and when it gets to 0, a trigger then stops VLC (and other trigger starts VLC streaming again when the counter becomes >0). So far so good.

Sometimes for various reasons an off command will be sent to these virtual devices when they're already off. In these cases, the counter gets decremented when it shouldn't.

I can think of lots of really messy ways to resolve this, but they're all really ugly. I really want to put the solution in the virtual device action groups rather than all the places that send commands to them, for ease of maintenance. The best I've come up with is to add a script for each virtual device 'off' action group and have the script check whether it's on first. But I don't want to write a bunch of scripts if I don't have to, as for simple things like this it's easier to maintain without scripts in my view. If I could add conditions to an action group, I'd be sorted but of course that's not possible.

Any suggestions please? Ideally avoiding scripts.

Thanks!

Posted on
Tue Sep 24, 2019 3:26 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Turn off virtual device only if it's on

If the extra off is happening through a trigger/schedule, then just put a condition on the trigger/schedule that checks first to see if the variable is already 0.

Another option is to run a script action to decrement the variable rather than use the built-in set variable action which would make sure the variable isn't already 0:

Code: Select all
counter_var = indigo.variables[ID_OF_COUNTER_VAR_HERE]
current_count = counter_var.getValue(int)
if current_count > 0:
    indigo.variable.updateValue(counter_var, value=str(current_count - 1))


Otherwise, a more hacky solution (though one not requiring a script or any other change to your environment) would be to have a trigger that watches the variable and if the value becomes less than 0, set it to 0.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Sep 25, 2019 2:26 am
jmdraper offline
Posts: 103
Joined: Sep 11, 2014
Location: Surrey, UK

Re: Turn off virtual device only if it's on

Thanks Jay

Yes I had already implemented your last suggestion of a script that watches the variable and resets it to 0 if it goes negative. I thought that would be good enough and left it. But there are some edge cases which occur just often enough to be annoying where the problem is not just the counter being below zero but it being inaccurate. E.g. when one radio is on and an off command is sent to another radio which was already off, the counter gets decremented to 0 so my other trigger correctly kicks in and stops the radio stream when in fact there was still one radio in use.

There are way too many different triggers, schedules and action groups all over the place which control the radio devices for me to want to go round tracking them down and adding conditions to all of them. So I think I will go with either turning all the virtual device 'off' action groups into scripts with a check for 'if on' at the start, or possibly if I'm feeling brave I might try to create a basic plugin to wrap an on/off device so that when sent an off it will check whether it's on first before sending off to the wrapped device.

Thanks again for your response - it's good to know I wasn't missing something more obvious!

BTW - I have been changing a bunch of stuff in my automation set up recently and got thinking about maintainability and how I could make it easier for me to do stuff like this. I had an idea: tagging. If I could tag devices, triggers, schedules and action groups and have a hierarchy of tags then I could for example tag all of the bits that make up my 'radio' automation and find them all really easily. I try to do this as best I can with folders at the moment but there are two problems with that approach: (1) there are still lots of folders because there is one in each category and I find having *loads* of folders is actually just as hard to keep track of (2) many triggers / schedules etc logically belong in more than one place - e.g. there are things that I could easily count as being part of my 'occupancy tracking' automation that also logically form part of my 'alarm' automation. Tagging would allow me to apply multiple tags and find them easily under both.

Any chance we could get tagging and a tag hierarchy view added to the Indigo Mac app?

Thanks!
Jon

Posted on
Wed Sep 25, 2019 6:27 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Turn off virtual device only if it's on

jmdraper wrote:
BTW - I have been changing a bunch of stuff in my automation set up recently and got thinking about maintainability and how I could make it easier for me to do stuff like this. I had an idea: tagging. If I could tag devices, triggers, schedules and action groups and have a hierarchy of tags then I could for example tag all of the bits that make up my 'radio' automation and find them all really easily. I try to do this as best I can with folders at the moment but there are two problems with that approach: (1) there are still lots of folders because there is one in each category and I find having *loads* of folders is actually just as hard to keep track of (2) many triggers / schedules etc logically belong in more than one place - e.g. there are things that I could easily count as being part of my 'occupancy tracking' automation that also logically form part of my 'alarm' automation. Tagging would allow me to apply multiple tags and find them easily under both.

Any chance we could get tagging and a tag hierarchy view added to the Indigo Mac app?


You can do this now for devices, by putting a string (hashtag) in the Notes field. Not a hierarchy, but it's a start.

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

Posted on
Wed Sep 25, 2019 8:33 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Turn off virtual device only if it's on

jmdraper wrote:
Any chance we could get tagging and a tag hierarchy view added to the Indigo Mac app?


This is on the request list already. No ETA of course.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests