Updating virtual device Last Update timestamp?

Discuss Python scripts here.
ryanbuckner
Posts: 1107
Joined: Sat Oct 08, 2011 12:33 pm
Location: Northern Virginia
Contact:

Updating virtual device Last Update timestamp?

Post by ryanbuckner »

I have. a virtual on/off device that gets status from a variable. That variable is updated by an API call to a 3rd party device not currently supported by Indigo. It's a back yard gate so it will not change 90% of the time.

I would like to update this Last Update timestamp each time the script runs so I know that the API is executing properly, even if the state does not change.

virtual_device.png
virtual_device.png (76.65 KiB) Viewed 751 times

I saw this code in the documentation. Is there something similar to update the Last Update timestamp ?

Code: Select all

virtual_devices_interface = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.devicecollection")
if virtual_devices_interface.isEnabled():
    virtual_devices_interface.executeAction('setVirtualDeviceState', deviceId=DEVICEIDHERE, props={'newValue': 'on'})
User avatar
DaveL17
Posts: 6858
Joined: Tue Aug 20, 2013 11:02 am
Location: Chicago, IL, USA
Contact:

Re: Updating virtual device Last Update timestamp?

Post by DaveL17 »

If I'm not mistaken, if you send a value that's equal to what it's currently set to, the device won't register an update (but I wouldn't swear to that in court).

Here's one option that I *THINK* would work. Using the Global Property Manager plugin, add a custom property to the device and then -- using your script -- set the custom property to something like a timestamp (which by definition will always be different). I'm pretty sure when the value of the custom property changes, the Last Update value will change as well because there's been a change to the device dictionary.
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]
User avatar
jay (support)
Site Admin
Posts: 18376
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Updating virtual device Last Update timestamp?

Post by jay (support) »

I don't think so - the server updates that timestamp automatically when a device changes. But the server is somewhat clever in that something actually has to change before it will update.

You can probably change the variable value to an empty string then set it to the value, like this (which will always force the last update field to update even if it didn't really change):

Code: Select all

indigo.variable.updateValue(12345, "");indigo.variable.updateValue(12345, "true")
If you watch the variable window, you'll see the variable value kinda flash. However, I never saw the virtual device itself to go into and then out of error mode. But it is in fact doing that, it's just not visible in the UI (at least on my dev Mac). It looks like if you trigger using device state changed - on/off state - becomes on then it will not fire when the state changes to error ("") then back to on (true). So that might be a reasonable workaround. You'd definitely want to test any logic around that device to make sure there weren't other side effects.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
jay (support)
Site Admin
Posts: 18376
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Updating virtual device Last Update timestamp?

Post by jay (support) »

DaveL17 wrote: Thu Sep 05, 2024 3:16 pmHere's one option that I *THINK* would work. Using the Global Property Manager plugin, add a custom property to the device and then -- using your script -- set the custom property to something like a timestamp (which by definition will always be different). I'm pretty sure when the value of the custom property changes, the Last Update value will change as well because there's been a change to the device dictionary.
That was my first thought, but it doesn't update the timestamp, probably because it's more of a definition/property item rather than an actual device attribute/state.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
ryanbuckner
Posts: 1107
Joined: Sat Oct 08, 2011 12:33 pm
Location: Northern Virginia
Contact:

Re: Updating virtual device Last Update timestamp?

Post by ryanbuckner »

DaveL17 wrote: Thu Sep 05, 2024 3:16 pm If I'm not mistaken, if you send a value that's equal to what it's currently set to, the device won't register an update (but I wouldn't swear to that in court).

Here's one option that I *THINK* would work. Using the Global Property Manager plugin, add a custom property to the device and then -- using your script -- set the custom property to something like a timestamp (which by definition will always be different). I'm pretty sure when the value of the custom property changes, the Last Update value will change as well because there's been a change to the device dictionary.
I just tried this and Jay was right. It didn't update
ryanbuckner
Posts: 1107
Joined: Sat Oct 08, 2011 12:33 pm
Location: Northern Virginia
Contact:

Re: Updating virtual device Last Update timestamp?

Post by ryanbuckner »

jay (support) wrote: Thu Sep 05, 2024 3:22 pm You can probably change the variable value to an empty string then set it to the value, like this (which will always force the last update field to update even if it didn't really change):
Since the virtual device state is updated from a variable, what would trigger the device state to update if I set the device value to "" ? I don't want to force a change in the variable because that would cause false on Change triggers
User avatar
jay (support)
Site Admin
Posts: 18376
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Updating virtual device Last Update timestamp?

Post by jay (support) »

Anything other than a boolean as the var value will be treated as an error string. So in effect it will go into an error state and then back out (I think) which will cause the timestamp to update.

Can’t recall if that’ll cause the trigger to fire, but you can easily test that.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
Post Reply

Return to “Python Scripting”