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

Time to give some code back.


Question

Posted

Hi.
I have gotten so much help from this forum and fibaro in learning LUA.
So i though i would give something back that might help others.

I have made a virtual device that stores all states in a room from all Fibaro devices in that room.
And then when you press the "Scene" button their states are restored.

You can also dim all the devices in the room simultaniuisly with 1 common slider.

It perfect for ex a motion sensor scene that you want to change "on the fly"
Just call the "Scene" button in the virtual device instead of having to go in to the HC2 to change the scene.
Or if you are like me and want to change scenes from day to day, just use your phone so save the state you want.

It works with Fibaro relays, Dimmers and RGBW devices.
It stores states and the current color of the LED stripe.

To get it working
1. Create global variables and change the virtual device according to that variable. 
Remember to change the names in all the buttons and the slider.
2. Enter the Room ID you will use in the virtual device in the TCP port field.
-Enter a "room" in your hc2 with your browser and you see the ID in the link
3. Add your user and password in HC2:setBasicAuthentication("admin", "admin") in the "Save" button
4. Save your virtual device after all the changes
5. Set your room to that perfect state
6. Press "Save"
7. Done.

If you add or remove devices from that room you need to press Save again to store the current devices.

It´s only tested with 4.056 due to new Json answers so it will NOT work with 3.6 or lower.

Hope you like it!

 

Edit* New version with more presets.

This is a "test" version for upcoming new version of VD.

 

Current VD device settings:

TCP port = Your room ID
 
3 variables required: (change as you like in code)
LightScene2
LightScene2a
LightScene2b

Please login or register to see this link.

 

Picture

Please login or register to see this attachment.

 

 

*Future:

A new version of this VD is under development 

That VD will be able to.

1. Get the room ID its in.

2. Auto create specific variables based on room ID

3. Auto store presets from all devices.

4. Option to exclude devices from the VD.

 

Will post it here when its done..

 

10 answers to this question

Recommended Posts

  • 0
Guest David R
Posted

speedy,

Thanks.

Please login or register to see this image.

/emoticons/default_laugh.png" alt=":lol:" />

  • 0
Posted

Speedy - only just spotted this.  looks fantastic idea and would love to try it out ...  not seeing the code/file on the post?

  • 0
Posted

Post is almost one year old!

  • 0
Posted

Well spotted - what a clever "guest" - good ideas normally survive a few months.

If this VD lets me save a room's set of devices' state as a "stored scene" - sounds good to me. Fibaro is ok if you want act on specific devices one by one in lua but not so hot at supporting manipulation of lists of devices of certain types ... Unless you use the REST API to build lists of relevant devices - not so straight forward particularly in a scene.

How hard would it be to extend the fibaro: function library to allow query of collections f sections, rooms and devices?

Be good to see the code of the device to see if Speedy had to go via REST api.

Cheers!

  • 0
Guest samuelboerhoop
Posted

Can you post a vfib file from the your virtual device? 

  • 0
  • Inquirer
  • Posted

    Hello. 

    Here is an updated version of the VD with more states.

     

    Look in the first post.

     

    Settings:

    TCP port = Your room ID
     
    3 variables required: (you can change this as you like)
    LightScene2
    LightScene2a
    LightScene2b
     
    Im working on a new VD that is auto config, auto variable config etc but that is some time away.
    I will add it to the forum when I'm finished.

    With that you just import the virtual device and press config.

    After that its all configured.

     

    But for now this is what i have

    Please login or register to see this image.

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

     

    I have edited the info in the original post.

    • 0
  • Inquirer
  • Posted

     

     

     

     

     

     

     

     

     

     

     

    Hello.

    Just updated the post with new VD.

    Hope you find it useful!

    • 0
    Posted

    Great - had been thinking along these lines. Will give it test at w/end. Thanks for sharing

    • 0
    Posted

    All

     

    I finally found an hour or two last night to play with the VD.   Thanks Speedy,  it works well.    I have tweaked and post a refreshed version here.

     

    In this version

     

    Global variables are created if they do not exist using POST - details found on the forum but sorry cannot remember who posted but thanks!

    Please login or register to see this code.

    The variable name is derived from the room the VD is allocated in and the 'scene name'.   These lines added at the top of each scene button and associate save button.  BTW -  I only found out about fibaro:getRoomName(roomID) from UK Fibaro support - I have never seen this documented elsewhere!

    Please login or register to see this code.

    You use in the same way,   import the VD into your room and allocate as normal.  It will work out room ID etc so you no longer need to place that in the TCP PORT on the configuration screen.  Each scene button tries to set the stored scene and reports if not yet configured.   Slider,  all on and all off assume that a 'morning' scene exists and controls all the light devices associated there.

     

    Speedy - thanks for sharing.  Hope this is helpful tweaks for people.   

     

     

     

     

    Please login or register to see this link.

    • 0
  • Inquirer
  • Posted

    AllI finally found an hour or two last night to play with the VD.   Thanks Speedy,  it works well.    I have tweaked and post a refreshed version here.

     

     

    fibaro:getRoomName(roomID) from UK Fibaro support - I have never seen this documented elsewhere!

     

    Glad that is came to use. 

     

    Great updates by the way!

    Can't believe that time flies and i never get enough time to finish the fun stuff.

    Nice that you got it started and have finished it for me

    Please login or register to see this image.

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

     

    RoomName etc is found in the development portal, you can find some nice stuff there. Just register and your in.

    The stupid thing is that i didn't know this command existed so i got all devices and went trough them all in a loop finding the information.

    I only found it when you said that these commands existed and started searching for the command.

    Sometime i will read all information in the portal, that will same me a lot of time!

    Please login or register to see this image.

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

     

    Will post updated VD when i get the time to change it.

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