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

Swagger to Scene LUA syntax


Corceiro

Question

I'm trying to learn and do more complex stuff but I've having issues with the correct syntax from Swagger to LUA Scenes.

 

I'm trying to change the Energy Consumption and Production Meters on the Energy Panel through a scene.

 

I'm trying something like:

 

api.put("/energy/settings",{"energyConsumptionMeters": [649] })

 

to make my energy meter device n. 649 a energy consumption meter on the Energy Panel, but I get the error [ERROR] [SCENE220]: (load):1: '}' expected near ':'

 

I tried different syntax and searched a lot on Google, but I'm not familiar with LUA code and can't quite get, yet, how to use the API.

 

Why doesn't it work like the syntax I use to enable and disable some devices on LUA Scene:

 

api.put("/devices/"..653,{enabled=true})
api.put("/devices/"..654,{enabled=false})

 

Shouldn' t it be the same?

 

I was also trying something like

 

api.put("/devices/"..653,{saveToEnergyPanel=true})

 

But it doen't work either...

 

Can someone give me a brief explanation of what I'm doing wrong (or some link or papers were I can learn how to do it)?

 

Thank you very much for your time.

Edited by Corceiro
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 1

api.put("/energy/settings",{energyConsumptionMeters={649}})

  • Thanks 1
Link to comment
Share on other sites

  • 1

saveToEnergyPanel is a property so

api.put("/devices/"..653,{properties={saveToEnergyPanel=true}})

 

  • Like 1
Link to comment
Share on other sites

  • 0
  • Inquirer
  • 4 hours ago, jgab said:

    api.put("/energy/settings",{energyConsumptionMeters={649}})

    Perfect!!! Thank you very much!!!

     

    What if I want to clear that option. In other words, If I don't want any Energy Consumption Meter on the Energy Panel?

     

    I already searched and tried some code lines. Neither of them give any error, but don't work.

     

    I tryed:

     

    api.put("/energy/settings",{energyConsumptionMeters={}})

    api.put("/energy/settings",{energyConsumptionMeters={""}})

    api.put("/energy/settings",{energyConsumptionMeters={0}})

    api.put("/energy/settings",{energyConsumptionMeters={null}})

    api.put("/energy/settings",{energyConsumptionMeters={ }})

    Edited by Corceiro
    Link to comment
    Share on other sites

    • 1

    from a QA this works:

    Please login or register to see this code.

    from a Scene it is another another json encode so you need to bring out the sledge hammer...
     

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 7 hours ago, jgab said:

    from a Scene it is another another json encode so you need to bring out the sledge hammer...
     

    Please login or register to see this code.

     

    It worked! Thank you very much! I still don't quite understand the syntax, but getting there with this examples.

     

    Thank you very much @jgab. Hava a wonderful weekend!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Good morning @jgab.

    If I may ask, where do you find the documentation to keep you up to date with Fibaro coding?

    Things like function(e) are Fibaro exclusive syntax coding or ir general LUA coding?

    I wanted to learn a lot more (only for personal amusement and entertainment myself) but, beside this Forum, I'm struggling to find papers or books where I can explore self-learning.

    I'm also exploring YAML with Home Assistant (HA) and found that HA as a very good documentation site, but can't say the same about Fibaro (or I still didn't find it).

    Link to comment
    Share on other sites

    • 0
    5 hours ago, Corceiro said:

    Good morning @jgab.

    If I may ask, where do you find the documentation to keep you up to date with Fibaro coding?

    Things like function(e) are Fibaro exclusive syntax coding or ir general LUA coding?

    I wanted to learn a lot more (only for personal amusement and entertainment myself) but, beside this Forum, I'm struggling to find papers or books where I can explore self-learning.

    I'm also exploring YAML with Home Assistant (HA) and found that HA as a very good documentation site, but can't say the same about Fibaro (or I still didn't find it).

    It's mainly standard Lua, where Fibaro actually removed some standard feature like coroutines and metatables for no good reason and other like os.system() for security reasons.

    Then Fibaro has added a couple of Lua libraries they developed themselves , like the fibaro.* , the QuickApp:* functions, and added some like the net.* and json.*

    Scenes has that home made trigger model that filter events before invoking your scene code...

     

    Fibaro has always been slow to evolve the Lua framework and document it. That's why you see a much more features and a more vibrant developer community for HASS etc... which is a real pitty.

     

    Edited by jgab
    • Like 1
    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...