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


How to decode Json / Lua in Variable


Recommended Posts

Posted

Hello, i have a question.

how can i write result from a JSON in a Fibaro Variables

 

This code works but i don't Know how i can write into Variables 

can anybody help many thanks

 

Please login or register to see this code.

 

 

and here the resalt

 

[DEBUG] 17:21:36: ["80s 90s stuff","miro","SIA","Top Hits Deutschland"]
 

 

 

Posted

you have two command for working with json on HC2:

json.decode()

json.encode()

 

in your example

Please login or register to see this code.

the result for 'b[1]' is:
80s 90s stuff

b[2] is:

miro

...

 

 

 

 

 

  • Topic Author
  • Posted

    Hi Thank,

    but in your post  "a" is a fix variable.. how can i  write my "Call" into "a"

     

    thanks

     

    Markus 

  • Topic Author
  • Posted (edited)

    Please login or register to see this code.

    well i  check this but now i have another Problem..

     

    in the JSON file the field "integrations" sometimes not exist so the lua Code went into an ERROR... how can i handle this

     

     

     

    can you please help

     

    Edited by hoschi_66
    Posted

    Please login or register to see this code.

     

    Hope it helps

    Enjoy coding :-)

  • Topic Author
  • Posted
    On 3/2/2020 at 9:46 PM, Sankotronic said:

    Please login or register to see this code.

     

    Hope it helps

    Enjoy coding :-)

     

     

    nice many thanks  it works !!! and it is so easy :-) sometimes in Germany we Say " man sieht den Wald vor lauter Bäume nicht !"  now i can testing with Owntracks :-)

    • 4 years later...
    Posted

    Hi.
    I want to make a global variable that contains the current stock price for electricity. I get a json string. I'm converting it to a Lua table. And for some reason I get zero. What am I doing wrong?

     

    hub.getGlobalVariable("EnergyPrice")
    local url = "https://dashboard.elering.ee/api/nps/price/EE/current"
     
    net.HTTPClient():request(url, {
        options={
            method = 'GET',
            headers = {
                ["Content-Type"] = "application/json"
            },
            timeout = 5000
        },
        success = function(response)
            EnergyPrice = json.decode(response.data) 
            hub.debug("EleringPrice", response.data, EnergyPrice.price)
            
        end,
        error = function(errorMessage)
            hub.debug("EleringPrice""HTTPClient error" .. errorMessage)
        end
    })

    Please login or register to see this attachment.

    Posted

    Just try this one:

    Please login or register to see this code.

     

    Posted
    On 5/1/2024 at 7:22 PM, Sankotronic said:

    Just try this one:

    Please login or register to see this code.

     

    Unfortunately it doesn't work

    Please login or register to see this attachment.

    Posted

    Hi @Eldar.D. ,

     

    Try then:

    Please login or register to see this code.

     

    Posted
    6 hours ago, Sankotronic said:

    Hi @Eldar.D. ,

     

    Try then:

    Please login or register to see this code.

     

    Thanks, it's working.

    Join the conversation

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

    Guest
    Reply to this topic...

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