[ANSWERED]Return to previous state

Posted on
Wed Jan 13, 2016 3:17 pm
greenhornet offline
Posts: 61
Joined: Jan 22, 2011

[ANSWERED]Return to previous state

I'm creating an action group where various lights flash when a condidtion is triggered. I would like to have the lights return to the state they were in prior to the trigger. How can I accomplish this?

Thanks in advance for any help.

Posted on
Thu Jan 14, 2016 1:14 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Return to previous state

I think you'd ideally need a script to do this.

You can use actions to store a device state into a variable before you start them flashing.

But I can't think of a sensible way of putting the states back.

I'm not at my PC right now so the first line of this code might need tweaking:

Code: Select all
if indigo.variables[123356].getbool():
    indigo.devices[123456].turnOn()
else:
    indigo.devices[123456].turnOff()

Replace the IDs of variables and matching devices then copy for each device.


Sent from my iPhone using Tapatalk

Posted on
Thu Jan 14, 2016 10:50 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Return to previous state

So, to clarify, here's what you can do in your Action Group:

  1. Add an action that uses the Insert Device State into Variable action to save the "onOffState" of the device in question
  2. Add your other actions that do the flashing (add a small delay so that the action above can complete before the device changes state while flashing)
  3. Add a final action that sets the device back to it's stored state (again, you'll want to delay but this time wait until your flashing ends). howartp's script is close:

Code: Select all
if indigo.variables[123356].getvalue(bool):
    indigo.device.turnOn(123456)
else:
    indigo.device.turnOff(123456)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 14, 2016 6:04 pm
greenhornet offline
Posts: 61
Joined: Jan 22, 2011

Re: [ANSWERED]Return to previous state

Guys,
Thanks for the help. I'm doing something wrong. After attempting Jay's script, I get the following error in the log:

Code: Select all
Error                           failed to execute script because script could not be compiled


This is what I have configured for the Action:

    Insert Device State Into Variable
    long alert (it's a Hue Bulb)
    execute embedded AppleScript (see script below)

Code: Select all
if indigo.variables[TARDIS Lamp].getvalue(bool):
    indigo.device.turnOn(TARDIS Lamp)
else:
    indigo.device.turnOff(TARDIS Lamp)

Posted on
Fri Jan 15, 2016 12:51 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: [ANSWERED]Return to previous state

That's not an AppleScript, it's a python script.

Change your action to execute an embedded Python script.

Then, at top right of the textarea where you paste the code, press compile - that will check the code and give you an idea of its right or wrong.


Sent from my iPhone using Tapatalk

Posted on
Fri Jan 15, 2016 12:54 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: [ANSWERED]Return to previous state

Oh, and you will need quotes around "TARDIS Lamp" in each place:

Code: Select all
If indigo.variables["TARDIS Lamp"].getvalue(bool):



Sent from my iPhone using Tapatalk

Posted on
Fri Jan 15, 2016 12:05 pm
greenhornet offline
Posts: 61
Joined: Jan 22, 2011

Re: [ANSWERED]Return to previous state

Thank you. Unfortunately, it's still throwing erros:

Code: Select all
 Hue Lights Error                Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 660, in runConcurrentThread
  File "plugin.py", line 2106, in getBulbStatus
<type 'exceptions.StandardError'>: ServerCommunicationError -- timeout waiting for response

  Hue Lights Error                plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)


Posted on
Fri Jan 15, 2016 12:16 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: [ANSWERED]Return to previous state

You'll need NSheldon to answer that one.

Can you post the embedded code you're using whilst he pops along?

(I'll summon him)


Sent from my iPhone using Tapatalk

Posted on
Fri Jan 15, 2016 12:42 pm
greenhornet offline
Posts: 61
Joined: Jan 22, 2011

Re: [ANSWERED]Return to previous state

You lost me. The only code I'm using is what we've been discussing. What am I not seeing? I'm sure it's obvious...
Code: Select all
if indigo.variables["TARDIS Lamp"].getvalue(bool):
    indigo.device.turnOn("TARDIS Lamp")
else:
    indigo.device.turnOff("TARDIS Lamp")

Posted on
Fri Jan 15, 2016 1:03 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: [ANSWERED]Return to previous state

That error is not the direct result of the script. Something is causing the Hue plugin to fail. I think a full description (where the script resides, how you're executing it, what other things are happening, etc.) is required to see if there's any indirect relationship between the script and the error.

BTW, there is a problem with your script: "TARDIS Lamp" isn't a valid variable name since variables can't have spaces in the name, so your script isn't working anyway. You really shouldn't be using names anyway because if you change the name of something the script will break. Use IDs instead to make it more robust.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Jan 16, 2016 12:47 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: [ANSWERED]Return to previous state

The Hue Lights error you're seeing...
Code: Select all
 Hue Lights Error                Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 660, in runConcurrentThread
  File "plugin.py", line 2106, in getBulbStatus
<type 'exceptions.StandardError'>: ServerCommunicationError -- timeout waiting for response

  Hue Lights Error                plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

has nothing to do with your script (though, as Jay pointed out, the script won't work in t's current state). The error above indicates that the Hue Lights plugin is unable to reach your Hue hub. Make sure that you have the correct IP address in the Hue Lights plugin configuration window (Plugins menu -> Hue Lights -> Configure). If the IP address does not exactly match the IP address of your Hue hub, the plugin cannot communicate with the hub. It's a good idea to configure your router to always give the Hue hub the same IP address so the IP address doesn't change every time you restart the hub or the router (thus causing the plugin to loose the connection until the new IP is configured in the Configuration window). The way to do this varies from router to router, but it's sometimes called an IP address reservation. Alternatively (and possibly more easily), configure the Hue hub to not use DHCP and set the IP address manually. This can be done in the Hue app on your iOS device.

Once the plugin is communicating with the Hub, you don't need to do any scripting to make a Hue light flash. You've already got the right idea by using the "Long Alert" action. The "Long Alert" action will cause the Hue bulb or other Hue controlled light to blink about 1 time per second for about 15 seconds before automatically returning to the previous state. The "Short Alert" blinks the light just once before returning it to the previous state. You don't need scripts to activate either Long Alert or Short Alert actions.

Posted on
Sat Jan 16, 2016 10:15 am
greenhornet offline
Posts: 61
Joined: Jan 22, 2011

Re: [ANSWERED]Return to previous state

nsheldon wrote:
The Hue Lights error you're seeing...
Code: Select all
 Hue Lights Error                Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 660, in runConcurrentThread
  File "plugin.py", line 2106, in getBulbStatus
<type 'exceptions.StandardError'>: ServerCommunicationError -- timeout waiting for response

  Hue Lights Error                plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)

has nothing to do with your script (though, as Jay pointed out, the script won't work in t's current state). The error above indicates that the Hue Lights plugin is unable to reach your Hue hub. Make sure that you have the correct IP address in the Hue Lights plugin configuration window (Plugins menu -> Hue Lights -> Configure). If the IP address does not exactly match the IP address of your Hue hub, the plugin cannot communicate with the hub. It's a good idea to configure your router to always give the Hue hub the same IP address so the IP address doesn't change every time you restart the hub or the router (thus causing the plugin to loose the connection until the new IP is configured in the Configuration window). The way to do this varies from router to router, but it's sometimes called an IP address reservation. Alternatively (and possibly more easily), configure the Hue hub to not use DHCP and set the IP address manually. This can be done in the Hue app on your iOS device.

Once the plugin is communicating with the Hub, you don't need to do any scripting to make a Hue light flash. You've already got the right idea by using the "Long Alert" action. The "Long Alert" action will cause the Hue bulb or other Hue controlled light to blink about 1 time per second for about 15 seconds before automatically returning to the previous state. The "Short Alert" blinks the light just once before returning it to the previous state. You don't need scripts to activate either Long Alert or Short Alert actions.



nsheldon - thanks for your reply. I still have to answer Jay's questions (which will take a bit more time) but I wanted to clear a couple things up for you, and anyone reading this.

100% positve the Hue hub has a static IP that hasn't changed. I've got it configured in my Cisco router. Here's the weird part - the light still works. So, even though Indigo says it can't communicate (I'm taking you at your word here), there are ZERO problems controlling it from Indigo.

Second - I may not want to use a Hue bulb for the flashing, because the "long alert" that you mentioned sucks. I'm trying to get a slow dim and brighten that's less abrupt. I have a hue bulb (for now) but that may change if I don't figure out a way to use it with a dimming / brighting effect.

Again, thanks for your help. Appreciate the response.

Posted on
Sat Jan 16, 2016 1:25 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: [ANSWERED]Return to previous state

Hi. Glad to help. Upon closer inspection, that error is not about communicating with the Hue hub, but about the plugin being able to communicate with the Indigo server itself. The error is likely a side effect of the server attempting to execute the bad code in the embedded Python script and temporarily becoming unresponsive. So once the script execution issue is resolved, the above error will likely go away. Sorry for the confusion.

As for the Long and Short Alerts, they are built-in Hue hub functions that are simply called from the plugin, so the plugin has no control over the appearance of fading or the speed of the flash for those alerts. So to accomplish what you're describing, you'd need to use the method described by howartp and Jay..

Posted on
Tue Jan 19, 2016 8:33 am
greenhornet offline
Posts: 61
Joined: Jan 22, 2011

Re: [ANSWERED]Return to previous state

Thanks to everyone for helping. I've made changes based on the recommendations and am now getting a different error. I've changed the script so that it uses the device ID instead of names. Perhaps it's best to try and outline my setup (as Jay asked).

The error I'm now getting is:

Code: Select all
 Script Error                    embedded script: 'key name 998140627 not found in database'
  Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 1, at top level
KeyError: 'key name 998140627 not found in database'


I think I know what this is. I'm using a Hue Light (for now) instead of an Insteon Device. Shouldn't the format for Hue Device IDs in Python be a little different than [12345678] ?

My script is:
Code: Select all
if indigo.variables[indigo.devices[998140627] # "TARDIS Lamp"].getvalue(bool):
    indigo.device.turnOn(indigo.devices[998140627] # "TARDIS Lamp")
else:
    indigo.device.turnOff(indigo.devices[998140627] # "TARDIS Lamp")

This is all setp on a dedicated Yosemite Mac Mini.
I have an action group configured. When an outside motion sensor detects activity, this action group is triggered. The action group is very shot at the moment (4 steps). Insert device state into variable, Hue lights long alert, play a sound through the computer speakers, and THIS python script. The script resides inside the action group.

Posted on
Thu Jan 21, 2016 9:52 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: [ANSWERED]Return to previous state

Your script doesn't make any sense actually - you're passing a device instance as a key to the variables dictionary. I'm now even more unclear what you're doing. Also, you can't have a comment in the middle of Python so I don't know how it's even compiling.

The error you show is because you were (before you changed the script to invalid Python) using the device ID in the indigo.variables[] call - the ID is for the device, not an Indigo variable.

So, I have to go back to my previous request: you really need to describe fully all the parts of your solution. Otherwise, we're just chasing our tails trying to guess what you've got.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 1 guest

cron