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 data file syntax


Rosavision

Question

I’m using decoded JSON data tables to set global variables so that lighting scenes set different light ambience during the day / evening. 

 

The following line works OK but its clumsy to change the references numbers in the decode string for each code line

 

Instead of this

decoded_light_settings.rgbw_4.r

 

I’d like to do this

 

Ref=4

decoded_light_settings.rgbw_(ref).r

 

but I can’t figure out the correct syntax

 

 

The complete code I’m using is….

 

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

 

local ref=

{decoded_light_settings.al_4.c, decoded_light_settings.al_4.w, decoded_light_settings.rgbw_4.r, decoded_light_settings.rgbw_4.g, decoded_light_settings.rgbw_4.b, decoded_light_settings.rgbw_4.w, decoded_light_settings.rgb_4.r, decoded_light_settings.rgb_4.g, decoded_light_settings.rgb_4.b, decoded_light_settings.rgb_4.w, decoded_light_settings.sl_4.sl,}

local g= 

{"g_al_cold", "g_al_warm", "g_rgbw_red", "g_rgbw_green", "g_rgbw_blue", "g_rgbw_white", "g_rgb_red", "g_rgb_green", "g_rgb_blue", "g_rgb_white","g_sl"}

 

if#g>0 then

for i = 1,#g do

--fibaro.call(g[i])

fibaro.setGlobalVariable(g[i], tostring(ref[i]))

 

end

end

 

Any help much appreciated

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0
20 minutes ago, Rosavision said:

I’m using decoded JSON data tables to set global variables so that lighting scenes set different light ambience during the day / evening. 

 

The following line works OK but its clumsy to change the references numbers in the decode string for each code line

 

Instead of this

decoded_light_settings.rgbw_4.r

 

I’d like to do this

 

Ref=4

decoded_light_settings.rgbw_(ref).r


ref=4

decoded_light_settings[”rgbw_”..ref].r

Link to comment
Share on other sites

  • 1
1 hour ago, Rosavision said:

Hi @jgab I've run into another syntax challenge which after a few hours I need help !

 

Instead of this

 

num=4

decoded_light_settings[”rgbw_”..num].r

 

I'd like to do this

 

num=4

ref="r"

decoded_light_settings[”rgbw_”..num].[ref]

 

The following throws an error  [ERROR] [SCENE27]: (load):15: expected near '['

 

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

--local rgbw

--local bob

local rgbw={"re","gr","bl","wh"}

 local ref={"r","g","b","w"}

 num=6

 

if#rgbw>0 then

for i = 1,#rgbw do

 

fibaro.setSceneVariable(rgbw[i],decoded_light_settings["rgbw_"..num].[ref[i])

 

end

end

 

 

If I can figure this out I can get rid of a whole load of code and a bunch of global variables.

 

Can you see what I'm doing wrong? Thanks in advance for any help you can give me

 

No '.' between the indexes.

If

decoded_light_settings = { rgbw_1 = { r = '*1', g = '*2', b = '*3', w = '*4'} }  

then

decoded_light_settings["rgbw_1"]["g"] 

is equal to '*2'

 

Link to comment
Share on other sites

  • 0

edit: 

Please login or register to see this link.

 

Please login or register to see this link.

 
has better solution... :-)

 

Edited by gbbsoft
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi @jgab I've run into another syntax challenge which after a few hours I need help !

     

    Instead of this

     

    num=4

    decoded_light_settings[”rgbw_”..num].r

     

    I'd like to do this

     

    num=4

    ref="r"

    decoded_light_settings[”rgbw_”..num].[ref]

     

    The following throws an error  [ERROR] [SCENE27]: (load):15: expected near '['

     

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

    --local rgbw

    --local bob

    local rgbw={"re","gr","bl","wh"}

     local ref={"r","g","b","w"}

     num=6

     

    if#rgbw>0 then

    for i = 1,#rgbw do

     

    fibaro.setSceneVariable(rgbw[i],decoded_light_settings["rgbw_"..num].[ref[i])

     

    end

    end

     

     

    If I can figure this out I can get rid of a whole load of code and a bunch of global variables.

     

    Can you see what I'm doing wrong? Thanks in advance for any help you can give me

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi again @jgab, I've beed reading your QuickApps coding guide for inspiration and have tried a few more things

     

    I get rid of the ERROR with this

     

    fibaro.setSceneVariable(rgbw[i],decoded_light_settings["rgbw_"..num.."."..ref[i]])

     

    But when I debug

     

    fibaro.debug("TestTag","rgbw red =",fibaro.getSceneVariable("re"))

     

    I get 

     

    [DEBUG] [TESTTAG]: rgbw red =

     

    However when I use this

     

    fibaro.setSceneVariable(rgbw[i],decoded_light_settings["rgbw_"..num].r)

     

    The debug gives me this

     

    [DEBUG] [TESTTAG]: rgbw red = 180

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thank you @jgab

     

    One "." has taken me all evening to fix, now it works like a charm :)

     

    Thanks you again sir

    Link to comment
    Share on other sites

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