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


  • 4

HC3 no motion for X time = lights off, how to?


Question

Posted

Hi,

 

How do you configure a scene that will turn on lights when motion and does not turn off until motion sensor has been safe for X time?

I am looking for both Lua and block options, if available.

Until now I have only found option for "delay" meaning lights will turn off after given time no matter if there has been motion during "delay" period.

 

Hope someone has found a solution for this.

Recommended Posts

  • 0
Posted
On 6/28/2020 at 12:34 AM, SmartHomeEddy said:

You can start simple. If it works, you can always make it better.

 

Add a lua scene

 

Use this for declarions

Please login or register to see this code.


Use this for Actions

 

Please login or register to see this code.


in this code 254 is my motion sensor,

256 is my lux sensor and

251 is the light switch.

You have to fill in the ID’s of your setup. 

 

“value = 3” represents the lux value. So in this code <= 3 lux (and motion) will turn on the light. You can experiment with this value, which lux value suites you the best in your setup. 
 

local maxTime = 1*60” represens the time the light stays on, in this case 60 seconds (and longer if there is still motion, motion resets the timer). 

 

 

Could someone please point me in the right direction to amend this code to add a time slot eg - between Xam and Xpm and also adding a dimming value to the light on?

  • 1
Posted (edited)

fibaro should go with pure python or c or any other lang that is not lua.... even php will be better... why they choose lua ... dont know...

 

 

more - bash - for 99% ppl will be simple enough without lua stupidity

 

HC2 - no stupid splitted window for lua.

And HC3 - why splitted window ? for what ? do You have splitted windows when you open any file and you want to programm something ? in any language ? so you edit two files ? seriously ?

Edited by paol
  • Like 1
  • 0
Posted (edited)

and is programming language looks like this ?

Please login or register to see this attachment.

rly ?

So condition is what ? separate what ? from what ? and when ?

Also - trigger... wtf... if I want in any language when any value changes to have "then" action thae I want to have it... now switching to lua i dont know what You mean... what is this ? declarations/conditions/triggers ? so what is this exacly in programming language ? rly ?

Edited by paol
  • Like 1
  • 0
Posted

also when switched from block to lua

operator = "match>=",
What is this ?
someone forgot to parse value ? it looks like it is missing also internally - cause block scenes also not working.
 
And block scene is like this:
So where is time match ?

Please login or register to see this attachment.

  • 0
Posted
On 7/3/2020 at 10:10 AM, SmartHomeEddy said:

I use copies of the scene for different rooms. That way I can tune the lux and maxTime easily. 
 

I have changed the code to make it more flexible, for instance, I use in my garage two motion sensors. 
 

In the declarations there are also time option like “sunrise” and “sunset”. If you add a block scene (and later disable it to keep it for future experiments) you can experiment with that condition and convert it to Lua to see how it looks like with all the {} and or constructions. 
 

In your case, copy your first scene to a new one, change the declaration between sunset and sunrise (is a condition not the trigger) and motion (as trigger) at night will turn on the light and the light stays on during motion. You don’t need the lux in the declaration as condition. 

 

 


 

Please login or register to see this code.

 

 

I try to use this LUA code in the  LUA Editor of the HC3. however I can't seem to find which part of the code should be added to the 'triggers/conditions'  and which part needs to be copied into 'actions'.  What am I doing wrong?
 

 

 

  • 0
Posted (edited)
7 minutes ago, MauritsG said:

I try to use this LUA code in the  LUA Editor of the HC3. however I can't seem to find which part of the code should be added to the 'triggers/conditions'  and which part needs to be copied into 'actions'.  What am I doing wrong?

 

The above is only the "ACTIONS" part. 

 

In the "DECLARATIONS" part you do have to define when the scene is triggered. 

 

An example of the "DECLARATIONS" part:

 

Please login or register to see this code.

 

Where ID 76 is my motion sensor and ID 78 is my Lux sensor. If the motion is triggered and the lux is equal or less than 1, the "ACTIONS" part begins.

 

 

 

Edited by SmartHomeEddy
  • Thanks 1
  • 0
Posted (edited)

Thanks this is much apreciated!
 

Edited by MauritsG
  • 0
Posted

One more question, if I want to set the brightness of the lighting in the room as well. Can I simply add the paramaters in the ACTION part like this:

 

fibaro.call({[1] = 58, [2] = 60, }, 'setColor', 119, 110, 65, 0)
fibaro.call({[1] = 58, [2] = 60, }, 'setValue', 48)
  • 0
Posted

Yes, that is possible. Just insert the 

 

Please login or register to see this code.

 

part in it, to work together with the script. But first try to get it to work with on / off. 

  • 0
Posted

The on/off works reallly well. Only problem occurs during night time (0 Lux). The motion controller recognises movement (blue indicator flashing) however the scene won't start.

  • 0
Posted

That is strange. Works here all the time. And the actual lux level is 0 at that time? (Lux sensor doesn’t gives a higher reading?)

  • 0
Posted

Declarations:

{
  conditions = { {
      id = 64,
      isTrigger = true,
      operator = "==",
      property = "value",
      type = "device",
      value = true
    }, {
      id = 66,
      isTrigger = false,
      operator = "<=",
      property = "value",
      type = "device",
      value = 50
    } },
  operator = "all"
}

Actions:

-- This scene turns on one or more lights: 
--    when Lux level is below a certain level (see DECLARATIONS) and 
--    shows the Lux level of one ore more Lux sensors and 
--    turns off the lights after a certain time (maxTime), 
--    unless there is motion from one or more Motion sensors
 
-- Please enter the right ID's (if more than one, seperate by ",") and the prefered maxTime for the lights to stay on 
 
local light = {53} -- ID's of the lights to turn on
local motion = {64} -- ID's of the Motion sensors to check if they are breached
local lux = {66} -- ID's of the Lux sensors to (only) show the lux level
local maxTime = 2*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 = "Keuken Lampen" -- Tag for the debug messages
 
-- Below here no changes are necessary
 
for i in pairs(light) do -- Turn on the lights
  fibaro.debug(debug_TAG,"Turning on (ID " ..light[i] ..") " ..fibaro.getName(light[i]) .." for " ..maxTime .." seconds")
  fibaro.call(light[i],"turnOn")
end
 
for i in pairs(lux) do -- Show the lux level of the Lux sensors
  fibaro.debug(debug_TAG,"Current Lux level " ..lux[i] .." " ..fibaro.getName(lux[i]) ..": " ..fibaro.getValue(lux[i],"value"))
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 lights
  fibaro.debug(debug_TAG, "Turning off " ..light[i] .." " ..fibaro.getName(light[i]))
  fibaro.call(light[i],"turnOff") 
end
  • Like 1
  • Thanks 1
  • 0
Posted (edited)

Did you check the lux level of the lux sensor in the dashboard at the time the motion sensor is triggered?

 

 

Edited by SmartHomeEddy
  • 0
Posted

Infact I did. The lux level was 0 at the moment of testing. I deleted the scenes and made them again and they are up and running now. Quit frankly the motion and light scene for the garden lights stopped working.  Mabey something in the settings?

  • 0
Posted

There are not that many settings. 
 

The lux level is only checked in the declarations. In the script the lux sensor is only used to show the lux level in the debug message. I used that lux level in the debug message to finetune the declarations, to finetune at what lux level the light should (not) turn on. 

  • 0
Posted

Grat code by the way. I have a question?

 

After the countdown ends i would like to check another condition like:

- After countdown , if light (ID 74) is turned on,  then stop counting and, and do not turn off the lamp (ID 324)

 

Declarations

 

{

  conditions = { {

      id = 455, -- motion sensor 

      isTrigger = true,

      operator = "==",

      property = "value",

      type = "device",

      value = true

    }, {

      id = 74, -- another light (condition only)

      isTrigger = true,

      operator = "==",

      property = "state",

      type = "device",

      value = false

    }, {

      id = 325, -- another light (condition only)

      isTrigger = true,

      operator = "==",

      property = "state",

      type = "device",

      value = false

    }, {

      conditions = { { 

         type = "date",

                    property = "sunset",

                    operator = ">=",

                    value = -15 

                },

                {

                    type = "date",

                    property = "sunrise",

                    operator = "<=",

                    value = 15   

        } },

      operator = "any"

    } },

  operator = "all"

}

 

ACTIONS

 

-- This scene turns on one or more lights:

--    when Lux level is below a certain level (see DECLARATIONS) and

--    shows the Lux level of one ore more Lux sensors and

--    turns off the lights after a certain time (maxTime),

--    unless there is motion from one or more Motion sensors

 

-- Please enter the right ID's (if more than one, seperate by ",") and the prefered maxTime for the lights to stay on

 

local light = {324} -- ID's of the lights to turn on

local motion = {455} -- 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

local debug_TAG = TEST SCENE " -- Tag for the debug messages

 

 

-- Below here no changes are necessary

 

for i in pairs(light) do -- Turn on the lights

  fibaro.debug(debug_TAG," Turning on (ID " ..light[i] ..") " ..fibaro.getName(light[i]) ..for " ..maxTime .." seconds")

  fibaro.call(light[i],"turnOn")

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 max time ..." ..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 lights

  fibaro.debug(debug_TAG, Turning off  " ..light[i] .." " ..fibaro.getName(light[i]))

  fibaro.call(light[i],"turnOff") 

end

 

  • 0
Posted

You could add an extra if statement or add the condition to the for statement, but the light will stay on forever, until there is motion and the other two lights are off. Is that what you are searching for?

  • 0
Posted

I would like for scene to check the condition of the lamp ID74 and ID325 and if that lamps turned on while the scene is running, scene would stop, and all the lights will stay on... 

 

Im not good at coding... What line do i need to insert in a code???

  • 0
Posted

going back to something @SmartHomeEddy explained to me once; a good override to the scene is using the manual switch. So rather than trying to build that logic into the code, simply assume if you press the physical switch it the lights go to be manually controlled.

 

I don't know if thats how your scene is setup or if that works for you, but if i understood what you're looking for correctly then i felt it was ok for me. 

  • 0
Posted

Im trying to learn basic LUA coding. Everything we do we can do with physical switches. But i would like to learn the code...

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