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

Getting ID of current scene in LUA


Question

Posted

When I set up my initial system way back in 3.X a couple of years ago there was no way of getting the ID of the current scene in LUA, is this still true for 4.090? 

 

fibaro:getSelfId() works for VDs but surely there must be a way of doing the same thing for scenes by now? Hardcoding that type of thing is so 1997.

 

Among other things I wish to kill the current scene using killScenes without hardcoding.

4 answers to this question

Recommended Posts

  • 0
Posted

I have around 60 scenes and never needed that option so I'm curious why you need to get scene ID from LUA code? It make sense to get it for VD because then it is possible to change icon or label etc., but for scene? To stop scene running it is enough to use fibaro:abort(). Can you also explain to me what you mean by hardcoding?

  • 0
  • Inquirer
  • Posted

    I didn't know (or forgot about) fibaro:abort, thanks! Maybe it was added since I made my setup in 3.5X or whatever?

     

    In this case I need to kill all instances of the current scene, fibaro:abort() does not do this.

     

    Another use would be to register the scene running in a global variable for example, interacting with other scenes, VDs and external units on the network. It could be used for making more dynamic and general scenes for many different tasks.

     

    Hardcoding in this example would be:

     

    local thisSceneId = 123;

     

    If you look closer on many of the a bit more advanced scenes posted on this forum you will see scene id hardcoding is frequently used. 

     

    Edit:

    To clarify and give you some context. I have a scene for our coffee maker to turn off after X minutes. A sceneActivation from a dimmer activates the scene when double tapping S2. It starts the "timer" and turns it off after the time is up. See the code below:

    Please login or register to see this code.

    • 0
    Posted

    Please login or register to see this code.

    --[[

    %% properties

    %% events

    %% globals

    --]]

    local id = 5; -- Device id to handle

    local time = 1; -- minutes

    if (tonumber(fibaro:countScenes()) > 1) then

    fibaro:debug("Script already running.");

    fibaro:abort();

    end

    if (fibaro:getValue(id, 'value') == '0') then

    fibaro:debug("Device " .. id .. " will turnOn for " .. time .. " minute(s)");

    fibaro:call(id, 'turnOn');

    fibaro:sleep(time * 60 * 1000);

    fibaro:debug("Device " .. id .. " will turnOff after being on for " .. time .. " minute(s)");

    fibaro:call(id, 'turnOff');

    else

    fibaro:debug("Device " .. id .. " is already on, will now turnOff.");

    fibaro:call(id, 'turnOff');

    end

    • 0
  • Inquirer
  • Posted

    Please login or register to see this code.

    This will not work in the intended way. The script should turn off the device if it is already on. 

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