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

countdown in scene


Question

Posted

Hi I have a scene which is triggered by a switch, i want to switch off the switch after 60 minutes, what would be the best way of doing this?

so far i have a simple way but it does not seem to be clean.
I  have a loop in the scene which runs for 60 minutes and then at the end of the loop sets the swicth to off,

I have two problems with this, one if I turnoff the switch manually and then on again it causes an error in the debug, this might not be a big thing but it does not feel right from progaming side. the other issue woudl be if the system reset during this countdown I would loose the countdown and the switch would stay on when it should be off.

Thank you for your help.

 

1 answer to this question

Recommended Posts

  • 0
Posted

Hi Jay Ess. I'm a learner but I may be able to help with your first point. I'm using the following to turn on a light from a movement sensor and to keep the light on for set amount of time. The timer is reset if the movement sensor is reactivated, but this part of the code could be removed if you want to have the light switch off even if you switch it manually. It seems to work well as a repeat loop and I've used it with several movement sensors & lights.

 

local startSource = fibaro:getSourceTrigger();

if (

 ( tonumber(fibaro:getValue(motion_1, "value")) > 0   **** replace "motion_1 with your switch****

or

startSource["type"] == "other"

)

  

then

 

fibaro:call(rgbw_1, "setColor", rgbw_r,rgbw_g,rgbw_b,rgbw_w) ***** replace this with your light *****

  

  

--Debug

fibaro:debug('after light on command')

  

--set the time delay for the movement sensor

sec = 60 --seconds  ****** set to 3600 seconds ******

 

--repeat loop 

repeat 

    

--Debug

fibaro:debug('before sleep')

    

fibaro:sleep(1000*1) -- sleep 1 sec

    

--Debug

fibaro:debug('after sleep & before 2nd if')

    

 

local startSource = fibaro:getSourceTrigger();

if (

 ( tonumber(fibaro:getValue(motion_1, "value")) > 0   

or

startSource["type"] == "other"

)

     

then

--Debug      

fibaro:debug('after 2nd if')

      

sec =  60 -- if breached, reset counter   ******* you might want to remove this part so that the counter isn't reset if you manually turn the light off and on*****

else      

sec = sec-1 -- otherwise count down   

end

    

--Debug

fibaro:debug('after end of repeat script')

    

until sec <= 0 --until the counter gets to zero

  

--Debug

fibaro:debug('before lights off')

  

fibaro:call(rgbw_1,"turnOff") -- light off ***** replace with your lights ref ******

 

end

 

The second part of your question might be solved with a time stamp saved as a global variable which would remain if the system is reset, your scene would then call the time stamp and use it to compare with the current time, but I'm not experienced enough to help you with the coding !

 

Hope this helps a bit

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