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

Question

Posted

Hi,

 

I tried to modify a light scene to set a GlobalVariable "on" as long as motion is detected. When a maxTime is reached without motion the GlobalVariable should be set "off" again. That all sould only work if the GlobalVariable presence is set on false. Could you held my?

 

local light = {} -- ID's of the lights to turn on
local motion = {21, 27, 64, 76, 99} -- ID's of the Motion sensors to check if they are breached
local maxTime = 1*60 -- Maximum time the sensor should be safe before turning off (n*60 where n is minutes)
local sleepTime = 5 -- Time in seconds between each check of the Motion sensor (default = 5)
local debug_TAG = "Alarm" -- Tag for the debug messages
local presence = fibaro.getGlobalVariable("Presence")
 
 
for i in pairs(light) do 
if presence == 'false' then
fibaro.debug(debug_TAG,"Turning on Alarm for " ..maxTime .." seconds")
fibaro.setGlobalVariable('alarm', 'on')
fibaro.call(114, 'setColor', 255, 0, 0, 0)
fibaro.sleep(10)
fibaro.call(114, 'setValue', 100)
end
end
 
local safeTime = 0
while safeTime < maxTime do -- Loop until maxTime is reached
fibaro.sleep(sleepTime*1000)
safeTime=safeTime+sleepTime
fibaro.debug(debug_TAG,"Counting up safeTime " ..safeTime .." to maxTime " ..maxTime)
for i in pairs(motion) do
if fibaro.getValue(motion[i],"value") then -- Check if Motion sensors are breached
fibaro.debug(debug_TAG,"Reset by Motion sensor " ..motion[i] .." " ..fibaro.getName(motion[i]))
safeTime = 0 -- Reset safeTime to zero
end
end
end
 
for i in pairs(light) do -- Counted down to maxTime, turn off the alarm
fibaro.setGlobalVariable('alarm', 'off')
fibaro.call(114, 'setValue', 0)
end

2 answers to this question

Recommended Posts

  • 0
Posted
1 hour ago, Eldar said:

if presence == 'false' then


Is your variable presence a boolean (false) or a string (“false”) ? 
 

If it is a boolean:

Please login or register to see this code.


The light variable is empty, so

for i in pairs(light) do 

won’t do anything. 

  • 0
  • Inquirer
  • Posted (edited)

    Thanks for your help. It is working now. In my HC2 I had the following scene running. Could anybody help me to convert it to HC3?

     

    Please login or register to see this code.

     

    Edited by Eldar

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