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

Cannot create enum Global variable via LUA


Question

Posted

Hello,

I use creating new global variables via virtual device and LUA. But now I need to create enum global variable, and it works not for me.

 

My tests:

1- I create enum GV with states 1,2,3

2-on response I get

response=HC2:GET("/api/globalVariables/test")

 

Please login or register to see this code.

3-Now I need to create new GV with new name, but same response

Please login or register to see this code.

There must be changed isEnum parameter to 1 (from true)

Now is new GV created, it is enum, but with no states, its only empty!

Same json works at docs well, but not at LUA code. This json at docs PUT /globalVariables/{globalVariableID} modified GV to enum with states:

Please login or register to see this code.

 

Why LUA code doesn't create states as well as docs API? How is well syntax for parameter enumValues?

Thank you very much

Martin

7 answers to this question

Recommended Posts

  • 1
Posted (edited)

@cag014 @marbe correct, it is a two step  process.

 

Here's an example. First I test if the variable exists. If not, create the variable. Then I change it to accept a few predefined values. In the next line, I change that list of values.

 

Can you please click on the spoiler ("Reveal hidden contents")  and try to run this scene?

 

Please login or register to see this spoiler.

 

Edited by petergebruers
  • 0
Posted

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

  • 0
  • Inquirer
  • Posted

    Hello FIBARO,

    thank you for moving to other content. Can you help me wit my issue?

    Thank you

    • 0
    Posted

    Could you post the LUA code?

    • 0
  • Inquirer
  • Posted

    Yes, is very simple only for testing purpose.

    Code

    Please login or register to see this code.

     

    Result

    [DEBUG] 23:17:37: {"name":"test","value":"3","readOnly":false,"isEnum":true,"enumValues":["1","2","3"],"created":1535018929,"modified":1535018929}   -existing enum global variable with states 1,2,3
    [DEBUG] 23:17:37: {"name":"new","value":"3","readOnly":false,"isEnum":true,"enumValues":[],"created":1535059057,"modified":1535059057} - new variable with same json, only with name and isEnum parameter changed. Result - enum states are empty
    [DEBUG] 23:17:37: 201
    [DEBUG] 23:17:37: 0

    • 0
    Posted (edited)

    As far as I know you can not create new variable, but you can change/modify exist variable.

    Just  exactly what you did in docs, I believe you have specified {globalVariableID}  as test... right?

    In your code {globalVariableID} not specified.

    Just an idea... have monitored how new variable created using UI. It was done by two steps:

    Step 1:

    PUT http://hc2/api/globalVariables/new

    Where request body is:

    {"name":"new","value":"Value 1","isEnum":true,"enumValues":["Value 1","Value 2"]}

    status response 200

    Step 2:

    POST http://hc2/api/globalVariables

    Request body is:

    {"name":"new","value":"Value 1"}

    status response 201

    Please try it... and let me know if it works...

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    Hi,

    yes, this procedure works, thank you!

    Important is:

    • first create new variable, but without isEnum parameter
    • seconds set isEnum and enumValues

    I tried create new variable with enum parameter true, and this is not possible.

     

    My working testing code

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