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

what´s wrong with my LUA script?


Question

Posted

Hi all,

I really would need your help. I have a keyfob with 4 keys. If key 1 is pushed a global variable is set to "On" that triggers a scene to arm some window sensors. If key 3 is pushed this global variable is set to "Off" that triggers a scene to disarm these sensors. For the first time it seems to work as expected but all following pushes (doesn´t matter if 1 or 3) don´t set the global variables accordingly and therefore arming and disarming doesn´t work. Do I have to "close" or "end" this LUA based scene anyhow at the end? Or is something else wrong?

here is my code:

--[[

%% properties

133 sceneActivation

%% globals

--]]

local id= 133; -- Doppeltaster

local name = fibaro:getName(id);

fibaro:debug(name);

ActiveSceneId =tonumber(fibaro:getValue(id, "sceneActivation"));

fibaro:debug(ActiveSceneId);

if ( tonumber(fibaro:getValue(id, "sceneActivation")) == 11)

-- button 1, single press - Activate AlarmModus Stufe 1

then

fibaro:setGlobal("AlarmModus", "An");

fibaro:setGlobal("AlarmModusStufe1", "An");

end

if ( tonumber(fibaro:getValue(id, "sceneActivation")) == 31)

-- button 3, single press - Deactivate AlarmModus Stufe 1

then

fibaro:setGlobal("AlarmModus", "Aus");

fibaro:setGlobal("AlarmModusStufe1", "Aus")

end

local alarmModus = fibaro:getGlobalValue("AlarmModus");

fibaro:debug(alarmModus);

local alarmModusStufe1 = fibaro:getGlobalValue("AlarmModusStufe1");

fibaro:debug(alarmModusStufe1);

thanks and cheers,

alkorsi

4 answers to this question

Recommended Posts

  • 0
Posted

Can you post some debug output please?

  • 0
  • Inquirer
  • Posted

    from the debugging point of view it seems ok but the global variables are not set reliable and thus the dependent scenes are not triggered accordingly

    here is the debugging result where it worked:

    [DEBUG] 20:59:29: Fernbedienung1

    [DEBUG] 20:59:29: 11

    [DEBUG] 20:59:29: An

    [DEBUG] 20:59:29: An

    [DEBUG] 20:59:29: Aus

    [DEBUG] 20:59:52: Fernbedienung1

    [DEBUG] 20:59:52: 31

    [DEBUG] 20:59:52: Aus

    [DEBUG] 20:59:52: Aus

    [DEBUG] 20:59:52: Aus

    But sometimes I can push a button and nothing happens and then you cannot see anything in the debugging panel!

    Do I have to use some countScenes with abort?

    thanks!

    alkorsi

    • 0
    Posted

    You'll often see "countScenes with abort" but it isn't always necessary or desirable. I put it in a scene when I know that it is OK that my scene *misses* a trigger. Judging from your question I'd say you haven't experimented with triggers... When a devices is triggered a scene starts. When the trigger occurs again, while the first scene is still running, a second instance will be started. Since HC2 scripting is fast, you may not have noticed it. To experiment I suggest you put a fibaro:sleep(10000) at the end of your code so you have plenty of time to cause a second trigger... But that was not you question

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Your observation that "you cannot see anything in the debugging panel" points in the direction of a communication problem, faulty device or bug. I have a few suggestions.

    If you own a Fibaro door/windows sensor, you can attach a push button. Then by altering the last parameter you can have sceneActivation so you can run comparable code to see if it happens with this device too...

    If you post the exact make and model of your key fob, maybe other forum members can help you... I have a Aeon minimote but that is a different device.

    What firmware version are you on?

    Are you using never ending code, like "while true ... end" constructs? Do they have sleep time?

    Wait... it wasn't until I triple checked your log that I saw why you say it's a problem with global variables... Maybe there are two issues.

    Like you suggested yourself... put this code at the top and see if you get the debug output:

    if (fibaro:countScenes() > 1) then fibaro:debug("scene already active")

    fibaro:abort() end

    If so, then you key fob sends sceneActivation commands faster than you can process.

    • 0
  • Inquirer
  • Posted

    Hi petergebruers,

    Thanks for your input! I will try it and see what´s happen

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    cheers,

    alkorsi

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