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

HC3 fibaro.setGlobalVariable ERROR


Question

Posted

Hi there

 

I’m struggling to convert some basic code from HC2 to HC3

 

The following code works on HC2

 

--calls json table and decodes

local decoded_light_settings = json.decode(fibaro.getGlobalVariable("g_light_set"))

print("after decode json file")

 

--STEP 2 gets the relevant json table settings from the decoded table

local ref_1 = (decoded_light_settings.al_7.c) 

print(ref_1)

fibaro.setGlobalVariable("g_al_warm", ref_1)

 

But I get this message on HC3 debugger

 

[11.11.2021] [17:39:28] [DEBUG] [SCENE18]: at top

[11.11.2021] [17:39:28] [DEBUG] [SCENE18]: after decode json file

[11.11.2021] [17:39:28] [DEBUG] [SCENE18]: 1

[11.11.2021] [17:39:28] [ERROR] [SCENE18]: (load):11: Assertion failed: Expected string

 

The error line is for the last line of the code .... fibaro.setGlobalVariable("g_al_warm", ref_1)

 

I’ve changed the syntax to what I think is correct but can’t get it to work.

I've set up the global variable with an initial value 0

 

Any help much appreciated

5 answers to this question

Recommended Posts

  • 0
Posted

it seems your variable contains more than just a string.. what is the decoded result?

  • 0
Posted

Yes, the ref_1 needs to be a string, now it's seems to be a number.

I believe that the HC2 did an implicit tostring on values to setGlobal

  • 0
  • Inquirer
  • Posted

    Many thanks @symbiot78 & @jgab 

     

    tostring did the job. All working now :)

     

    • 0
    Posted

    Hi

     

    On HC3

    I would like to get the lux value it is a number from motion sensor and add to global variable int_Lux  but I got an errro message:" Assertion failed: Expected string"

    local value = fibaro.getValue(32, "value") -- get lux value
    fibaro.setGlobalVariable("int_Lux",value)

     

    Can you help me?

    • 0
    Posted
    11 hours ago, iTibor said:

    Hi

     

    On HC3

    I would like to get the lux value it is a number from motion sensor and add to global variable int_Lux  but I got an errro message:" Assertion failed: Expected string"

    local value = fibaro.getValue(32, "value") -- get lux value
    fibaro.setGlobalVariable("int_Lux",value)

     

    Can you help me?

    Try that

    fibaro.setGlobalVariable("int_Lux",tostring(fibaro.getValue(32, "value")))

     

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