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

All off switch at the front door.


Question

Guest David R
Posted

Hello I am completely new to Fibaro and LUA and was wondering how to do an all off switch at the front door. At the minute I have it as a relay s2 activating a scene if its either switched on or off with a momentary switch. I made the scene using blocks as I am still just started out learning LUA but here it is in LUA.

%% properties

76 value

%% globals

--]]

local startSource = fibaro:getSourceTrigger();

if (

( tonumber(fibaro:getValue(76, "value")) > 0 ) --if turned on--

or

( tonumber(fibaro:getValue(76, "value")) == 0 ) --or if turned off--

or

startSource["type"] == "other"

)

then

setTimeout(function()

fibaro:call(62, "turnOff");

end, 2000)

setTimeout(function()

fibaro:call(60, "turnOff");

end, 4000)

setTimeout(function()

fibaro:call(49, "turnOff");

fibaro:call(70, "turnOff");

end, 6000)

setTimeout(function()

fibaro:call(58, "turnOff");

end, 8000)

setTimeout(function()

fibaro:call(56, "turnOff");

fibaro:call(64, "turnOff");

fibaro:call(66, "turnOff");

end, 10000)

setTimeout(function()

fibaro:call(51, "turnOff");

end, 12000)

setTimeout(function()

fibaro:call(14, "turnOff");

end, 14000)

setTimeout(function()

fibaro:call(9, "turnOff");

fibaro:call(11, "turnOff");

fibaro:call(16, "turnOff");

end, 16000)

setTimeout(function()

fibaro:call(6, "turnOff");

fibaro:call(19, "turnOff");

fibaro:call(36, "turnOff");

fibaro:call(40, "turnOff");

end, 18000)

setTimeout(function()

fibaro:call(44, "turnOff");

end, 24000)

end

Is there a better way to do this so I don't have to have on or off? Just activate scene. Remember im completely new so go easy and everybody has to learn somewhere

Please login or register to see this image.

/emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

Thanks

6 answers to this question

Recommended Posts

  • 0
Posted

I use sceneActivation for this.

Put all your switch off commands in a scene (without the delay). Jot down the ID

Please login or register to see this image.

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

Then create another scene with the code below. Change 196 to the device ID of your front door switch and the startScene ID with the one you prepared above.

(If you do it this way, you can reuse the scene with another sceneActivation, without copying over a stack of code)

Please login or register to see this code.

Also enable the scene activation parameter (for the dimmers it's 41) for the device. If you own a pulse switch, things are a little more convenient, but it should work with momentary switches.

  • 0
Guest David R
  • Inquirer
  • Posted

    Ill try this later thanks!! :->

    • 0
    Posted

    Hey David,

    Quick and dirty tip for applying the same command to multiple devices:

    Please login or register to see this code.

    What this does is drops your device IDs into an array, and then initiates a loop that sends the relevant command to each device one after the other. You can then add as many (or few) devices into that array as you like.

    This is basically the same as doing multiple duplicate lines like this:

    Please login or register to see this code.

    But just more efficiently.

    Hope this helps!

    Dan

    [ Added: 2014-10-18, 12:39 ]

    Just noticed your support ticket as well - I'll post my reply here if you don't mind? That way others can benefit...

    The error you're getting is because you're trying to call 2 devices in a single function:

    Please login or register to see this code.

    You can't do that, you need a line per device, like this:

    Please login or register to see this code.

    Or, use the method I described above.

    Cheers,

    Dan

    • 0
    Guest David R
  • Inquirer
  • Posted

    Thanks Dan

    What I want to do is go round room one by one turning off the appliances one by one at one second intervals. Am I right thinking I have to fibaro:sleep (1000) between each id.

    • 0
    Posted

    Hey David,

    Sure, just need to add a sleep. Something like this:

    Please login or register to see this code.

    That will turn off each of the devices in the array with a 1 second gap between each one.

    Dan

    [ Added: 2014-10-18, 13:37 ]

    Actually one thing to consider is that the order that items get returned from the pairs() function is not defined, even for indexed tables.

    What this means in practice is that the devices won't turn off in any consistent order.

    Is that something you specifically require? My whole house off uses this, because in practice I don't care what order they go off in, the important part is that they all go off.

    • 0
    Guest David R
  • Inquirer
  • Posted

    Hey Dan. I was after a little bit of order room by room finishing with the hall so ill guess ill have to put in order manually. Thanks for the tip though! Ive now come to make a timer for the bathroom fan and thought I would use your example but change the ids to mine. It doesn't work though? Error line 6

    --[[

    %% properties

    127 value

    %% globals

    --]]

    local lightID = 127 -- change in the trigger if you change it here

    local fanID = 139

    local fanDelay = 2 * 60 -- 2 minutes (the value is in seconds)

    -- Only allow one instance of the current scene to run at a time

    if (fibaro:countScenes() > 1) then

    fibaro:abort()

    end

    local value, timestamp = fibaro:get(lightID, "value")

    if (value == '0') then -- is the light off?

    -- the light has been turned off

    -- keep looping until the light has been off for 2 minutes

    while ((value ~= '0') or ((os.time() - timestamp) < fanDelay)) do

    fibaro:sleep(1000) -- let other things happen for a second, just wait here

    value, timestamp = fibaro:get(lightID, "value")

    end

    -- the light has been off for long enough now.

    fibaro:call(fanID, "turnOff") -- turn off the fan

    else

    -- the light has been turned on

    fibaro:call(fanID, "turnOn") -- turn on the fan

    end

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