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

printing a global variable shows some unexpected numbers


Question

Posted

Can anyone tell me please, what are those numbers behind by global variable?

 

["192.168.100.7","192.168.100.23","192.168.100.47","192.168.100.96"] 1728491927

 

This is driving me crazy..all json.decodes fails..whatever i do, i get that number behind. I can change the content of any variable some numbers shows up behind.

15 answers to this question

Recommended Posts

  • 0
Posted (edited)

@Neo Andersson

unix timestamp it seems like :)

 

1728491927 is Wed Oct 09 2024 16:38:47 GMT+0000

Edited by Brors94
Tag
  • 0
  • Inquirer
  • Posted (edited)
    3 minutes ago, Brors94 said:

    @Neo Andersson

    unix timestamp it seems like :)

     

    1728491927 is Wed Oct 09 2024 16:38:47 GMT+0000

    yes but why??? all my json.decodes fail..i cant to anything

    Edited by Neo Andersson
    • 0
    Posted
    3 minutes ago, Neo Andersson said:

    yes but why??? all my json.decodes fail..i cant to anything

    You are printing the result from som function that returns 2 values. 

    Ex. fibaro.getValue usually returns the value and the timestamp

    Lua's print will print all values returned from the last argument, so

    print(fibaro.getValue(55,'value')) will print the value and the timestamp.

    To get rid of the multiple values and only return the first value you can enclose the expression in parenthesis.

    print((fibaro.getValue(55,'value'))) will only print the first value.

    • Like 1
    • 0
    Posted (edited)

    @jgab Got the answer :D 👆

     

    Or @Neo Andersson was pointing to globals 🤔

    so he isnt using the sintax fibaro.getvalue i guess? 🤔

     

     

    Edited by Brors94
    • 0
  • Inquirer
  • Posted (edited)
    13 minutes ago, jgab said:

    You are printing the result from som function that returns 2 values. 

    Ex. fibaro.getValue usually returns the value and the timestamp

    Lua's print will print all values returned from the last argument, so

    print(fibaro.getValue(55,'value')) will print the value and the timestamp.

    To get rid of the multiple values and only return the first value you can enclose the expression in parenthesis.

    print((fibaro.getValue(55,'value'))) will only print the first value.

    @jgab thanks for the answer, but this is crazy..how can this be possible..i am using this approach like in 50 quickapps. Many of them is running years and i never got that problem..

     

    Having this json string in a global variable SPEAKERS {"RobSpeaker":{"ip":"192.168.100.23","mac":"cc:f4:11:ce:51:5c"},"HubSpeaker":{"ip":"192.168.100.72","mac":"ac:67:84:83:46:75"},"OfficeSpeaker":{"ip":"192.168.100.96","mac":"ac:67:84:ec:90:a5"},"HallSpeaker":{"ip":"192.168.100.47","mac":"d4:f5:47:19:70:4b"},"LivingroomSpeaker":{"ip":"192.168.100.7","mac":"d4:f5:47:16:be:72"}} and using 

    Please login or register to see this code.

    always fails...

     

    So i need to always use paparenthesiss?? for any fibaro.getValue or fibaro.getGlobalVariable etc ?

     

    Here nust be something else behind the scenes..

     

    Like lterally i was using print(hub.getVariable(<somestringvariable>)) in milion ocasions and never had anything like that

    Edited by Neo Andersson
    • 0
  • Inquirer
  • Posted (edited)
    6 minutes ago, Neo Andersson said:

    @jgab thanks for the answer, but this is crazy..how can this be possible..i am using this approach like in 50 quickapps. Many of them is running years and i never got that problem..

     

    Having this json string in a global variable SPEAKERS {"RobSpeaker":{"ip":"192.168.100.23","mac":"cc:f4:11:ce:51:5c"},"HubSpeaker":{"ip":"192.168.100.72","mac":"ac:67:84:83:46:75"},"OfficeSpeaker":{"ip":"192.168.100.96","mac":"ac:67:84:ec:90:a5"},"HallSpeaker":{"ip":"192.168.100.47","mac":"d4:f5:47:19:70:4b"},"LivingroomSpeaker":{"ip":"192.168.100.7","mac":"d4:f5:47:16:be:72"}} and using 

    Please login or register to see this code.

    always fails...

     

    So i need to always use paparenthesiss?? for any fibaro.getValue or fibaro.getGlobalVariable etc ?

     

    Here must be something else behind the scenes..

     

    Like lterally i was using print(hub.getVariable(<somestringvariable>)) in milion ocasions and never had anything like that

    @jgab Wait,,,can this be just because i am using eventLib?

    Edited by Neo Andersson
    • 0
  • Inquirer
  • Posted

    Just to get me to some Psychiatric Institute this approach, that failied a few minutes ago

    Please login or register to see this code.

    doesnt fail. It works again, and i did nothing with the variables...nothing

     

    • 0
    Posted (edited)
    1 minute ago, Neo Andersson said:

    Just to get me to some Psychiatric Institute this approach, that failied a few minutes ago

    Please login or register to see this code.

    doesnt fail. It works again, and i did nothing with the variables...nothing

     


    What is setting thoose globals? is it that what sets it with a timestamp? 🤔

    Or is the timestamp still there? 

     

     

     

     

    Edited by Brors94
    • 0
  • Inquirer
  • Posted (edited)
    6 minutes ago, Brors94 said:


    What is setting thoose globals? is it that what sets it with a timestamp? 🤔

    Or is the timestamp still there? 

     

     

     

     

    when printing out without parenteshis it is still there, but for some reason the json.decode doesnt fail at this moment

    when i just open the web ui and grab the value of that variable, i can not see the timestamp, only when printing it out

    Edited by Neo Andersson
    • 0
    Posted
    4 minutes ago, Neo Andersson said:

    when printing out without parenteshis it is still there, but for some reason the json.decode doesnt fail at this moment

    when i just open the web ui and grab the value of that variable, i can not see the timestamp, only when printing it out

     

    Hmm strange 🤔
    I havent used alot of globals, but never experienced it 🤔

     

       
        local test = hub.getGlobalVariable("EVENTS")
        print(hub.getGlobalVariable("EVENTS"))  --- gives timestamp
        print("test:",hub.getGlobalVariable("EVENTS")) --- gives timestamp
        print("test:",(hub.getGlobalVariable("EVENTS"))) --- no timestamp
        print(test) --- no timestamp
        print("test:",test) --- no timestamp
     
    [DEBUG] [QUICKAPP2554]: {"2593":[{"event":{"type":"property","propertyName":"value"},"method":"onDeviceValueChange"}]} 1728491851
    [DEBUG] [QUICKAPP2554]: test: {"2593":[{"event":{"type":"property","propertyName":"value"},"method":"onDeviceValueChange"}]} 1728491851
    [DEBUG] [QUICKAPP2554]: test: {"2593":[{"event":{"type":"property","propertyName":"value"},"method":"onDeviceValueChange"}]}
     [DEBUG] [QUICKAPP2554]: {"2593":[{"event":{"type":"property","propertyName":"value"},"method":"onDeviceValueChange"}]}
     [DEBUG] [QUICKAPP2554]: test: {"2593":[{"event":{"type":"property","propertyName":"value"},"method":"onDeviceValueChange"}]}
     

     

    and this a strange thing you found here 😅

     

    @jgab why is it like this? sometimes it print without timestamp sometimes with? 

     

    • 0
  • Inquirer
  • Posted

    the major issue for me is, that is not consistant with json.decode(), like all the afternooon i was struggling to find why the decode doesnt work..then i found that it should be probably these extra timestamp numbers (that are invisible in web ui), later i tried it again and the same code works. Same variable, same code, and now works..Driving me crazy...I have so many quickapps running on customer's systems, and i naver ever had any issue with getValue or getGlobalVariable functions. I have never ever got timestamps written, or json.decode fails...

    • 0
    Posted
    Just now, Neo Andersson said:

    the major issue for me is, that is not consistant with json.decode(), like all the afternooon i was struggling to find why the decode doesnt work..then i found that it should be probably these extra timestamp numbers (that are invisible in web ui), later i tried it again and the same code works. Same variable, same code, and now works..Driving me crazy...I have so many quickapps running on customer's systems, and i naver ever had any issue with getValue or getGlobalVariable functions. I have never ever got timestamps written, or json.decode fails...

    Yea that is kinda scary 😲


     

     

    • 0
    Posted (edited)

    So, computers are rational and relative predictable - so it's usually in one own's code... ;-) 

    This will fail

    Please login or register to see this code.

    The reason is that fibaro.getGlobalVariable return the value and the timestamp when the variable was changed so json.decode gets the arguments

    Please login or register to see this code.

    Unfortunately, json.decode can take an extra second argument being a table with decoding options. However, now it gets an integer (timestamp) and crashes.

    Wrapping it in parentheses makes it work

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    • Thanks 1
    • 0
  • Inquirer
  • Posted (edited)
    30 minutes ago, jgab said:

    So, computers are rational and relative predictable - so it's usually in one own's code... ;-) 

    This will fail

    Please login or register to see this code.

    The reason is that fibaro.getGlobalVariable return the value and the timestamp when the variable was changed so json.decode gets the arguments

    Please login or register to see this code.

    Unfortunately, json.decode can take an extra second argument being a table with decoding options. However, now it gets an integer (timestamp) and crashes.

    Wrapping it in parentheses makes it work

    Please login or register to see this code.

     

    @jgab so Jan doesn that mean, that every time i do somehing like

    Please login or register to see this code.

    or

    Please login or register to see this code.

    the variables speakers and sensorstate can hold some extra timestemp? Or it goes only for cases when i am redaing a json string and i want to decode it?

    Edited by Neo Andersson
    • 0
    Posted
    10 minutes ago, Neo Andersson said:

    @jgab so Jan doesn that mean, that every time i do somehing like

    Please login or register to see this code.

    or

    Please login or register to see this code.

    the variables speakers and sensorstate can hold some extra timestemp? Or it goes only for cases when i am redaing a json string and i want to decode it?

    No, a variable can only hold one value.

    Functions can return multiple values. 

    So when fibaro.getGlobalVariable(...) returns 2 values they are passed as 2 arguments to json.decode(...)

    However, when you do

    Please login or register to see this code.

    the second value gets dropped, as variables can only hold one value...

    • Like 1
    • 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...