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

[SOLVED]Too many instances in a LUA script for a RF keypad. [solved]


Question

Posted

Community,

 

I use a keypad with tags with a Fibaro binary senso to switch mij alarm on and off.

 

Somebody made me a LUA script for that.

When I present a tag the alarm will switch on or off.

 

This is the script:

 

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

local startSource = fibaro:getSourceTrigger();
-- 2 streepjes is commentaar
fibaro:debug(fibaro:getGlobalValue("Alarmstatus"))
if (
 ( tonumber(fibaro:getValue(245, "value")) > 0 )  -- keypad activated
and
 ( fibaro:getGlobalValue("Alarmstatus") == "uit" )
)
then
    fibaro:setGlobal("Alarmstatus", "aan");
elseif (
 ( tonumber(fibaro:getValue(245, "value")) > 0 )  -- keypad activated
and
 ( fibaro:getGlobalValue("Alarmstatus") == "aan" )
)
then
    fibaro:setGlobal("Alarmstatus", "uit");  
  
end


fibaro:debug( fibaro:getValue(245, "value"))
fibaro:debug(fibaro:getGlobalValue("Alarmstatus"))

fibaro:sleep(3500)
fibaro:abort()
 

My problem is that I get "too many instances".

 

I guess I need to include the following line:

 

"maxRunningInstances": 2,

 

But I have no clue how and where.

 

Is there anybody that could and would tell me how to do so?

 

It would be highly appreciated!

Please login or register to see this attachment.

9 answers to this question

Recommended Posts

  • 0
Posted

Hi Rob,

this may help:

there is a sleep command at the end of your code. Likely (but I am not sure) this is to prevent repeated sensing of a tag that’s supposed to be only once.

 

in other words: now that you present your tag, the scripts prevents the alarm from turning on and off because it reads the tag twice. Essentially it waits 3,5 seconds before a new tag is accepted.

 

If this is true, the "too many instances" thing is harmless and even functional. However, it can be annoying. Another way to achieve the same would be to include something like the second example here: 

Please login or register to see this link.

 

In the settings you can then increase the number of allowed instances.

 

let me know if this helps!

J

 

  • 0
  • Inquirer
  • Posted

    Hi J,

     

    Thanks for your reply.

     

    I have tried your suggestion with >1 until >3 but it didn't help.

    Good to hear that it is at least harmless! that makes it allready less annoying :)

     

    Your thoughts about the delay are correct, without this code the alarm switched on and immediately after it switched off.

     

    • 0
    Posted
    6 hours ago, RobVeenis said:

     

    I have tried your suggestion with >1 until >3 but it didn't help.

     

    What exactly do you mean? 

    • 0
  • Inquirer
  • Posted

    I mean that I tried the "count scenes"

    • 0
    Posted

    Can you share your code? With the solution suggested, you should no longer get the notification.

    • 0
  • Inquirer
  • Posted

    3JL,

     

    Here is the code.

     

    --[[
    %% properties
    245 value
    %% weather
    %% events
    %% globals
    --]]
    -- Only allow one instance of the current scene to run at a time
    if (fibaro:countScenes() > 1) then
      fibaro:abort()
    end
    local startSource = fibaro:getSourceTrigger();
    -- 2 streepjes is commentaar
    fibaro:debug(fibaro:getGlobalValue("Alarmstatus"))
    if (
     ( tonumber(fibaro:getValue(245, "value")) > 0 )  -- keypad activated
    and
     ( fibaro:getGlobalValue("Alarmstatus") == "uit" )
    )
    then
        fibaro:setGlobal("Alarmstatus", "aan");
    elseif (
     ( tonumber(fibaro:getValue(245, "value")) > 0 )  -- keypad activated
    and
     ( fibaro:getGlobalValue("Alarmstatus") == "aan" )
    )
    then
        fibaro:setGlobal("Alarmstatus", "uit");  
      
    end

    fibaro:debug( fibaro:getValue(245, "value"))
    fibaro:debug(fibaro:getGlobalValue("Alarmstatus"))
    fibaro:sleep(3500)
    fibaro:abort()

    • 0
    Posted

    @RobVeenes

    Increase the count just below the header to >3

    and raise the number of instances in the scene General tab ( this defaults generally to 2) 

     

    The way it is setup now is allowing only one concurrent scene to execute at any point so if your tag registers twice, it gives you the notification you see ...

     

     

     

     

    • 0
  • Inquirer
  • Posted

    @Autofrank,

     

    Thanks for your suggestion!

     

    At first the problem got worse, increasing the count to 3 and the number of instances to 3 made that the script ran 3 times, switching on, off and on again.

    Scenes based on the status of the alarm were not happy with that so the result was that I had 4 scenes with too many instances instead of one!

     

    But when I put back the count to 1 again and left the number of instances at 3 the whole problem was solved!

     

    Now the script runs once to switch the alarm either on or off and the error message doesn't come back.

     

    Thanks a lot to you and 3JL for your help!

     

    • 0
    Posted

    Great! Happy to be of help :)

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