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

%% killOtherInstances


Question

Posted

Where to put into the code  %% killOtherInstances ?

 

My motion sensor generates more instances by detecting movement, I´d like to kill older instances by this

below is lua code for turning off wall plug when motion sensor is safe 30 seconds…

Ive putted it on the beggining it doesnt works

Thanks

 

--[[
%% properties
21 value
%% weather
%% events
%% globals
--]]

local startSource = fibaro:getSourceTrigger();
if(startSource["type"] == "other") then
    fibaro:call(8, "turnOff");
else
if (( tonumber(fibaro:getValue(21, "value")) == 0 )) then
setTimeout(function()
local delayedCheck0 = false;
local tempDeviceState0, deviceLastModification0 = fibaro:get(21, "value");
if (( tonumber(fibaro:getValue(21, "value")) == 0 ) and (os.time() - deviceLastModification0) >= 30) then
    delayedCheck0 = true;
end

local startSource = fibaro:getSourceTrigger();
if (
 ( delayedCheck0 == true )
or
startSource["type"] == "other"
)
then
    fibaro:call(8, "turnOff");
end
end, 30000)
end
end
 

 

12 answers to this question

Recommended Posts

  • 0
Posted (edited)

Usually before %% properties

I mean in your case it should look  like this:

--[[

%% killOtherInstances
%% properties
21 value
%% weather
%% events
%% globals
--]]

 

Please remember that new scene instance will kill all other previous instances. Means only the last instance could run.

May I suggest to  make this scene automatic and to remove the trigger "21 value".

That way your scene will run constantly as one instance and if you need more things to track you can add it here as well.

Edited by cag014
  • 0
Posted

Please login or register to see this code.

This is one of many possible implementations. Works for me.

Here I can set LUX device to consider

Also the Auto-OFF is disabled, when the main light (one of 2) is ON. This is the way i handle the undesired light OFF (sometimes it happen when no motion for a sleep time,, and its annoying)

 

  • 0
Posted

To my opinion all these scenes could be replaced by very simple scene (or VD main loop)  without so many triggers and instances (unnecessary CPU and RAM load)..... I have just one VD that controls all timeouts and other time depended actions.

But as you said - there are many possible implementations.

  • 0
Posted
6 minutes ago, cag014 said:

To my opinion all these scenes could be replaced by very simple scene (or VD main loop

Yes, possible. I have no chance to try the so-called single scene event model

I hope to do it soon and then to compare my expirience

  • 0
Posted

Great... take a look on Virtual Device (main loop) possibility as well.

  • 0
Posted
7 minutes ago, cag014 said:

Great... take a look on Virtual Device (main loop) possibility as well.

There is still some problems running LUA VD on my current HCL mod. This is for HC2 users only for now.

  • 0
  • Inquirer
  • Posted
    4 hours ago, cag014 said:

    Usually before %% properties

    I mean in your case it should look  like this:

    --[[

    %% killOtherInstances
    %% properties
    21 value
    %% weather
    %% events
    %% globals
    --]]

     

    Please remember that new scene instance will kill all other previous instances. Means only the last instance could run.

    May I suggest to  make this scene automatic and to remove the trigger "21 value".

    That way your scene will run constantly as one instance and if you need more things to track you can add it here as well.

    Thank you

    the trigger is SAFE on Fibaro motion sensor /no movement detected/ then 30 sec count . this trigger i dont want to delete

    problem is that if movement detected during that 30 sec another and another scenes begin, and there is problem with maximum running instances

    I hope it will work, i did block scene, transfered it to lua code and added %% killOtherInstances, but it seems that is not ok, i will try again, here is whole code ... is it OK please ? Thank you very much

     

    --[[
    %% killOtherInstances
    %% properties
    21 value
    %% weather
    %% events
    %% globals
    --]]

    local startSource = fibaro:getSourceTrigger();
    if(startSource["type"] == "other") then
        fibaro:call(8, "turnOff");
    else
    if (( tonumber(fibaro:getValue(21, "value")) == 0 )) then
    setTimeout(function()
    local delayedCheck0 = false;
    local tempDeviceState0, deviceLastModification0 = fibaro:get(21, "value");
    if (( tonumber(fibaro:getValue(21, "value")) == 0 ) and (os.time() - deviceLastModification0) >= 300) then
        delayedCheck0 = true;
    end

    local startSource = fibaro:getSourceTrigger();
    if (
     ( delayedCheck0 == true )
    or
    startSource["type"] == "other"
    )
    then
        fibaro:call(8, "turnOff");
    end    
    end, 22000)
    end
    end
     

     

    • 0
    Posted

    Could you please add follow line and remove %% killOtherInstances

    if fibaro:countScenes() > 1 then fibaro:abort() end

    local startSource = fibaro:getSourceTrigger();
    if(startSource["type"] == "other") then
        fibaro:call(8, "turnOff");
    else

    .....

     

    I should keep just one scene instance.

    • 0
  • Inquirer
  • Posted
    4 minutes ago, cag014 said:

    Could you please add follow line and remove %% killOtherInstances

    if fibaro:countScenes() > 1 then fibaro:abort() end

    local startSource = fibaro:getSourceTrigger();
    if(startSource["type"] == "other") then
        fibaro:call(8, "turnOff");
    else

    .....

     

    I should keep just one scene instance.

    Thank you

    but it works now perfectly with the same code as i mentioned /code was wrongly typed into Fibaro HC2 i think/

    i do not want to abort the last instance, but kepp last and abort previous so I need killotherinstances

    • 0
    Posted

    Great... glad to hear that the code is up and running.

    by the way it makes no different which instance is running....

    • 0
  • Inquirer
  • Posted
    3 hours ago, cag014 said:

    Great... glad to hear that the code is up and running.

    by the way it makes no different which instance is running....

    do you think it is no difference ?

     

    first instance counts 300 second from last movement in the room to switch wall plug off

    then i move again etc. after 100 seconds and I want to restart countdown. it needs i think to stop previous sentence/countdown and not to stop actuall new countdown/sentence

    i´m maybe wrong, i do not know how lua code works exactly

    • 0
    Posted

    According to your code ( end, 30000) ) It "counts" 30 seconds only.

    So after 30 seconds the scene checks following condition

            if (( tonumber(fibaro:getValue(21, "value")) == 0 ) and (os.time() - deviceLastModification0) >= 30) then

    If it's not true, it "counts" 30 seconds again and again... till the condition is true

    As you can see it doesn't matter which instance is running.

    Please pay attention that your light will go off, after sensor is safe, between 30 to 60 seconds. Depends when sensor turned safe.

    In order to reduce this margin you need to decrease the timeout

    for example :

    timeout of 15 seconds gives range of 30 to 45 seconds

    timeout of 10 seconds gives range of 30 to 40 seconds

    ....

    timeout of 1 second gives range of 30 to 31 seconds

     

    But probably this is a minor issue.

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