Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

How can I find the timestamp when a variable was changed


Question

Posted

Is there a way to find when a variable was last changed ?

7 answers to this question

Recommended Posts

  • 1
Posted
20 minutes ago, RohitNz said:

Is there a way to find when a variable was last changed ?

api.get('/globalVariables/'.."myVar").modified

ex.

print(os.date("%c",api.get('/globalVariables/'.."myVar").modified))

  • 1
Posted

Was just checking HC3 v5.150.18 Swagger and could not find globalVariables under the Select Definition. ;-)

 

Also can't believe that there is no function for that like hub.getGlobal("varName")

like on HC2 is fibaro:getGlobal("varName") or even better fibaro:getGlobalModificationTime("varName") 😮

 

I'm not surprised that @RohitNz had to ask about it here. Thanks @jgab for doing Fibaro job.

 

Fibaro, what is the use of "Game changer" box when it is missing proper manuals?

  • 0
Posted
58 minutes ago, Sankotronic said:

Was just checking HC3 v5.150.18 Swagger and could not find globalVariables under the Select Definition. ;-)

 

Also can't believe that there is no function for that like hub.getGlobal("varName")

like on HC2 is fibaro:getGlobal("varName") or even better fibaro:getGlobalModificationTime("varName") 😮

 

I'm not surprised that @RohitNz had to ask about it here. Thanks @jgab for doing Fibaro job.

 

Fibaro, what is the use of "Game changer" box when it is missing proper manuals?

It's under /panels/globalVariables

hub.getGlobalVariable(name)

...and it turns out that hub.getGlobalVariable(name) returns modification time as second returned result.

 

Please login or register to see this code.

 

 

  • 0
Posted

Big thanks @jgab ,

 

It is time for me to get new glasses 🥸

 

 

  • 0
Posted

@jgab how to use in ER5?

  • 0
Posted
22 hours ago, jgab said:

hub.getGlobalVariable(name)

...and it turns out that hub.getGlobalVariable(name) returns modification time as second returned result.

 

Please login or register to see this code.

 

 

Hi @jgab ,

 

Can you please explain the select(2,..) part in above line.

 

I have tested this code and it doesn't work in scene:

Please login or register to see this code.

but it works in Quick Apps.

Explanation of this function in

Please login or register to see this link.

is at least not complete and in

Please login or register to see this link.

is not mentioned even is working as expected??

 

 

  • 0
Posted (edited)
35 minutes ago, Sankotronic said:

 

Hi @jgab ,

 

Can you please explain the select(2,..) part in above line.

 

I have tested this code and it doesn't work in scene:

Please login or register to see this code.

but it works in Quick Apps.

Explanation of this function in

Please login or register to see this link.

is at least not complete and in

Please login or register to see this link.

is not mentioned even is working as expected??

 

 

 

Yes, it's because they maintain 2 different implementations of the fibaro sdk (or hub). One for scenes and one for QAs... 

It seems that the scene version of .getGlobalVariable(name) doesn't return the modification time as the second value. So for scenes you need to go back to the api

or redefine the function

Please login or register to see this code.

So, select is a standard Lua function. 

Please login or register to see this code.

will return the parameters from i and forward (as multiple values), so

Please login or register to see this code.

will return

Please login or register to see this code.

 

So, in our case, fibaro.getGlobalVariable("A") will return

Please login or register to see this code.

so our select(2,fibaro.getGlobalVariable("A")) will only give us the time that we then pass on to os.date()...

 

We could have written it as 

Please login or register to see this code.

but it is creating an unnecessary table and is much less efficient  and not the "Lua way" ;-) 

Edited by jgab
  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...