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

[SOLVED]Scene - turn on only once at a specific time


wojtas810

Question

Hello

 

I need to create a scene that will be every day in the morning between 7.30 and 9.30 checking if the motion detector is violated, if so it will trigger some reaction, but only once a day.

Therefore, it is definitely necessary to make a variable that will change the value after the violation from 0 to 1

Unfortunately, my beginnings with Lua are difficult if anyone could help me to sort it out to start working?

 

--[[
%% properties
%% events
%% globals
--]]
if fibaro:countScenes() > 1 then 
 fibaro:debug("SCENE ABORT --------------------------") 
end

function toMinutes(czasHHMM) 
local a 
if type(czasHHMM) => "07:30"
if type(czasHHMM) =< "09:30"

end 
      then 
      fibaro:setGlobal("rano", "0") 
      else 
      fibaro:setGlobal("rano", "1") 
    end 
  
fibaro:sleep(60*1000) 
    
end 

Link to comment
Share on other sites

Recommended Posts

  • 0

Please login or register to see this code.

 

Edited by 10der
Link to comment
Share on other sites

  • 0
18 minutes ago, wojtas810 said:

and can I ask a small description . :)

done

btw, is code for "motion detector is violated" should di provide too?

:D

here is my sample code for newcomers.

 

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thank you very much, I added a motion sensor to the start.
    but something does not work because I do not write :) hello after the move :(
    Of course, instead of saying hello, I would like to throw in a welcome note from Sonos in the morning - but first I would like it to work once in the appointed hours on the motion sensor :)

    Will you help my friend?

     

     

    --[[
    %% properties
    %% events
    %% globals
    %% autostart
    17 value
    17 armed
    --]]

    local startSource = fibaro:getSourceTrigger();
    if (
     ( (tonumber(fibaro:getValue(17, "value")) > 0 and tonumber(fibaro:getValue(17, "armed")) == 0) )
    or
    startSource["type"] == "other"
    )
    then
    function between(str)
          -- get current time
        local t = os.date("*t", os.time())
          -- grep input params and separate on hh mm start and hh mm end
        local h1,m1,h2,m2 = str:match("(%d+):(%d+)-(%d+):(%d+)")
          -- some magic - pure mathematics.
        m1, m2, t = h1*60+m1, h2*60+m2, t.hour*60+t.min
          -- check possible variants
        if (m1 <= m2) then
          return m1 <= t and t <= m2 -- 01:00-02:00
        else
          return m1 <= t or t <= m2 -- 23:00-21:00
        end
    end


    -- not executed by default
    local executed = false

    -- infinity loop
    while true do
        -- check is period active
          if between("22:00-22:30") then -- yes active
            -- if not executed
            if not executed then
                  -- just do it
                print("Hello!")
                  -- set what we already executed in this period.
                  executed = true
              end
        else -- not active 
            -- propbably we exit from work period
            -- mask as not executed and waiting for next hop
            executed = false
        end

          -- every 1 min
        fibaro:sleep(1000 * 60);
    end
      end
     

    Link to comment
    Share on other sites

    • 0

    I am sorry, are looking attached post?!!!

     

    PS: do not use any params at header when your use  infinity loop

    no print here

    just click on link

    Edited by 10der
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I act so but unfortunately, a lamp lights up every movement.
    and if I had just implemented that it has to read something once in a while - it will do it every time it detects motion and lights turns on

    Link to comment
    Share on other sites

    • 0
    58 minutes ago, wojtas810 said:

    I act so but unfortunately, a lamp lights up every movement.
    and if I had just implemented that it has to read something once in a while - it will do it every time it detects motion and lights turns on

     

    so. as I can understand you won't turn off lamp automatically, right? 

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I am including - but something else.
    I need to do this properly. :)
    in the morning I go down the sensor detects me between 7.00 - 8.00 am
    the Sonos command is sent.
    read about it through TTS - what is the weather outside. - I know how to dress :)
    and I turn on the radio by calling the button.
    But I need it to be turned on once...

    Link to comment
    Share on other sites

    • 0

    simple: Save action datetime to Global params and check before

    IMHO that really simple 

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I'm just trying to do it but my adventure with the lua is just the beginning.
    no, it does not really come to me, that's why I'm trying to advise you here - because I do not have any undertod global params

    Edited by wojtas810
    Link to comment
    Share on other sites

    • 0

    Please login or register to see this image.

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi thanks for your help me 

     

    but i do somthing wrong 

    This is all my scen 

     

     

    --[[
    %% autostart
    %% properties
    17 value
    %% weather
    %% events
    %% globals
    --]]
    local when = tonumber(fibaro:getGlobalValue('I_got_up'))
    local daysfrom = os.difftime(os.time(), when) / (24 * 60 * 60)
    local wholedays = math.floor(daysfrom);
    print(wholedays) -- 0 today > 0 next days
    if wholedays == 0 then
          -- nothing todo
          -- waiting tomorrow
    else
        -- play
        -- save current datetime
        fibaro:setGlobal("I_got_up", os.time())
    end

    local sourceTrigger = fibaro:getSourceTrigger();
    function tempFunc()
    local currentDate = os.date("*t");
    local startSource = fibaro:getSourceTrigger();
    if (
     ( tonumber(fibaro:getValue(17, "value")) > 0  and  (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "15", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "16", "45"))) and (math.floor(os.time()/60)-math.floor(1513438320/60))%10 == 0 )
    )
      
    then     
        fibaro:call(391, "setSlider", "15", "8");
        setTimeout(function()
            fibaro:call(391, "pressButton", "24");
        end, 25000)
        setTimeout(function()
            fibaro:call(391, "pressButton", "7");
        end, 28000)
    end

    setTimeout(tempFunc, 60*1000)
      
    local sid, bid = 391, 28
    local cond = fibaro:getValue(323, "WeatherConditionConverted");
    local tempext = fibaro:getValue(323, "ui.lblTemperature.value"); -- température extérieure
    fibaro:debug ("Temperatura na zewnatrz: "..tempext)
    local degre = string.gsub(tempext, '[,]' , ' degré ')
    local degre = string.gsub(degre, '[.]' , ' degré ')
    local degre = string.gsub(degre, '[-]' , ' moins ')
     
    local currentDate = os.date("*t")
    local jourL = {"Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"}
    local jour = jourL[currentDate.wday]
    fibaro:debug ("Dzień : "..jour)
     
    local moisL = {"styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec",
                   "lipiec", "sierpień", "wrzesień", "pażdziernik", "listopad", "grudzień"}
    local mois = moisL[currentDate.month]
    fibaro:debug ("Miesiąc : "..mois)
     
    local condfr = fibaro:getValue(323, "ui.lblForecast.value");
    if( cond == "clear" ) then condfr = "czyste niebo"; end
    if( cond == "cloudy" ) then condfr = "pochmurnie"; end
    if( cond == "rain" ) then condfr = "deszcz"; end
    if( cond == "snow" ) then condfr = "śnieg"; end
    if( cond == "storm" ) then condfr = "burza"; end
    if( cond == "fog" ) then condfr = "mgła"; end
    fibaro:debug ("Conditions météorologiques : "..condfr)
     
    fibaro:debug ("co mówi TTS ")
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Dzień Dobry Wojku, Kasiu, Zosiu,"..jour .." "..currentDate.day .." "..mois ..
                ". Teraz jest ".. currentDate.hour .." godzina i  ".. currentDate.min .." minut. "..
                "Na zewnątrz termometr ma "..degre ..
                ", a za oknem przewidywana jest  "..condfr ..". ",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "pl-PL",    -- Language: fr-FR
      volume = 40            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid) 
       
      
      
    end
    if (sourceTrigger["type"] == "autostart") then
    tempFunc()
    else

    local currentDate = os.date("*t");
    local startSource = fibaro:getSourceTrigger();
    if (
     ( tonumber(fibaro:getValue(17, "value")) > 0  and  (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "17", "30")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "17", "45"))) )
    or
    startSource["type"] == "other"
    )
    then
        fibaro:call(391, "setSlider", "15", "8");
        setTimeout(function()
            fibaro:call(391, "pressButton", "24");
        end, 25000)
        setTimeout(function()
            fibaro:call(391, "pressButton", "7");
        end, 28000)
    end
        -- play
        -- save current datetime
        fibaro:setGlobal("I_got_up", os.time())
    end  

    Link to comment
    Share on other sites

    • 0
    12 hours ago, wojtas810 said:

    and how will you help? my friends ?

    Dzien dobry!

     

    co nie dziala?

     

     

    Link to comment
    Share on other sites

    • 0
    1 minute ago, wojtas810 said:

    my scene above what I inserted above

     

    so, you propose to me install your scene, understand what is 17 device, buy sonos and debug?

    instead of attending to just provide error or clear say what happens.

     

    thank you understanding.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • sorryi, I did not mean it.

    I used your example.
    I pasted what I'm interested in, i.e. every day between xxx and yy when I detect motion, I want to turn on the sonos radio once - and not repeat it anymore.

    I do not know what I'm doing wrong. because after all, the scene is turned on every time it detects motion.

    sonos works fine.

    but I do something wrong or I do not know anymore.

    That's why I gave you the whole scene - because I thought it would be better

    Link to comment
    Share on other sites

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