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

Read thé device status


Question

Posted

I have hue lichts on my fibaro. I would like toch make a virtual device where i make more lights go on of of whit one button.

 

How can i read thé light out if it is in or off?

 

Check if the light is on

If it's on turn it of

If it's not on turn it on.

 

How do it say that in lua code (fibaro:call(42, "turnOn"))

 

thank you Gerry lucht for thé help

15 answers to this question

Recommended Posts

  • 0
Posted (edited)

The simplest way is :

Please login or register to see this code.

The interesting way is :

Please login or register to see this code.

 

Edited by cag014
  • 0
  • Inquirer
  • Posted

    Thank you verry much, but of thé getValue don't works when i test it

    Is it compatibel whit thé Philips hue?

    • 0
    Posted

    Do you use Hue plugin?

    • 0
  • Inquirer
  • Posted (edited)

    Yes

    And the lights are automatic found

    I have a virtual device whit 2 buttons and it works

     

    Sorry die my bad English

    Edited by Chundo
    • 0
    Posted (edited)

    Hi @Chundo ,

     

    From LUA scene you can use following functions to control HUE plugin lights:

    to read HUE plugin light status:

    Please login or register to see this code.

    if light is turned on then above function will return 1 and if it is off then will return 0.

    You can also check what brightness is set with this function:

    Please login or register to see this code.

    To turn on HUE light:

    Please login or register to see this code.

    After light is turned on you can change brightness, color (hue) and saturation:

    Please login or register to see this code.

    To turn off HUE light:

    Please login or register to see this code.

    Hope this helps!

    Enjoy coding :-)

     

    Edited by Sankotronic
    • 0
    Posted

    Thank you @Sankotronic

    So @Chundo please use as following:

    The simplest way is :

    Please login or register to see this code.

    The interesting way is :

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    I still have a error when i debug info thé first rule?

    Did you test it yourself?

    Sorry i am a noob :-) thank you for thé good response!

    • 0
    Posted (edited)
    1 hour ago, Chundo said:

    I still have a error when i debug info thé first rule?

    Did you test it yourself?

    Sorry i am a noob :-) thank you for thé good response!

     

    Did you replaced pluginID with real ID number of the plugin that controls wanted light?

     

    And Yes of course I tested it, many times, it is part of my Very Smart Light scene that can control HUE lights using Fibaro HUE plugin ;-)

    When you  use fibaro functions bare in mind that they are almost ALWAYS returning value in STRING format. So you have to convert it to number to compare with numeric value or you have to use value that is inside quotes which then is interpreted by LUA as string. Bellow conditions are all correct:

    Please login or register to see this code.

    LUA will give you error and stop running if you compare string with numeric value. Also it is very important that you are aware that LUA is case sensitive language so using big "ABCD" and small letters "abcd" make BIG difference.

     

    Enjoy coding :-)

     

    EDIT

    I recommend to check this websites:

    Please login or register to see this link.

    Please login or register to see this link.

    Please login or register to see this link.

     

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

    I now, I have a virtual device whit one on and one off button and it works, it was a lot of trail and error tot make it as noob. Now I would like to have one button for on and off, just to try and get some experience to make more complicatet code.

     

    Thank you for thé help, i keep trying! :-)

    this is my code

     

    if fibaro:getValue(42, "on") == "0" then
      fibaro:call(42, "turnOn")
        else
        fibaro:call(42, "turnOff")
        end

     

    this is the error

     

     

    [ERROR] 17:56:21: line getValue(42, "on") == "0" then..."]:2

    Edited by Chundo
    • 0
    Posted

    Could you please post the entire code of yours?

     

    • 0
  • Inquirer
  • Posted

    if fibaro:getValue(42, "on") == "0" then
      fibaro:call(42, "turnOn")
        else
        fibaro:call(42, "turnOff")
        end

    3 hours ago, Sankotronic said:

     

    Did you replaced pluginID with real ID number of the plugin that controls wanted light?

     

    And Yes of course I tested it, many times, it is part of my Very Smart Light scene that can control HUE lights using Fibaro HUE plugin ;-)

    When you  use fibaro functions bare in mind that they are almost ALWAYS returning value in STRING format. So you have to convert it to number to compare with numeric value or you have to use value that is inside quotes which then is interpreted by LUA as string. Bellow conditions are all correct:

    Please login or register to see this code.

    LUA will give you error and stop running if you compare string with numeric value. Also it is very important that you are aware that LUA is case sensitive language so using big "ABCD" and small letters "abcd" make BIG difference.

     

    Enjoy coding :-)

     

    EDIT

    I recommend to check this websites:

    Please login or register to see this link.

    Please login or register to see this link.

    Please login or register to see this link.

     

     

    if fibaro:getValue(42, "on") == "0" then
      fibaro:call(42, "turnOn")
        else
        fibaro:call(42, "turnOff")
        end

     

     

    is thé full code

    • 0
    Posted

    Very strange... is the error that you've posted is the full error line?

    Usually it shows line number as well, in your case I don't see it.

    If you could post the picture of the screen (including error of the scene) it will help to understand what is wrong with code

    • 0
  • Inquirer
  • Posted

    Here are thé pictures.

     

    Thank you forever thé Replay and solution

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    • 0
    Posted (edited)

    OK... now I can see it....

    You forgot to close "turnOn statement in fibaro:call(42, "turnOn) with double quotes...

    It should be "turnON", please correct to   fibaro:call(42, "turnOn").

    Hope it is understandable ...

     

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    than you verry much en soory that I am a noob :-)

    it work and i am verry happy :-))

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