Page 3 of 3

Re: use custom states from a ghost xml device

PostPosted: Sat Jul 17, 2021 5:03 pm
by Monstergerm
Hi Dave,
so here is something weird. If I refresh my stock quote ghostxml device using a python script it takes about 2 seconds for the device "Last update date" to change.

If I however add a delay of 10 seconds in the python script AFTER the device refresh code line, the device "Last update date" does not change for 10 seconds but then shows again a date that is 2 seconds after I ran the script. Hope this is clear. So it looks like the Indigo interface does not update the date for 10 seconds and if I grab the "Last update date" during this time it still shows the old date. Only after the script finishes, everything gets properly updated with the correct times.

Now, I am not even sure anymore that adding a delay will help me getting updated data for my variables.

Re: use custom states from a ghost xml device

PostPosted: Sat Jul 17, 2021 5:59 pm
by FlyingDiver
If you're doing a sleep() call in the middle of an embedded Python script, you're locking up the entire Indigo server until after the script ends. So the variables can't be updated during the script.

Just do the initial GhostXML call in the script, then do the rest in a trigger on the device state changing.

Re: use custom states from a ghost xml device

PostPosted: Sat Jul 17, 2021 6:08 pm
by DaveL17
That's not necessarily strange in so far as Indigo may just be waiting to update the UI with the latest information.

I think Joe's suggestion might be the safest bet. Fire an update on your time table and then trigger on when the device Last Update value changes.

EDIT: Jinx. Buy me a Coke.

Re: use custom states from a ghost xml device

PostPosted: Sat Jul 02, 2022 12:03 pm
by gskarp
How would we trap for a custom state that is not always in the feed.? In the Open Weather feed, the rain forecast shows up occasionally. I would like to capture that number whenever it happens. Is there a way to run a script that ignores that state if is does not exist?

Re: use custom states from a ghost xml device

PostPosted: Sat Jul 02, 2022 12:41 pm
by DaveL17
Absolutely. In Python, you can account for a missing dictionary key with 'get':

Code: Select all
x = my_dict.get('key', "default value if key doesn't exist")