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

Question

Posted (edited)

I want to use a construction in my hometable like for example

 

local HT = { light1 = { fib_id = 211, hue_id = 7  },
                     light2 = { fib_id = 227, hue_id = 12 },
                   }
HT.ftoh  = { [ HT.light1.fib_id ] = HT.light1.hue_id,
                    [ HT.light2.fib_id ] = HT.light2.hue_id,
                   }

 

When i test fibaro:debug( HT.ftoh[ 227 ] ) it gives the expected value 12.

 

I want to use this in a couple of VD's with generic code for hue lights, but when i test local HT2 = fibaro.decode( fibaro.encode( HT ) ) then
fibaro:debug( HT2.ftoh[ 227 ] ) gives un expected NIL result.

 

fibaro:debug( HT2.ftoh[ "227" ] ) does give the correct result 12 so the original key index 227 is now a string.

 

Is this normal behaviour of the json.encode / json.decode functions or is this a bug ?

Edited by Alex de Bruin
Changed : to .

Recommended Posts

  • 0
Posted

I am sorry, I posted before I had my coffee. I looked at your code but focused on the pcall. Anyway, that should give us some feedback because this code is very hard to test without owning the hardware.

  • 0
Posted
On 3/29/2021 at 9:42 AM, jgab said:

In my version of his code that I attached I have added the error handlers also :-)

 

waow.... what can i say except so impressed and thanks !

haven't been able to get connnecteed those last days due to work, and now that i'm back i've treasure of options to test and to fix my isssue.

A very warm thank for all of you @jgab and @petergebruers

will test all this soon and will let you know very soon :)

thanks a lot ! so  much appreciated.

 

  • 0
Posted
On 3/29/2021 at 9:42 AM, jgab said:

In my version of his code that I attached I have added the error handlers also :-)

 

Thanks @jgab and @petergebruers for your time and attention.

I've tried to integrate your ideas, proposals and best practices... always good to improve the code. Thanks @jgab for the string:norm() approach... very helpful.

Unfortunately, results is the same and saving data to global variable remains at an average of 30 seconds at the end.

I should have mentionned this before but i do not get any error message, including from http request, now integrating error message return (but none ;))

My return of debug are perfect also, well showing me, room per room the list of attached scenes (not in order now that i ve changed numeric ID to string to see if potentyially creating an error in table structure.

 

Would it help if sharing 1. Debug return 2. Other Global Variable details for simulation or anything else?

 

Reason why i nested functions was that i was wondering if one process was starting before the other correctly end, being in a asynchronous situation but guess i go to far :)

(@jgab you were the one who teach me and learn  me how to get out of asynchroneous situation by nesting next action in success and really help me in various situation ... but not this one truly)

 

thanks a lot for your attention and support

 

 

 

 

 

 

 

  • 0
Posted (edited)

@jgab & @petergebruers

 

hello guys, still trying to find the answer to my issue and just made an interesting test:

instead of all my code, i directly code an http:request to hue Bridge to get the rough scenes list

i decode it into a local variable and set this local variable into a global one.

 

Globally, same thing i'm doing above, except i don't add any information to the basic hue dataset just store it as below in Global Variable

Result: 24 seconds between step 2 (ask to set globalvariable) and step 3 (done) ! 

 

could it be hue data set that would be non consistent or "dirty" ?

below the simple code i tested. Is it also taking 20 sec or so for you?

 

 

Please login or register to see this code.

 

Edited by Mateo
  • 0
Posted

and when i then reset the Global variable in doing a 

fibaro.setGlobalVariable("hueGroupDetails", "0")  

it takes about 12 seconds to do it when immediatly following the code above.

 

if executing the code again, it's then done at the speed of the light.

> once the global variable is written with potentially an issue in, replacing the content by a simple 0 takes 12 seconds!

 

don't know if it helps understanding

 

  • 0
Posted
19 hours ago, Mateo said:

 

Thanks @jgab and @petergebruers for your time and attention.

I've tried to integrate your ideas, proposals and best practices... always good to improve the code. Thanks @jgab for the string:norm() approach... very helpful.

Unfortunately, results is the same and saving data to global variable remains at an average of 30 seconds at the end.

I should have mentionned this before but i do not get any error message, including from http request, now integrating error message return (but none ;))

My return of debug are perfect also, well showing me, room per room the list of attached scenes (not in order now that i ve changed numeric ID to string to see if potentyially creating an error in table structure.

 

Would it help if sharing 1. Debug return 2. Other Global Variable details for simulation or anything else?

 

Reason why i nested functions was that i was wondering if one process was starting before the other correctly end, being in a asynchronous situation but guess i go to far :)

(@jgab you were the one who teach me and learn  me how to get out of asynchroneous situation by nesting next action in success and really help me in various situation ... but not this one truly)

 

thanks a lot for your attention and support

 

 

hello :)

Some news of the day, not quitting the thing....

suspecting the hue data set could in one way or the other "corrupt" the table, generating the issue in set it in Global Variable, I quit associating the whole dataset and juist extract from it the sole data i was needing, one by one.

Not working either, still 30 secondes.

 

I'm now suspecting that in one way or the other, i'm mixing somewhere mixed or invalid key types.

Do you think it can be an idea to follow?

 

Except this 30 seconds delay, the resulting global variable is correct (see below) and I can get it without iossue in a sec from other scene

Just setting in global variable takes 30 secs...

 

All ideas welcome :)

have a great easter week end

 

 

Please login or register to see this code.

 

  • 0
Posted

browser and fibaro interface reacts very strangely... the different returns i get are not consistent and really not convince me that the issue is in the code actually

may it be an "encode" issue ? a bad memory management from the box...

by the way, remind me i'm using 5.040 and read some where there was memory issue with

 

will check if any new update, apply and advise

 

  • 0
Posted

The trouble is I cannot test this in any way but I only can come up with these idea's

- Iiirc someone said a HUE bridge can (only) handle 4 connections at the same time. If you have running things in parallel maybe you exceed this limit which maybe causes delays. That's a lot of "maybes", I know...

- There is a way to shoot yourself in the foot in a FQA but I forget the exact circumstances. But is it something along these lines: post some change (eg simulate a button push) and also handle that in the FQA. So to speak, "call yourself" in an FQA... This leads to a 5 second timeout each time to do this. It was discussed briefly in one of @jgab's (long) threads but I cannot remember the magic words to find it.

 

AFAIK neither Lua, nor JSON, nor get or set global are "slow enough" with any kind of real world data to cause a 30 s delay.

 

1 hour ago, Mateo said:

5.040 and read some where there was memory issue with

It is possible that older version has got something to do with it.

 

I get very positive feedback from users that had delays, who are now on 5.070, I think memory usage is pretty much controlled now.

  • 0
Posted

just finished the fibaro hc3 update...

 

it solves all the issues at once...

i ve even included now lights data into the global variable, 

everything runs in less than 1 second !

 

what else to say?

big thanks to all and happy easter

  • 0
Posted
On 4/3/2021 at 7:15 PM, Mateo said:

just finished the fibaro hc3 update...

 

it solves all the issues at once...

i ve even included now lights data into the global variable, 

everything runs in less than 1 second !

 

what else to say?

big thanks to all and happy easter

 

 

 

hello @jgab and @petergebruers and all

 

may i request one more time some of your time ...

i'm finally not out of the issue. everything looks working fine BUT when trying to use contents of my global variable in another scene, when trying to json.decode the variable i get this:

 

[ERROR] [SCENE149]: /opt/fibaro/lua_engine/lua/lib/json.lua:185: unexpected character '' at line 1 col 1

 

what does it mean  ? how solving this?

i don't understand the message and don't find related contents

 

thanks in advance for any suggestion :)

 

  • 0
Posted
1 hour ago, Mateo said:

 

 

 

hello @jgab and @petergebruers and all

 

may i request one more time some of your time ...

i'm finally not out of the issue. everything looks working fine BUT when trying to use contents of my global variable in another scene, when trying to json.decode the variable i get this:

 

[ERROR] [SCENE149]: /opt/fibaro/lua_engine/lua/lib/json.lua:185: unexpected character '' at line 1 col 1

 

what does it mean  ? how solving this?

i don't understand the message and don't find related contents

 

thanks in advance for any suggestion :)

 

What is the content of the variable? (the string)

  • 0
Posted

was a synthax error in the variable name

why not saying it was not existing instead of this message, don't know ... b t solved :)

2 minutes ago, jgab said:

What is the content of the variable? (the string)

 

just found the answer ... a stupid error from me in the name which strangely returns this error where it could have just says that the GV was not existing ;)

was not confident enough in  my JSON table after those last days issues ...

thanks for your attention @jgab

take care

 

  • 0
Posted
10 hours ago, Mateo said:

was a synthax error in the variable name

why not saying it was not existing instead of this message, don't know ... b t solved :)

 

just found the answer ... a stupid error from me in the name which strangely returns this error where it could have just says that the GV was not existing ;)

was not confident enough in  my JSON table after those last days issues ...

thanks for your attention @jgab

take care

 

Well, a nonexistent GV will return "" (empty string) and json.decode('') complain that the first character it looked for was no character.

This is actually another reason for QuickApp:getVariable and fibaro.getGlobalVariable should return nil if the variable doesn't exists, instead of the "perceived" helpfulness of returning an empty string.

json.decode(nil) tells us "...expected argument of type string, got nil"

 

Btw,  correction to statement above; fibaro.getGlobalVariable for nonexistent variable in a scene returns "", in a QA it return nil. Go figure...

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...