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

Lua code for changing state?


Question

Posted

Hi

I use a Relay switch 2x1,5 to execute some scenes in my house from a double switch. I have set it to "momentery switch" to turn switch on/ off on both switches, and want to ( in one of the scene's ) to turn off some ligths in the house by pushing it, but in block scenes I don't get the change state option. ( I get the "change state" in magic scenes ). So if the lights are "on" and the switch is "off" I have to push the button twice... When i look at it in LUA I see that it the state is "0" then the scene is executed, but how can i set the parameter to "change state" instead?

 

It looks like this:

 

--[[
%% properties
80 value
%% globals
--]]

local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getValue(80, "value")) == 0 ) <------- This is the parameter i want to edit to "change state" instead
or
startSource["type"] == "other"
)
then
    fibaro:call(58, "turnOff");
    fibaro:call(52, "turnOff");
    fibaro:call(50, "turnOff");
    fibaro:call(56, "turnOff");
    fibaro:call(54, "turnOff");
    fibaro:call(68, "turnOff");
    fibaro:call(31, "turnOff");
    fibaro:call(25, "turnOff");
    fibaro:call(44, "turnOff");
    fibaro:call(27, "turnOff");
end
 

 

Thanks!

 

-KH

4 answers to this question

Recommended Posts

  • 0
Posted

Just remove the IF condition. As You will want to run the scene every time it is called, without exceptions. So just use this: 

 

--[[
%% properties
80 value
%% globals
--]]


fibaro:call(58, "turnOff");
fibaro:call(52, "turnOff");
fibaro:call(50, "turnOff");
fibaro:call(56, "turnOff");
fibaro:call(54, "turnOff");
fibaro:call(68, "turnOff");
fibaro:call(31, "turnOff");
fibaro:call(25, "turnOff");
fibaro:call(44, "turnOff");
fibaro:call(27, "turnOff");

  • 0
  • Inquirer
  • Posted

    Thanks! I tried using your code without the IF condition, and it worked if I ran it from the computer, but when I used the switches it turned off / on one or two times then it randomly set at on or off at the different dimmers.

    Tried changing:

    Parameter 13

    State Change (ON / OFF) for toggle switch (Parameter no.14). Default Setting: key position change = ON or OFF

     

    But the same problem..

    Not sure what is wrong?

    -KH

    • 0
    Posted

    The above scene does not turn on any lights. So if you have lights turning on at button press, then something else is causing that. Have you perhaps set up any group associations for the relay that could be trying to interact with lights directly?

    • 0
  • Inquirer
  • Posted

    Ok.. I think I know the problem, but I don't know how to fix it. I have made two scenes, House ON and House OFF.

    What I want is that the same switch ( ID 80 ) turns all lights in the house off, and by pushing the button again turns On "all" lights.

     

    Look under. I think if I combine them in one scene all will be perfect? Can you please help me?

     

    Lights on:

    -------------------------

    --[[
    %% properties
    80 value
    %% globals
    --]]

    local startSource = fibaro:getSourceTrigger();
    if (
     ( tonumber(fibaro:getValue(80, "value")) > 0 )
    or
    startSource["type"] == "other"
    )
    then
        fibaro:call(58, "turnOn");
        fibaro:call(52, "turnOn");
        fibaro:call(50, "turnOn");
        fibaro:call(56, "turnOn");
        fibaro:call(31, "turnOn");
        fibaro:call(44, "setValue", "50");
        fibaro:call(27, "turnOn");
    end

     

     

    Lights OFF:
    -----------------------------

    --[[
    %% properties
    80 value
    %% globals
    --]]

    local startSource = fibaro:getSourceTrigger();
    if (
     ( tonumber(fibaro:getValue(80, "value")) == 0 )
    or
    startSource["type"] == "other"
    )
    then
        fibaro:call(58, "turnOff");
        fibaro:call(52, "turnOff");
        fibaro:call(50, "turnOff");
        fibaro:call(56, "turnOff");
        fibaro:call(54, "turnOff");
        fibaro:call(68, "turnOff");
        fibaro:call(31, "turnOff");
        fibaro:call(25, "turnOff");
        fibaro:call(44, "turnOff");
        fibaro:call(27, "turnOff");
    end
     

    --------------------------

     

    Thanks!

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