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

Load a data from json into a fibaro global variable


Question

Posted

Hello

 

I'm trying to do a virtual devise with load a json data with the current date. I'm currently stuck with LUA programming, If you could help me , it would be nice.


www.mysite.com/json/data.json
is looking like this

Please login or register to see this code.


 

Please login or register to see this code.

 

What I'm trying to do is in theory quite simple.

I do read my json

with the current date, I try to see if I can get a value for the date in my json,
if yes, I do set the Variable in Fibaro named "Today" with the value of my json.

 

Thanks a lot

Christophe

4 answers to this question

Recommended Posts

  • 0
Posted (edited)

Please login or register to see this code.

 

Edited by jgab
  • 0
  • Inquirer
  • Posted

    Thanks a lot for your code.

     

    I did try It, it is working when I manually define

    Please login or register to see this code.

     

    but if I do take res from

    res = HC2:GET("/ical/test.json") with the same content, it is not working anymore, it says

    [DEBUG] 14:54:41: { d20200201="A", d20200204="A", d20200128="B", d20200207="C"}
    [DEBUG] 14:54:41: Value for d20200128 not found

     

    it looks like it does not recognise the type of the array anymore. Any idea why ?

     

    • 0
    Posted
    5 minutes ago, pixys said:

    Thanks a lot for your code.

     

    I did try It, it is working when I manually define

    Please login or register to see this code.

     

    but if I do take res from

    res = HC2:GET("/ical/test.json") with the same content, it is not working anymore, it says

    [DEBUG] 14:54:41: { d20200201="A", d20200204="A", d20200128="B", d20200207="C"}
    [DEBUG] 14:54:41: Value for d20200128 not found

     

    it looks like it does not recognise the type of the array anymore. Any idea why ?

     

     

    res = json.decode(HC2:GET("/ical/test.json"))

    • 0
  • Inquirer
  • Posted

    Thanks you so much

     

    After checks when you load it from json without the decode, it is a string

    the json.decode convert the json to an array

     

    In order to work I had to

     

    response = HC2:GET("/json/myjson.json")
    response = json.decode(response)

     

    change my file from

    Please login or register to see this code.

     

    to

    Please login or register to see this code.

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