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

DW sensor + PIR


julesmartens

Question

Hi all,

 

I have a DW sensor that should switch on the light when it is evening and the door is open.

Once triggered, the light should remain on until the door is closed and no motion is detected in that room.

When door is closed and motion is no longer detected the light should slowly fade out.

 

I wrote below code for this but cant get it working properly.

I have the problem that the light will perfectly go when the door is opened but it will not go out! 

 

Anybody an idea what I do wrong? It seems not to reach the "repeat" part of my code which is within the IF statement.

 

Here is the code:

 

--[[
%% autostart
%% properties
21 value
127 value
%% weather
%% events
%% globals
omtrekverlichting
--]]

--============ HOME TABLE =======================
fibaro:getGlobalValue("HomeTable")
local jT = json.decode(fibaro:getGlobalValue("HomeTable"))
--===============================================

-- used devices and its id
fibaro:debug("device: hal - voordeur DW = ID: " ..jT.hal.voordeursensor) --127
fibaro:debug("device: hal - hal PIR = ID: " ..jT.hal.HalMo21) --21
fibaro:debug("device: hal - duospot = ID: " ..jT.hal.duospot) --160
fibaro:debug("device: hal - halspot = ID: " ..jT.hal.halspot) --116
--===============================================

local debug = false

Debug = function (debug,color, message )
  if (debug) then
      fibaro:debug(os.date("%x")..string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); 
  end
end

 

if (fibaro:countScenes() > 1) then
    Debug( true,"purple", " too many instances --> abort ");
      fibaro:abort()
end

 

local trigger = fibaro:getSourceTrigger()

if (trigger['type'] == 'property')         then Debug(true, "Grey", ' scene triggered by - Source device = ' .. trigger['deviceID'])
elseif (trigger['type'] == 'global')     then Debug(true, "Grey", ' scene triggered by - Global variable source = ' .. trigger['name'])
elseif (trigger['type'] == 'other')     then Debug(true, "Grey", ' scene triggered by - Other source')
end

-- start up ---------------------------------------


local deurstatus = fibaro:getValue(jT.hal.voordeursensor, "value")
local Darkness = fibaro:getGlobalValue("Darkness")
local motion = fibaro:getValue(jT.hal.HalMo21, "value")
local lampstatus = fibaro:getValue(jT.hal.duospot, "value")

local dimlevel = 60


if     (tonumber(Darkness) == 1) and (tonumber(deurstatus) == 1) then
                  Debug( true,"Orange",' hal verlichting ingeschakeld')
                  fibaro:call(jT.hal.duospot , 'setValue' , dimlevel) 
                  fibaro:call(jT.hal.halspot , 'setValue' , dimlevel) 
                 

                  repeat fibaro:sleep(3*1000) -- always wait at least x seconds before fade out.
                  until (tonumber(motion) == 0) and (tonumber(deurstatus) == 0)
          
                 while( dimlevel > 10 )       do -- start fade -out.
                 fibaro:call(jT.hal.duospot , 'setValue' , dimlevel) 
                 fibaro:call(jT.hal.halspot , 'setValue' , dimlevel) 
                 fibaro:sleep(20)
                 Debug( true,"Yellow",' dimlevel is '..dimlevel)
                dimlevel = (dimlevel -0.4)
                end


      fibaro:call(jT.hal.duospot , 'turnOff' ) -- make sure lights are really off
      fibaro:call(jT.hal.halspot , 'turnOff' )
      Debug( true,"Green",' hal verlichting uitgeschakeld')      
end

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

 

Please login or register to see this code.

 

Edited by 10der
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...