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
2 minutes ago, jimicr said:

@robw No problem:

 

You'll have to create the variable manual as standard variable.

Please login or register to see this code.

 

 

Nice, thank's!

 

Link to comment
Share on other sites

  • 0
6 hours ago, jimicr said:

Hi guys, I edited the scene and runs for me (see code below).

I added check against lux, manual override and check if light is on or off all ready.

It runs like a charm but I think the pro's here can clean the code to make it better.

Conditions only check the motion sensor:

 

maybe this helps someone.

 

Jim 

 

I'm sure you've coded everything right, and I'm doing something wrong. But what happens for me is that the light turns on correctly, but it does not turn off. What can I have done wrong? I turned off the original light scene so it should not interfere. By the way, the HomeTable works great!

 

Conditions:

 

{
  conditions = { {
      id = 79,
      isTrigger = true,
      operator = "==",
      property = "value",
      type = "device",
      value = true
   }, {
      isTrigger = false,
      operator = "==",
      property = "sleepstate",
      type = "global-variable",
      value = "false"
    } },
  operator = "all"
}
 
 
Scene:
 
local hc = fibaro
jT = json.decode(hc.getGlobalVariable("HomeTable")) 
 
local light = jT.Bathroom.lamp
local motion = jT.Bathroom.motion
local lux = tonumber(jT.Bathroom.lux)
local luxmin = 75
 
if hc.getValue(light, "state"then state = "On" else state = "Off" end
 
hc.debug("","Current lux: "..hc.getValue(lux,"value"))
if state == "Off" then
if luxmin >= lux then hc.debug("","room to light to turn on  lights")
else
local maxTime = 1*60  -- max time the sensor should be safe before turning off
local sleepTime = 3   -- time in seconds between each check of the sensor
 
if hc.getValue(light,"state") == false then hc.call(light,"turnOn");
hc.debug("","Turning on")  end
 
local safeTime = 0
while safeTime < maxTime do
  hc.sleep(sleepTime*1000)                 
  safeTime=safeTime+sleepTime                   -- count up safeTime
  hc.debug("","Counting up safeTime ",safeTime,maxTime)  
    if hc.getValue(light,"state") == false then hc.debug("","Light turned off manual");
  break end
  if hc.getValue(motion,"value"then -- motion breached
     safeTime=0                                 -- reset safeTime
     hc.debug("","Reset")
  end
end 
  
if hc.getValue(light,"state"then hc.call (light,"turnOff");
hc.debug("","Turning off")  end
end
else hc.debug("","Light manual turned on")
end
hc.debug("","Scene ended")
Edited by robw
Link to comment
Share on other sites

  • 0

@robw Can't find the error in a glance.

Maybe it is the new conditions and your sleepstate is false? Or id=79 is your switch instead of your motion sensor?

Link to comment
Share on other sites

  • 0

@robw, I found an error in my code, line 6 should be: 

local lux = tonumber(hc.getValue(jT.Badkamer.lux, "value"))
 
Editing the code I posted earlier
  • Like 1
Link to comment
Share on other sites

  • 0
14 minutes ago, jimicr said:

@robw, I found an error in my code, line 6 should be: 

local lux = tonumber(hc.getValue(jT.Badkamer.lux, "value"))
 
Editing the code I posted earlier

 

Thank's! I will test again :)

Link to comment
Share on other sites

  • 0
1 minute ago, robw said:

 

Thank's! I will test again :)

And I changed line 14 to:

 
if luxmin < lux then hc.debug("","room to light to turn on  lights")
I had it turned around for testing and forgot to change it back when I posted the scene
Link to comment
Share on other sites

  • 0
28 minutes ago, jimicr said:

And I changed line 14 to:

 
if luxmin < lux then hc.debug("","room to light to turn on  lights")
I had it turned around for testing and forgot to change it back when I posted the scene

Hmmm... Now the light don't turn on. Something is not right, I think:

(load):11: attempt to concatenate a nil value

 

I will check more.

Edited by robw
Link to comment
Share on other sites

  • 0
9 hours ago, petergebruers said:

 

 

Look at the last line of your scene - look carefully at the single quotes... See something strange? No? they are "angled" and that does not work, it causes "unexpected symbol near '<\226>'"

 

Please login or register to see this code.

So fix that line, instead write:

 

Please login or register to see this code.

 

EDIT: forgot to mention... There is onother one to fix on line 8, fibaro.call(light,'turnOn') - check all quotes

 

 

@robw the code with wrong kind of quotes is in your post because you've quoted a version with that error, can you please fix that? Jgab already fixed his version here...

 

 

 

 

 

Great i got it working 1 more question how do i add more light en sensors. i tried the below but does not work.

 
local light = 115,130,150,153,27
local motion = 134

 

  • Like 1
Link to comment
Share on other sites

  • 0
9 hours ago, jimicr said:

@marius de jong like this:

Enjoy coding

 

Jim

 

Sorry, I must have ghosts in my HC3. The new code does not turn off the light(s). A proposal also (I'm not a coder), would be to check if there is motion before running the scene. If not - don't turn on the light when starting the scene. Could that be done? Thank you Jim and Marius!

 

[DEBUG] 2020-03-10 06:42:17: Turning on

[DEBUG] 2020-03-10 06:42:20: Counting up safeTime 3 60

[DEBUG] 2020-03-10 06:42:20: Light(s) turned off manual

[DEBUG] 2020-03-10 06:42:20: Scene ended

Link to comment
Share on other sites

  • 0

@robw , maybe a long shot:

Remove the sleepstate part from the condition and reboot your HC3.

 

Here the same code runs like supposed too.

 

jim

Link to comment
Share on other sites

  • 0
42 minutes ago, jimicr said:

@robw , maybe a long shot:

Remove the sleepstate part from the condition and reboot your HC3.

 

Here the same code runs like supposed too.

 

jim

 

 

I'm sorry, it does not work for me. It turns on the light, but not off. I've uncommented the sleepstate in the triggers section. I have only one light, so I use:

    local light = {jT.Bathroom.bathroomlamp}
 
Log:

[DEBUG] 2020-03-10 10:25:43: Current lux: 486.0

[DEBUG] 2020-03-10 10:25:43: minlux: 500

[DEBUG] 2020-03-10 10:25:43: Turning on

[DEBUG] 2020-03-10 10:25:46: Counting up safeTime 5 60

[DEBUG] 2020-03-10 10:25:46: Reset

[DEBUG] 2020-03-10 10:25:46: Counting up safeTime 3 60

[DEBUG] 2020-03-10 10:25:46: Light(s) turned off manual

[DEBUG] 2020-03-10 10:25:46: Scene ended

 

Don't know what I'm doing wrong here, but I wil look further. I'm no coder, thought.

Note: If I change "Allow to restart a running scene" back and forth, I can see in the logs that it counts up Safetime. But it still does not turn off the light.

Link to comment
Share on other sites

  • 0

Is your light a dimmer?

A dimmier might require different code to turn off.

I only have a double switch and a Aeotec MS6 connected to my HC3 atm.

 

I'm not a coder too, I work with a lot of trail and error to get things working.

 

Jim

 

Link to comment
Share on other sites

  • 0
1 hour ago, jimicr said:

Is your light a dimmer?

A dimmier might require different code to turn off.

I only have a double switch and a Aeotec MS6 connected to my HC3 atm.

 

I'm not a coder too, I work with a lot of trail and error to get things working.

 

Jim

 

 

 

No, it is a Hue light. I'm stumped, and, I'm lousy at coding - trying to get a hang of it though on the HC3, I want to learn.

 

As an example, this code works:

 

        Trigger section:

 

{
  conditions = { {
      id = 79,
      isTrigger = true,
      operator = "==",
      property = "value",
      type = "device",
      value = true
    }, {
      id = 81,
      isTrigger = false,
      operator = "<=",
      property = "value",
      type = "device",
      value = 100
    }, {
      isTrigger = false,
      operator = "==",
      property = "sleepstate",
      type = "global-variable",
      value = "false"
    } },
  operator = "all"
}
 
 
        Lua section:
 
local light = 52
local motion = 79
 
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")
fibaro.call(light,'turnOn')
fibaro.call(light,'setValue'90)
 
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

Ah you should have told me sooner it wasn't a switch ;)

But no worries, try setting the value to "0" instead of "turnOff"

Please login or register to see this code.

Hope this solves your problem

 

Jim

Link to comment
Share on other sites

  • 0
1 hour ago, jimicr said:

Ah you should have told me sooner it wasn't a switch ;)

But no worries, try setting the value to "0" instead of "turnOff"

Please login or register to see this code.

Hope this solves your problem

 

Jim

 

The code that I had above here, with fibaro.call(light,'turnOff', works.

 

Should I change like this in your example?

 

function turnoff()
  if #light > 0 then
    for i = 1, #light
    do
        if hc.getValue(light,"state"then hc.call(light,"setValue"0);
        hc.debug("","Turning off");
        hc.sleep(100end
    end
    end
end
 
I tested that, but unfortunately it did not work. The light don't turn off.
Link to comment
Share on other sites

  • 0

@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

  • Like 1
Link to comment
Share on other sites

  • 0
1 hour 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

Thank's Jim! I will test in the morning. I'll get back here and tell how it went. Thank you for all help!!

Link to comment
Share on other sites

  • 0
23 hours ago, jimicr said:

@marius de jong like this:

Please login or register to see this code.

Enjoy coding

 

Jim

I still don't understand howe to add more lights en sensors. i got 5 lamps and 3 sensors do i add them to the scene or to the hometable? and howe do i add them?

Link to comment
Share on other sites

  • 0

@marius de jong your lights go in here:

Please login or register to see this code.

can also be {10, 20, 30} --> your light ID numbers.

I havent tuned the scene for more than one motion sensor.

 

Jim

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