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?


Pete123

Question

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.

Link to comment
Share on other sites

Recommended Posts

  • 0

if you use home table and you filled it you can use jT.Woonkamer.verlichting else you the device's ID number (you can find it at "settings>Devices" you'll see a list of installed devices and their ID numbers (next to the icon

Link to comment
Share on other sites

  • 0
3 minutes ago, jimicr said:

if you use home table and you filled it you can use jT.Woonkamer.verlichting else you the device's ID number (you can find it at "settings>Devices" you'll see a list of installed devices and their ID numbers (next to the icon

i used the hometable but the lights did not go on in al the other rooms with 1 light en sensor it works perfectly.

 

jsonHome = {
Woonkamer={beweging=134, beweging=1401, beweging=1442, temp_PIR=135, temp_PIR1=141, temp_PIR2=145, lux=136, lux1=142, lux2=146, lux3=236,  luchtvocht=237, verlichting=115, verlichting1=130, verlichting2=153, verlichting3=150, verlichting4=27,},
Badkamer={beweging=209, temp_PIR=210, lux=211, luchtvocht=212, verlichting=215, ventilatie=221},
Slaapkamer={beweging=92, temp_PIR=93, lux=94, verlichting=99,},
Gang={beweging=62, temp_PIR=226, lux=64, verlichting=82,},
Wc={beweging=86, temp_PIR=87, lux=88, verlichting=113,},
Bijschuur={beweging=86, temp_PIR=87, lux=88, verlichting=113,},
}
 
fibaro.setGlobalVariable("HomeTable", json.encode(jsonHome)) 
jT = json.decode(fibaro.getGlobalVariable("HomeTable")) 
 
fibaro.debug("""HomeTable created")
fibaro.debug("", jT.Badkamer.verlichting)
Link to comment
Share on other sites

  • 0
2 minutes ago, jimicr said:

You can only use one sensor unless you edit the scene

oke it works now. i will try to make it work now wit 3 sensors?

Link to comment
Share on other sites

  • 0
1 minute ago, marius de jong said:

oke it works now. i will try to make it work now wit 3 sensors?

I may do it as well tomorrow, I see you're from Holland aslo. I have time now I live in Braband and have a cold so been send home from work...

Link to comment
Share on other sites

  • 0
3 minutes ago, jimicr said:

I may do it as well tomorrow, I see you're from Holland aslo. I have time now I live in Braband and have a cold so been send home from work...

i am from zuid holland so for the moment its oke here.

i tink i got it. changed line 68 to the below code and added the 2 motionsensor in the biginning of the rule
 

local motion = jT.Woonkamer.beweging
local motion1 = jT.Woonkamer.beweging1
local motion2 = jT.Woonkamer.beweging2

 

line 68: if hc.getValue(motion,"value"or hc.getValue(motion1,"value"or hc.getValue(motion2,"value"then -- motion breached
Link to comment
Share on other sites

  • 0
1 minute ago, marius de jong said:

i am from zuid holland so for the moment its oke here.

i tink i got it. changed line 68 to the below code and added the 2 motionsensor in the biginning of the rule
 

local motion = jT.Woonkamer.beweging
local motion1 = jT.Woonkamer.beweging1
local motion2 = jT.Woonkamer.beweging2

 

line 68: if hc.getValue(motion,"value"or hc.getValue(motion1,"value"or hc.getValue(motion2,"value"then -- motion breached

Nice! I still need to get used to the new triggers

Link to comment
Share on other sites

  • 0
12 hours ago, jimicr said:

@robw, remove the check if lights are on:

Please login or register to see this code.

to:

Please login or register to see this code.

Same goes for turning off

 

Jim

 

 

Hi, I just tested, and it turns on and then it turns off immediately after a second. So it is good it can turn on and off.

 

local hc = fibaro
jT = json.decode(hc.getGlobalVariable("HomeTable")) 
 
local light = {jT.Bathroom.bathroomlight}
local motion = jT.Bathroom.motion
local lux = tonumber(hc.getValue(jT.Bathroomt.lux, "value"))
local luxmin = 500
 
count = 0
function checkLights()
  if #light > 0 then
    for i = 1, #light
    do
if hc.getValue(light"state"then count = count+1 end
    end
    end
end
 
function turnon()
  if #light > 0 then
    for i = 1, #light
    do
        hc.call(light,"turnOn");
        hc.debug("","Turning on");
        hc.sleep(100)
    end
    end
end
 
function turnoff()
  if #light > 0 then
    for i = 1, #light
    do
        hc.call(light,"turnOff");
        hc.debug("","Turning off");
        hc.sleep(100)
    end
    end
end
 
checkLights()
if count >0 then state = "On" else state = "Off" end
 
hc.debug("","Current lux: ",lux)
hc.debug("","minlux: ",luxmin)
if state == "Off" then
if luxmin < lux then hc.debug("","room to light to turn on  lights")
else
local maxTime = 3*60  -- max time the sensor should be safe before turning off
local sleepTime = 3   -- time in seconds between each check of the sensor
 
turnon()
 
local safeTime = 0
while safeTime < maxTime do
  hc.sleep(sleepTime*1000)                 
  safeTime=safeTime+sleepTime                   -- count up safeTime
  hc.debug("","Counting up safeTime ",safeTime,maxTime)  
  
 count = 0 
 checkLights()
 if count >0 then state = "On" else state = "Off" end
    if state == "Off" then hc.debug("","Light(s) turned off manual");
  break end
  
  if hc.getValue(motion,"value"then -- motion breached
     safeTime=0                                 -- reset safeTime
     hc.debug("","Reset")
  end
end 
  
turnoff()
end
else hc.debug("","Light manual turned on")
end
hc.debug("","Scene ended")
Link to comment
Share on other sites

  • 0

Hello,

 

I'd like to use this method in my 3 rooms (every room with it own script and different timeouts) to turn off light when no move detected in room for x time.

I'd like to:

- turning on any of 3 switches > start cuntdown

- manually turning off switch > stop countdown

- detected move > reset countdown

 

 

Now i'm trying this code, but:

- it causes high cpu utilization

- turning off switch doesn't stop counting

- when i turn on 3 scenes, debug of every one of them shows 3 countdowns, not only it's own

 

Can you help me to deal with it?

 

{
  conditions = { {
      id = 115,
      isTrigger = true,
      operator = "==",
      property = "state",
      type = "device",
      value = true
    }, {
      id = 116,
      isTrigger = true,
      operator = "==",
      property = "state",
      type = "device",
      value = true
    }, {
      id = 117,
      isTrigger = true,
      operator = "==",
      property = "state",
      type = "device",
      value = true
    } },
  operator = "any"
}
 
 
local light = {115,116,117}
local motion = 163
 
local maxTime = 1*60  -- max time the sensor should be safe before turning off
local sleepTime = 5   -- time in seconds between each check of the sensor
 
fibaro.debug("","Turning on")
local safeTime = 0
while safeTime < maxTime do
  fibaro.sleep(sleepTime*1000)                 
  safeTime=safeTime+sleepTime                   -- count up safeTime
  fibaro.debug("","Counting up safeTime ",safeTime,maxTime)
  if fibaro.getValue(motion,'value'then -- motion breached
     safeTime=0                                 -- reset safeTime
     fibaro.debug("","Reset")
  end
end 
  
fibaro.debug("","Turning off")
fibaro.call(light,'turnOff'
Link to comment
Share on other sites

  • 0
59 minutes ago, michal85pl said:

Anyone?

 

Well, I made this QuickApp the other day...

Assume you have 3 motion sensors in the kitchen, id 44, id 55, and id 66

If you use the QA in the post and create a QA variable (quickAppVariable) 

name: #motionsInKitchenSafeFor5min

and as value put the string

"00:05/2/44:safe & 55:safe & 66:safe"

It will send a CustomEvent named 'motionsInKitchenSafeFor5min' when the all the motion sensors are safe for 5 min.

If anyone gets breached it will restart waiting until they all are safe for 5min again and send a new event etc etc.

You could then build a block scene that triggers on the CustomEvents and turns off the lights

You could add more rules for more rooms - the quickvar needs to start with #.

 

To handle the case with the the switch stopping the countdown I would recommend the same block scene triggering on the switch becoming 'on' and set a global variable that you check before you turn off the lights when you react on the 'motionsInKitchenSafeFor5min' customEvent.

It's usually a bit complicated because you need to decide when to let the countdown continue again. After 20min of no motion? Then add another rule

name: #motionsInKitchenSafeFor20min

value: "00:20/2/44:safe & 55:safe & 66:safe"

and clear the variable.

 

My thinking behind creating the QA was to setup rules that posts events when rooms are safe, when rooms are breached, when rooms are lit (lux), etc. as I usually have more than one sensor per room. The expressiveness for rules are more or less what Lua supports which  allows for quite complex rules. 

"00:20/2/(101:lux + 102:lux + 103:lux)/3 > 200"

is true when the average lux value in a room with 3 lux sensors exceeds 200 and will fire off an event.

 

However, I haven't had to play with it much yet...

Anyway, it's a possibility...

 

 

Link to comment
Share on other sites

  • 0
W dniu 18.03.2020 o 18:16, jgab napisał:

Well, I made this QuickApp the other day...

Assume you have 3 motion sensors in the kitchen, id 44, id 55, and id 66

If you use the QA in the post and create a QA variable (quickAppVariable) 

name: #motionsInKitchenSafeFor5min

and as value put the string

"00:05/2/44:safe & 55:safe & 66:safe"

It will send a CustomEvent named 'motionsInKitchenSafeFor5min' when the all the motion sensors are safe for 5 min.

If anyone gets breached it will restart waiting until they all are safe for 5min again and send a new event etc etc.

You could then build a block scene that triggers on the CustomEvents and turns off the lights

You could add more rules for more rooms - the quickvar needs to start with #.

 

To handle the case with the the switch stopping the countdown I would recommend the same block scene triggering on the switch becoming 'on' and set a global variable that you check before you turn off the lights when you react on the 'motionsInKitchenSafeFor5min' customEvent.

It's usually a bit complicated because you need to decide when to let the countdown continue again. After 20min of no motion? Then add another rule

name: #motionsInKitchenSafeFor20min

value: "00:20/2/44:safe & 55:safe & 66:safe"

and clear the variable.

 

My thinking behind creating the QA was to setup rules that posts events when rooms are safe, when rooms are breached, when rooms are lit (lux), etc. as I usually have more than one sensor per room. The expressiveness for rules are more or less what Lua supports which  allows for quite complex rules. 

"00:20/2/(101:lux + 102:lux + 103:lux)/3 > 200"

is true when the average lux value in a room with 3 lux sensors exceeds 200 and will fire off an event.

 

However, I haven't had to play with it much yet...

Anyway, it's a possibility...

 

 

 

Man You are Great ... this method works great and gives more possibilities, which in my opinion should be available as ready conditions in block scenes ...

I have an additional question. What if, by mistake, we turn on the switch, for example, through an Application without detected motion (the motion sensor was already marked as safe), how to force a countdown restart?

Does the following apply to this problem because I do not understand it?

 

Cytat

To handle the case with the the switch stopping the countdown I would recommend the same block scene triggering on the switch becoming 'on' and set a global variable that you check before you turn off the lights when you react on the 'motionsInKitchenSafeFor5min' customEvent.

It's usually a bit complicated because you need to decide when to let the countdown continue again. After 20min of no motion? Then add another rule

name: #motionsInKitchenSafeFor20min

value: "00:20/2/44:safe & 55:safe & 66:safe"

and clear the variable.

 

Link to comment
Share on other sites

  • 0
53 minutes ago, michal85pl said:

 

Man You are Great ... this method works great and gives more possibilities, which in my opinion should be available as ready conditions in block scenes ...

I have an additional question. What if, by mistake, we turn on the switch, for example, through an Application without detected motion (the motion sensor was already marked as safe), how to force a countdown restart?

So, you turn on the lamp in the room from another scene or the app and no one is in the room?

You can add the lamp to the condition, ex. the lamp deviceID is 77

 

name: #roomLitWhileEmptyFor5min

value: "00:05/2/77:on & 44:safe & 55:safe & 66:safe"

 

If the lamp is on and the sensors are safe for 5min it will send the event

Link to comment
Share on other sites

  • 0
10 minut temu, jgab napisał:

So, you turn on the lamp in the room from another scene or the app and no one is in the room?

You can add the lamp to the condition, ex. the lamp deviceID is 77

 

name: #roomLitWhileEmptyFor5min

value: "00:05/2/77:on & 44:safe & 55:safe & 66:safe"

 

If the lamp is on and the sensors are safe for 5min it will send the event

Yes, but given that we turn on the switch virtually, the motion sensor is already in safe state, so it immediately turns off the switch, but I would like the countdown to be triggered

Link to comment
Share on other sites

  • 0
6 minutes ago, michal85pl said:

Yes, but given that we turn on the switch virtually, the motion sensor is already in safe state, so it immediately turns off the switch, but I would like the countdown to be triggered

Yes, but 77:on  need to be true for 5mins also.

Actually the whole expression needs to be true for 5min, which includes 77 being on and the sensors being safe.

So when the lamp is turned on it will start counting 5mins (given that the sensors are safe already)

Edited by jgab
Link to comment
Share on other sites

  • 0
7 minut temu, jgab napisał:

Yes, but 77:on  need to be true for 5mins also.

Actually the whole expression needs to be true for 5min, which includes 77 being on and the sensors being safe.

So when the lamp is turned on it will start counting 5mins (given that the sensors are safe already)

it seems to work different, just like i said, below debug after switch turned on remotelly:

 

#ppSwiatloOn

00:00:01/2/115:on
#ppRuch
00:00:01/2/115:on & 163:safe

 

 

[DEBUG] 21.03.2020 11:35:08: true: 115:on

[DEBUG] 21.03.2020 11:35:08: true: 115:on & 163:safe

[DEBUG] 21.03.2020 11:35:10: true(00:00:01): 115:on => customEvent:ppSwiatloOn

[DEBUG] 21.03.2020 11:35:10: true(00:00:01): 115:on & 163:safe => customEvent:ppRuch

Link to comment
Share on other sites

  • 0
7 minutes ago, michal85pl said:

it seems to work different, just like i said, below debug after switch turned on remotelly:

 

#ppSwiatloOn

00:00:01/2/115:on
#ppRuch
00:00:01/2/115:on & 163:safe

 

 

[DEBUG] 21.03.2020 11:35:08: true: 115:on

[DEBUG] 21.03.2020 11:35:08: true: 115:on & 163:safe

[DEBUG] 21.03.2020 11:35:10: true(00:00:01): 115:on => customEvent:ppSwiatloOn

[DEBUG] 21.03.2020 11:35:10: true(00:00:01): 115:on & 163:safe => customEvent:ppRuch

Yes, but the on/safe period is only 1s? And it's on/safe for 1s and sends the event

Please login or register to see this code.

(actually 2s because that is the specified interval it checks the test ../2/..)

Give it 5min and see if it waits for 5min (or at least a bit longer than 1s)

Please login or register to see this code.

 

Edited by jgab
Link to comment
Share on other sites

  • 0
2 minuty temu, jgab napisał:

Yes, but the on/safe period is only 1s? And it's on/safe for 1s and sends the event

Please login or register to see this code.

(actually 2s because that is the specified interval ../2/..)

Give it 5min and see if it waits for 5min (or at least a bit longer than 1s)

Please login or register to see this code.

 

of course You're right...sorry for my oversight

Link to comment
Share on other sites

  • 0
13 minutes ago, michal85pl said:

of course You're right...sorry for my oversight

 

No problems, 

and you're right. It should be a function that is part of the standard conditions test for scenes.

Link to comment
Share on other sites

  • 0
1 hour ago, jgab said:

 

No problems, 

and you're right. It should be a function that is part of the standard conditions test for scenes.

Made a small improvement to stateWatcher.

value=R00:05/2/88:on

A starting 'R' (as in 'Repeat') indicates that the rule should continue to fire events every 5min the expression is true.

Normally, the expression has to become false before it starts to watch for true again.

Good to have if you want to have notification and reminders if a door/window is left open.

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