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

Simple scene and number of running instances?


Question

Posted

I have two simple scenes that should turn on the boiler pumps (528 and 529) if at least one of the valves (941,942 and 943) is open. And another scene that turns off the pumps when all the valves are closed. If I limit these scenes to a single instance-they don't work, why? And is it possible to combine these two scenes?

--[[
%% autostart
%% properties
941 value
942 value
943 value
%% weather
%% events
%% globals
--]]

if fibaro:countScenes()>3 then os.exit()end

local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getValue(941, "value")) > 0 )
or
 ( tonumber(fibaro:getValue(942, "value")) > 0 )
or
 ( tonumber(fibaro:getValue(943, "value")) > 0 )
or
startSource["type"] == "other"
)
then
  fibaro:debug("ON  .....");
    setTimeout(function()
        fibaro:call(528, "turnOn");
    end, 5000)
    setTimeout(function()
        fibaro:call(529, "turnOn");
    end, 10000)
end

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

--[[
%% autostart
%% properties
941 value
942 value
943 value
%% weather
%% events
%% globals
--]]

if fibaro:countScenes()>3 then os.exit()end

local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getValue(941, "value")) == 0 )
and
 ( tonumber(fibaro:getValue(942, "value")) == 0 )
and
 ( tonumber(fibaro:getValue(943, "value")) == 0 )
or
startSource["type"] == "other"
)
then
  fibaro:killScenes(198);
   fibaro:debug("OFF  .....");
    setTimeout(function()
        fibaro:call(529, "turnOff");
    end, 5000)
    setTimeout(function()
        fibaro:call(528, "turnOff");
    end, 10000)
end
 

5 answers to this question

Recommended Posts

  • 0
Posted

remove the unnecessary %% autostart and use the following example code

 

local action = "turnOff"
if tonumber(fibaro:getValue(941, "value")) +
   tonumber(fibaro:getValue(942, "value")) +
   tonumber(fibaro:getValue(943, "value")) > 0 then action = "turnOn"

end

fibaro:call(528, action)
fibaro:call(529, action)

  • Thanks 1
  • 0
  • Inquirer
  • Posted

    This beautiful code works great! Thanks

    Please login or register to see this link.

    !

    How best to organize the delay between fibaro:call(528, action)  and fibaro:call(529, action)

    fibaro:sleep(5000);  or  setTimeout(function() ?

    • 0
    Posted (edited)

    Whatever you like best. Mostly I myself use the fibaro:sleep function.

     

    Example of somewhat more sophisticated coding:

     

    Please login or register to see this code.

     

    Edited by Alex de Bruin
    • Thanks 1
    • 0
  • Inquirer
  • Posted

    Thanks 

    Please login or register to see this link.

    !

    I tried more complex code, but it doesn't work. The pumps are turned on without delay, and the scene is started for as long as it costs in this line 

    Please login or register to see this code.

    Here is my full code

    --[[
    %% autostart
    %% properties
    941 value
    942 value
    943 value
    532 value
    --]]

     

    function getval(valve) return tonumber(fibaro:getValue(valve, "value")) end

    function switch(pump,onoff,wait)
       fibaro:debug(onoff .. " .....")
       fibaro:call(pump, "turn" .. onoff)
       fibaro:sleep(wait * 1000)
    end

    action = "Off"
    if getval(941) + getval(942) + getval(943) > 0 then action = "On" end

    switch(528,action,60)
    switch(529,action,120)

    • 0
    Posted (edited)

    move the call command behind the sleep.
     

    Please login or register to see this code.

     

    Edited by Alex de Bruin
    • Like 1

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