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

[Question] Change VD Name by LUA/API


Question

Posted

I wonder if there is a way to change the name of VD using LUA or API calls. I see it well documented to change a label but I can not find an example to change the name of the VD. Any example would be helpful! :)

 

16 answers to this question

Recommended Posts

  • 0
Posted

First look http://HC2IP/docs and 

 many other tutorials on forum.fibaro.com

 

1. use API.GET function for take data for VD (ex. vd_section = api.get('/devices/988')["properties"]["rows"] or vd_full = api.get('/devices/988')) depends of your LUA code and method of access and edit vd data.

2. edit name of label for change (ex. edited_data = vd_section.elements[1].caption = 'new text') or edited_data = vd_full.rows[1].elements[1].caption = 'new text')  --for chose correct row and element number look the vd code by .../docs or use code like below (this for button but for label is similar) 

Please login or register to see this code.

 

3. use API.PUT for store new value (ex. return = api.put('/devices/988', edited_data) or simular

But remember for effect you need to refresh web browser or retake all data for HC2 on mobile app.

 

  • 0
  • Inquirer
  • Posted

    @drboss thank you for your answer. I try to change the name of VD by itself and not a label/button that is included on the VD. 

    The reason I need this because I have VDs that are controlled by other applications, so if I change the name of a plug from native application, I like to get the same name on fibaro without change it by hand. 

    • 0
    Posted

    sorry, my mistake. It's night ;-) I read that You have change the name of labels in VD not VD name.

    For change VD name is mach easy. The same method.

    Ex. from any external HTTP REST client use PUT http://HC2IP/api/devices/48 {"name": "Zmywarka"} of course with username and password but from  LUA (any VD) use: 

    pload = api.put('/devices/48', '{"name": "New name"}')

    fibaro:debug(pload)

     

    or

    name = 'new name'

    id = '48'

    pname = '"name":"'..name..'"}'

    pload = api.put('/devices/'..id, pname)

    • Thanks 1
    • 0
  • Inquirer
  • Posted

    @drboss thank you! you make it so simple! I m on learning period so many questions are stupid. Thanks again!

    22 minutes ago, drboss said:

    sorry, my mistake. It's night ;-) I read that You have change the name of labels in VD not VD name.

    For change VD name is mach easy. The same method.

    Ex. from any external HTTP REST client use PUT http://HC2IP/api/devices/48 {"name": "Zmywarka"} of course with username and password but from  LUA (any VD) use: 

    pload = api.put('/devices/48', '{"name": "New name"}')

    fibaro:debug(pload)

     

    or

    name = 'new name'

    id = '48'

    pname = '"name":"'..name..'"}'

    pload = api.put('/devices/'..id, pname)

    I tested but it did not worked :(

    I try to rename the VD that code is included but no change on the name done. No errors returned

    • 0
    Posted

    There's no such thing as a stupid question. 

    , only the answer can be a stupid ;)

    ... we say in Poland 

     

    The forum is for ask and learn for all as. 

     

     

     

    • 0
  • Inquirer
  • Posted
    12 minutes ago, drboss said:

    There's no such thing as a stupid question. 

    , only the answer can be a stupid ;)

    ... we say in Poland 

     

    The forum is for ask and learn for all as. 

     

     

     

     

    you are right! I tried to search answer first but it was not found. Could you please confirm your code? It looks like it did not renamed VD :(

    I also placed on a scene using both methods as below. What I miss? I just want to edit the name of VD, not to create a new one. Also on docs there is no api.put but there is api.post

     

    pload = api.put('/devices/48', '{"name": "New name"}')

    fibaro:debug(pload)

     

    or

    name = 'new name'

    id = '48'

    pname = '"name":"'..name..'"}'

    pload = api.put('/devices/'..id, pname)

    • 0
    Posted

    I will check on my hc2 afternoon. 

    • 0
    Posted

    working code for change name of any device:

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    55 minutes ago, drboss said:

    working code for change name of any device:

    Please login or register to see this code.

     

    tested once again...which version do you have installed? mine is 4.510 and It did not rename VD

    • 0
    Posted (edited)

    i tested on 4.510 but on normal device, it's crease but not work with VD. Interesting I will check in the moment.

    ok I find for VD is another API command for write and read, for read work two, but for write only dedicated. Below code for Virtual Devices, the code before is for Device.

     

    Please login or register to see this code.

     

    Edited by drboss
    • 0
  • Inquirer
  • Posted (edited)

    I also confirm that on a normal device is change name. Still VD do not get this change!!!!

    ---Deleted---

    Someone PLEASE UPDATE LUA/API Documentation!

    Edited by korniza
    • 0
    Posted (edited)

    but with this line work?

    Please login or register to see this code.

    in my test system works fine, the name of VD was changed

    Edited by drboss
    • Thanks 1
    • 0
  • Inquirer
  • Posted
    Just now, drboss said:

    but with this line work?

    Please login or register to see this code.

    Yes Sir!

    it is working....! Where did you find all these api calls?

    2 minutes ago, drboss said:

    but with this line work?

    Please login or register to see this code.

    in my test system works fine, the name of VD was changed

    Yes Sir! It works! Where did you find all these API calls? Official documentation has gaps.

    • 0
    Posted (edited)

    combination of /docs, forum, checking rest command in web browser sending by hc2 web page when I push save bottom and medium knowledge of LUA and JSON ;-)

     

     

    if you have any other questions, write to the forum. I often look here. But there are really many better professionals here who also help.
    I learned a lot here

    Edited by drboss
    • Like 1
    • 0
  • Inquirer
  • Posted

    IMHO it is a way not just to change just names BUT you can add some info on the name of VD according to status (online/offline, enabled/disabled, Off/On, armed/disarmed etc) or even values.

     

    • 0
    Posted

    problem is limit of character in name of VD displayed in mobile app (you need check this). it's no problem 

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