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

Slowly increasing light over set time. Please help me fix the code....


ErikP

Question

I want to have a kind of wakeup light that gradually increases intensity over a set amount of minutes. I tried this code:

 

--[[
  Slowly increase light brightness over time
  Adapted from code by Fibaro Forum user: iRobot
--]]

-- User-defined variables
local lightID = 1  -- ID of the light device to control
local duration = 10  -- Duration of the fade-in in seconds

-- Get current light level
local currentLevel = fibaro:getValue(lightID, "value")

-- Set initial brightness level to 0
fibaro:call(lightID, "setProperty", "ui.brightnessLevel.value", 0)

-- Calculate the brightness increment based on the duration
local brightnessIncrement = 100 / (duration * 10)

-- Loop through and gradually increase brightness level
for i=0,100,brightnessIncrement do
  fibaro:sleep(100)
  fibaro:call(lightID, "setValue", i)
end

-- Set the final brightness level
fibaro:call(lightID, "setValue", currentLevel)
 

But is does not seem to work. I get the following error:
"(load):11: Assertion failed: Expected number"

 

Can someone help me make this code work?

 

Thanks!

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
3 hours ago, ErikP said:

I want to have a kind of wakeup light that gradually increases intensity over a set amount of minutes. I tried this code:

 

--[[
  Slowly increase light brightness over time
  Adapted from code by Fibaro Forum user: iRobot
--]]

-- User-defined variables
local lightID = 1  -- ID of the light device to control
local duration = 10  -- Duration of the fade-in in seconds

-- Get current light level
local currentLevel = fibaro:getValue(lightID, "value")

-- Set initial brightness level to 0
fibaro:call(lightID, "setProperty", "ui.brightnessLevel.value", 0)

-- Calculate the brightness increment based on the duration
local brightnessIncrement = 100 / (duration * 10)

-- Loop through and gradually increase brightness level
for i=0,100,brightnessIncrement do
  fibaro:sleep(100)
  fibaro:call(lightID, "setValue", i)
end

-- Set the final brightness level
fibaro:call(lightID, "setValue", currentLevel)
 

But is does not seem to work. I get the following error:
"(load):11: Assertion failed: Expected number"

 

Can someone help me make this code work?

 

Thanks!

Is this in a HC2 right?

I am not familiar with HC2 but i think this line is making the trouble

 

fibaro:call(lightID, "setProperty", "ui.brightnessLevel.value", 0)

 

in HC3 i would do fibaro:call(lightID, "setValue",  0)

 

And on the other hand, if this is a fibaro rgbw modul or dimmer modul i would just set up the transition time in parameters. You dont need to hardcode it.

 

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thanks. Indeed it seems like HC2 but I want to get it working on HC3. As for the parameters, indeed that is an option but then this light will always behave like that and I only want it in certain occasions, so if I run the scene...

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks!,

     

    this line is also an issue:

    -- Get current light level
    local currentLevel = fibaro:getValue(lightID, "value")

     

    Is that not HC3 compatible?
     

    Link to comment
    Share on other sites

    • 0
    37 minutes ago, ErikP said:

    Thanks!,

     

    this line is also an issue:

    -- Get current light level
    local currentLevel = fibaro:getValue(lightID, "value")

     

    Is that not HC3 compatible?
     

    It should be fibaro.getValue(lightID, "value"), 

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