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

JSON POST http request


Cafun

Question

Hi community!

I was hoping someone can help me out with something.

 

So, I got

Please login or register to see this link.

to open/close my curtains.

They've got an OpenAPI. At this moment there is no integration Fibaro (but they say it will be). I also do have Home Assistant and with that I can control my curtains.

I know it's not ideal, but I would like to use the Home Assistant API to open/close my curtains. So when I press a button on a Zwave remote, it opens/closes my curtains.

 

I don''t have any knowledge about JSON and http requests into Lua. I have the code below, but it doesn't work (I didn't expected to ;-)).

At this moment it I get the error: 

[ERROR] 07:22:13: line 3: '' expected near '" "'

But I don't think it's the only thing which isn't right.

They payload I defined should be in the body.

 

Please login or register to see this code.

Link to comment
Share on other sites

Recommended Posts

  • 0

Hi @Cafun,

 

not really an answer to your question, but I'm working already on integration of Slide, but it's delayed a bit because my Slide is currently @ IIM to be revised/repaired, but i hope to continue soon with testing and will share it soon here as well to IIM so they can provide it on their support site :-)

See below attached screenshot of Slide VD:

image.png.5fcb2efe36b6e2c61289751eb09a0422.png

 

As soon as i receive my Slide back (hopefully this week) I will continue development and testing, so i hope to finish it very soon. :-D

 

Edited by Bodyart
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Ah cool! Thanks for the response! Hopefully you can soon continue with testing. If you want me to test anything, I will be happy to.

     

    In the mean time, I hope someone can help me with the problem.

    Link to comment
    Share on other sites

    • 0

    I'm not sure if I can help you, but

    try ' instead of " at the beginning and the end; then a " inside is handled as a real character

    I suppose ...= '{ entity_id: "cover.raam_voor" }'

     

    have a look at 

    Please login or register to see this link.

      , too

    good luck!

    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi muc, thank you for your reply.

    I would try your suggestion, but it appears I'm stuck at row 1:

     

    [ERROR] 09:05:43: line 1: attempt to index global 'net' (a nil value)

     

    I'll dig a little deeper.

    If anyone has suggestions, I'm open to it.

    Thanks.

     

    Edit:

    I guess it needs to be a scene instead of a virtual device to call the 'net.HTTPClient()' command.

    But now I get the following error:

     

    [DEBUG] 11:05:52: 2019-12-15 11:05:52.306106 [ fatal] Unknown exception: /opt/fibaro/scenes/262.lua:21: attempt to index global 'ltn12' (a nil value)

     

    I'm going to lookup some other examples, hopefully I get it working.

     

    @Bodyart

    I hope you've got your slide back already?

    Edited by Cafun
    Link to comment
    Share on other sites

    • 0
    2 hours ago, Cafun said:

    @Bodyart

    I hope you've got your slide back already?

    Hi @Cafun,

    yes it came on Friday, but currently there is something wrong with the API, so i didn't make much progress and will contact the "Slide guys" on monday to solve the issue..

    Link to comment
    Share on other sites

    • 0

    @Bodyart It's great to hear that you are working on integration. Will the end result still be a VD? If so, I'll need to find a voice control work around.

    Link to comment
    Share on other sites

    • 0
    1 hour ago, Blackdog65 said:

    @Bodyart It's great to hear that you are working on integration. Will the end result still be a VD? If so, I'll need to find a voice control work around.

    Hi @Blackdog65,

    it will be 1 VD per Slide with one scene for all Slides.
    Just solved a nasty bug with help of @Sankotronic, so i hope to finish it soon (January)

    :-D

     

    Edited by Bodyart
    Link to comment
    Share on other sites

    • 0
    3 minutes ago, Cafun said:

    Nice! Can't wait to integrate it in Fibaro

    Hi @Cafun,

     

    i'm doing my best :-D

    Link to comment
    Share on other sites

    • 0

    Hi @Cafun,

     

    if you want to do something with JSON in LUA/Fibaro you need to use the json.encode/json.decode libraries in LUA. What you can typically do is already list your datamodel in JSON (see authData below) so you can make it visual for yourself what your data will look like and how you can access it. Especially with multi dimension tables it helps to visualise how you can call your data, e.g. below you will have tables in tables ('slides' is a table, but the entry 'slide1' is also a table). So you have tables within tables and by visualising this upfront it helps you in your encoding/decoding endeavours 

    Please login or register to see this code.

     

    Since I was looking into

    Please login or register to see this link.

    as well hereby a snippet of a way in which I'm able to get a Token (and do other calls to their platform using that token).  I've included a small loop that shows you how you can access data in a table. The call towards the slide api contains JSON encode data (username and password) and since the data you'll get back is also a JSON it also includes a way to read the JSON response by decoding it.

    Please login or register to see this code.

    Hopes this helps to get JSON up and running in LUA!

     

     

    Edited by gabordewit
    Adjusted code snippet
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @gabordewit I have downloaded the scene/vib from your github. When I want to initialize the slides I get the error below. Hope you can help me with this:

    [DEBUG] 09:37:56: 2020-03-06 09:37:56.774388 [ fatal] Unknown exception: /opt/fibaro/scenes/264.lua:54: '=' expected near ','

    Edited by Cafun
    Link to comment
    Share on other sites

    • 0

    @Cafun  Can you paste your scene block here so I can have a look at the line that is giving the error?

     

    You did make me realise I had a function in there called debuglogger that i've just replace for fibaro:debug (editted above), however if I run the code standalone now in a scene it seems to reply from the SLIDE API.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I've used the code and virtual device from your github. Here is my scene:

     

    Please login or register to see this code.

    Edited by Cafun
    Link to comment
    Share on other sites

    • 0

    @Cafun Apologies for not getting back sooner.

     

    The reason why line 54 is generating an error is due to the fact that code that should be commented out is actually visible (see red below):

    Please login or register to see this code.

    If you change the red to --[[ or put slides = {} (and remove everything that is now in between the { } under slides you should be good to go. I've updated the api itself a bit recently, there is now also a 1.0.1 available.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Oh damn, I didn't got a notification you replied! I'll try it. Thanks!

    And where can I find the 1.0.1? It's not on your github?

     

    Edit: It works! Thanks, Now I can do some detailed programming for the curtains :-) (normally I let it open and close at sunrise and sunset, but now that's not sufficient anymore).

    If I can get your updated code, I would be happy to.

    Edited by Cafun
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • It's working great, thank you!

    Are you still developing some things for it? Just curious :-)

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