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
5 hours ago, SmartHomeEddy said:

You have two motion sensors, how does this line looks in your code?

 

Please login or register to see this code.

 

Or can you share the code you are actually using? 

 

 

 

 

Hi, SmartHomeEddy,
Below is the original scene I'm using today.
A. Motion sensor 1 OR motion sensor 2 violated AND Lux <300 turns main room light on (ID 35).
B. After the 1 minute timeout in a safe state of the motion sensor (no motion detected), the scene verifies that the garage and laundry lights are on. In this case, if they are lit, the main room light will remain ON.
C. Now, if the garage and laundry lights are off, the scene also turns off the main room light.

what i would like to do......

1. any of the 2 violated motion sensors (motion detected);
2. Turns on the lights in the Main Room (ID 35), Garage (ID 69) and Laundry (ID 70).
3. after counting the safe time, the scene turns off the light in the main room, but keeps the previous state of the garage and laundry lights (on or off), that is, if these lights were already on before the start of the scene , they will remain lit. ... .. otherwise, Cena turns them off too ...... 

 

thanks,

 

 

{
  conditions = { {
      id = 170,
      isTrigger = true, -- Motion 1
      operator = "==",
      property = "value",
      type = "device",
      value = true
      }, {
      id = 190,
      isTrigger = true, -- Motion 2
      operator = "==",
      property = "value",
      type = "device",
      value = true
      
      }, {
      id = 172,   -- LUX
      isTrigger = false,
      operator = "<=",
      property = "value",
      type = "device",
      value = 300,
          } },
  operator = "any"
}
--------------------------------

local light = {35} -- ID's the main room light
local motion = {170,190} -- ID's the Motions
local lux = {172, 192} -- ID's the Lux
local maxTime = 1*60  -- max safe time
local sleepTime = 5 -- check interval (default = 5)
local debug_TAG = "Lights Timer" -- Tag for the debug messages
 
for i in pairs(light) do -- Turn On main room light
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 lux level at the moment(LUX)
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 max time reached
fibaro.sleep(sleepTime*1000)                 
safeTime=safeTime+sleepTime 
fibaro.debug(debug_TAG," Counting safe time " ..safeTime .." para maxTime " ..maxTime)

for i in pairs(motion) do 

if fibaro.getValue(motion[i],"value") then -- Check se Motion violado(s)
fibaro.debug(debug_TAG,"Reset o Motion sensor " ..motion[i] .." " ..fibaro.getName(motion[i]))
safeTime = 0 -- Reset safeTime 
        end
    end
end 
if fibaro.getValue (69, 'value') or fibaro.getValue (70, 'value') then
fibaro.debug(debug_TAG, "leave the lights on") -- garage and laundry lights IDs (69, 70)

else
for i in pairs(light) do
fibaro.debug(debug_TAG, " Turning off  " ..light[i] .." " ..fibaro.getName(light[i]))
fibaro.call(light[i],"turnOff") -- main room light
end
end

Link to comment
Share on other sites

  • 0

I thinks this will do the job

 

When running the code, first it will check if the Garage and Laundry lights are on. If both lights are on, they won't be turned off is there is no more motion. 

 

 

Please login or register to see this code.

 

 

 

Edited by SmartHomeEddy
Link to comment
Share on other sites

  • 0
On 7/2/2021 at 2:53 AM, SmartHomeEddy said:

I thinks this will do the job

 

When running the code, first it will check if the Garage and Laundry lights are on. If both lights are on, they won't be turned off is there is no more motion. 

 

 

Please login or register to see this code.

 

 

 

 

 

Hello SmartHomeEddy,
I was only able to test the Scene today, it is reporting the error below:
on line 14 that refers to:

14 - if fibaro.getValue(lightlit1) and fibaro.getValue(lightlit2) then
 

Please login or register to see this image.

/monthly_2021_07/image.png.db134569d1ba8ee19d8a9b6013a42557.png" />
 
 
 
Link to comment
Share on other sites

  • 0

Can you replace the line with

 

if fibaro.getValue(lightlit1,”value”) and fibaro.getValue(lightlit2,”value”) then

Link to comment
Share on other sites

  • 0
20 minutes ago, SmartHomeEddy said:

Você pode substituir a linha por

 

if fibaro.getValue (lightlit1, ”valor”) e fibaro.getValue (lightlit2, ”value”) então

Works perfect ......thanks so much [email protected]'m so happy......thanks for the help!

Link to comment
Share on other sites

  • 0
12 minutes ago, SmartHomeEddy said:

?

SmartHomeEddy@,

Forgive me, a question came to me now using the scene in practice: if the laundry light was already "off" and the garage light "on" or vice versa, how to keep them that way instead of turning them on or off them always together?

Link to comment
Share on other sites

  • 0

In this script the Garage and Laundry lights are handles separately. The script is actually more simple, in the if-elseif-end it checks which lights are already on and excludes them from the "light" variable to turn on and off the light. I think this should do the job. 

 

Please login or register to see this code.

 

Edited by SmartHomeEddy
Link to comment
Share on other sites

  • 0

Don't have much todo today either :-)

 

I'm a big fan of abstractions, and when expressing an algorithm it's nice to create abstract functions for turning on or checking devices instead of calling fibaro.* every time. If you have an isON(device) function that works it also minimise the risk that you forget to add that second "value" parameter when you use the fibaro.getValue(x,"value") for the nth time...

If we have a NAME(dev) function that returns the name we want to print in the log for a device (here <ID>:<name>) we can easily change that function if we would like to log <name>:<ID> instead.

etc.

 

It also tends to keep the code size down (at least the main part) and create a better overview of the logic of the algorithm/code.

 

So, here's an example on how to code the above example without changing the flow/logic.

 

Please login or register to see this code.

 

  • Like 1
Link to comment
Share on other sites

  • 0
5 hours ago, SmartHomeEddy said:

In this script the Garage and Laundry lights are handles separately. The script is actually more simple, in the if-elseif-end it checks which lights are already on and excludes them from the "light" variable to turn on and off the light. I think this should do the job. 

 

Please login or register to see this code.

 

 

 

SmartHomeEddy@,

 

The scene works, only this error message appears every time the scene resets the time count.......but it still works normal after...

Please login or register to see this image.

/monthly_2021_07/image.png.74feff301c98908c096e599c4e43486f.png" />

 

I also noticed that when the motion sensor timer is reset due to a new detected motion, before reaching the safe time, the scene saves the new "status" of the light. In this situation (new movement detected during the execution of the scene) the Lights never go out... is it possible to work around this situation? in order to maintain the original status of the lights?
thank you so much...

Link to comment
Share on other sites

  • 0
5 hours ago, jgab said:

Don't have much todo today either :-)

 

I'm a big fan of abstractions, and when expressing an algorithm it's nice to create abstract functions for turning on or checking devices instead of calling fibaro.* every time. If you have an isON(device) function that works it also minimise the risk that you forget to add that second "value" parameter when you use the fibaro.getValue(x,"value") for the nth time...

If we have a NAME(dev) function that returns the name we want to print in the log for a device (here <ID>:<name>) we can easily change that function if we would like to log <name>:<ID> instead.

etc.

 

It also tends to keep the code size down (at least the main part) and create a better overview of the logic of the algorithm/code.

 

So, here's an example on how to code the above example without changing the flow/logic.

 

Please login or register to see this code.

 

 

jgab@,

thank you very much for the tips and tricks for the example, please help me with this error that appeared when running Scene.

image.png.49edc8a7e3d32c3aea8c587e82ae8333.png

 

15   local function NAME(dev) return ""..dev..":"..fibaro.getName(ldev) end

Link to comment
Share on other sites

  • 0
32 minutes ago, jorge rintaro said:

 

jgab@,

thank you very much for the tips and tricks for the example, please help me with this error that appeared when running Scene.

Please login or register to see this link.

 

15   local function NAME(dev) return ""..dev..":"..fibaro.getName(ldev) end

Typo. ldev should be dev 

Link to comment
Share on other sites

  • 0
1 hour ago, jorge rintaro said:

The scene works, only this error message appears every time the scene resets the time count.......but it still works normal after...

Please login or register to see this link.


I see some different ID’s in comparison to the code.
Does the version of @jgab give the same error? 

Link to comment
Share on other sites

  • 0
39 minutes ago, SmartHomeEddy said:


I see some different ID’s in comparison to the code.
Does the version of @jgab give the same error? 

Hello, SmartHomeEddy@,
I just tested the @Scene jgab, it didn't show this error...
this error in your scene appears only when the scene is stopped (time count restart) new motion detected during the timer.
but even with the error it still works after ......
in the Scene indicated by jgab @ Scene also presents the same situation that I explained about the condition of the lights on or off initially ..... if the motion sensor is violated during the execution of the scene it resets the timer and considers the original state of lights ALL on... ...because actually, when the new instance started, they were on... I don't know how it would be possible to get around that.......

SmartHomeEddy@,

complementing....the IDs were changed just for testing, I used the same IDs in the Scene of jgab @......they are correct in relation to their respective devices/functions (lights, motions and Luxs)

thanks

Link to comment
Share on other sites

  • 0

I think, hope, this setting will do the trick

 

Please login or register to see this image.

/monthly_2021_07/42C26278-1B9A-410F-944C-AADB3D68CC0E.jpeg.e1761e58e6b1fe2a351acf6583928132.jpeg" />

 

Allow to restart a running scene: No

 

(I think this one also triggers the error)

 

 

 

 

 

Edited by SmartHomeEddy
Link to comment
Share on other sites

  • 0
5 hours ago, SmartHomeEddy said:

Eu acho, espero, que esta configuração funcione

 

Please login or register to see this link.

 

Permitir reiniciar uma cena em execução: Não

 

 

thank you very much, it worked perfect ....
a lot of learning for me these days .... grateful.

Link to comment
Share on other sites

  • 0
On 04/07/2021 at 05:23, jgab said:

Não tenho muito o que fazer hoje também :-)

 

Sou um grande fã de abstrações e, ao expressar um algoritmo, é bom criar funções abstratas para ligar ou verificar dispositivos em vez de chamar fibaro. * Todas as vezes. Se você tem uma função isON (dispositivo) que funciona, também minimiza o risco de você se esquecer de adicionar o segundo parâmetro de "valor" ao usar fibaro.getValue (x, "valor") pela enésima vez ...

Se tivermos uma função NAME (dev) que retorna o nome que queremos imprimir no log de um dispositivo (aqui <ID>: <name>), podemos facilmente alterar essa função se quisermos registrar <name>: < ID> em vez disso.

etc.

 

Também tende a manter o tamanho do código baixo (pelo menos a parte principal) e a criar uma visão geral melhor da lógica do algoritmo / código.

 

Portanto, aqui está um exemplo de como codificar o exemplo acima sem alterar o fluxo / lógica.

 

Please login or register to see this code.

jgab@, please......if instead of motion sensor I use door and window sensor... what needs to be changed in Scene? thanks

 

Link to comment
Share on other sites

  • 0
2 minutes ago, jorge rintaro said:

 

Nothing, as all binary sensors return true when opened/breached and false if closed/safe

Link to comment
Share on other sites

  • 0
11 minutes ago, jgab said:

Nada, pois todos os sensores binários retornam verdadeiro quando aberto / violado e falso se fechado / seguro

@jgab, thanks ...... had forgotten to change the IDs in the "CONDITIONS" .... so it wasn't working .... now everything is OK... grateful

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