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

Get IP of virtual device (or Scene?)


StarkJohan

Question

How do I use/get the ip from the ip-field of a virtual device in the LUA of the buttons?

Seems this would be the only use of that field so it has to be possible.

Edit:

fibaro:getSelfId() works very well with virtual devices, but how can we do to get the ID of a Scene?

Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0

Try this function:

Please login or register to see this code.

This works in mainLoop.

Link to comment
Share on other sites

  • 0
  • Inquirer
  • I thought there would be an easier method, what is otherwise the deal with entering the IP of the virtual device as if it was important, right below name and room?

    I'm fresh out of the fog on LUA so I'm having problems using your nice function. Trying to call it without any variables gets me this: (this is the "tcp = Net.FHttp("localhost", 80);" line)

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    Where did you put that code? Becouse "Net." class is available only in virtual devices. You have to put the code to main loop in virtual device.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Oh OK, this test was with a scene. Explains the error.

    I have the code in the main loop and tried to do a simple with a button:

    Please login or register to see this code.

    but this results in:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
    Oh OK, this test was with a scene. Explains the error.

    I have the code in the main loop and tried to do a simple with a button:

    Please login or register to see this code.

    but this results in:

    Please login or register to see this code.

    Try this:

    Please login or register to see this code.

    Also check login and password inside function.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Cool, this work well in the main loop but if I do the same in the button code:

    Please login or register to see this code.

    i get this:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    you could put the function in each button you want to check from

    I just hard code just now

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I like elegant solutions. Putting the whole function in beach button isn't exactly elegant

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Is the problem that you can't access main loop functions from the buttons?

    Link to comment
    Share on other sites

    • 0

    Know what you mean but setmetatable function and environment table is blocked so you have no global functions or variables.

    Link to comment
    Share on other sites

    • 0
    I like elegant solutions. Putting the whole function in beach button isn't exactly elegant

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Is the problem that you can't access main loop functions from the buttons?

    I'm also don't like situation with mess in my virtual devices

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    There is sollution for that. But you have to write more code in main loop.

    Here:

    Please login or register to see this link.

    is the script, where I made the all functionality in main loop - witchout any extra code in buttons. Short description:

    1. On buttons you can put only some information, like action: KEY_PRESS=PAUSE.

    2. The mainloop can read that information and run action if user (or scene) pressed the button. But, for that you need some extra solution...

    3. For detect pressing button you can not use standandard api from fibaro - there is no any function for that. I'm using for that icons functionality. Each button has assigned (by script in mainloop) separate icon (non existed icon - only virtual id of icon), soo if button was pressed, then I can read the id of button by read id of icon assigned to that button and compare with main id icon

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Summary: This is no easy way, but give us possibility to have code only in mainloop.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • This is so strange. Putting the function in BOTH main and button makes it work. Any other way and I get the above errors. How can this be?

    Keeping all the code in the main loop would be neat but that will give me even more code. All I am looking for is a simple line and it should be possible. Can anyone think of any other reason to enter the IP in the main fields of the device?

    Wouldn't such a use be nice and completely logical:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    I think there are such functions:

    As you can read

    Please login or register to see this link.

    , IPAddress and TCPPort are properties of any virtual device, so you can get both with:

    Please login or register to see this code.

    I only miss a property that return its own device id, so you could write 100% portable virtual devices. Something like this:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Awesome, this saves a lot of code.

    Still not getting the info dynamically (i.e. THIS device) but at least it's a lot neater.

    Did you find documentation on this? Name and icon would be nice to be able to get as well.

    Edit: Exactly, this-function would be the best, I've posted a feature request and it's been assigned som possible we'll see this in the future.

    Link to comment
    Share on other sites

    • 0

    ortegaga, you could use fibaro:getSelfId() to get current device ID

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Krikroff, awesome! That solves the problem.

    Is there any documentation on getSelfId() anywhere? Maybe there's similar functions for port, ip and so on in the newer versions?

    [ Added: 2014-02-04, 07:38 ]

    Would it be possible to get the ID of a scene in a similar way? Krikroff's example works fine with virtual devices but not scenes.

    Any suggestions?

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