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

Howto triggercontinous/time based command and by event/change of device state


rsjabbens

Question

Hi all,

 

I have a script to send a message when my garage door is opend / closed. Because the door is doing a close/open/close when closed i needed something to prevent sending multiple messages. 

This is working, however the counter i have is not reset, so i changed a bit, but now i guess i need to have some loop to validate if it is closed for more than 60 seconds to reset some counters and prevent the counters for only adding 1 when opening/closing the door.

 

How can the scene be triggered by a open/close, such as it already works now, and in addition a time validation/loop when the door is closed for more then 60 seconds to reset the counters? 

Ideally i want to add when the door is open for more than x minutes to receive some reminder, but this can be added later.

 

Any help is appriciated.

 

The script i created is added below.

 

Kind regards,

Roland

 

Please login or register to see this code.

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Here is a functional LUA scene for my Home Center 3 that is just a proof of concept for something I am working on that is only outputting messages in console window, maybe you can make it suit your needs. I am not really clear on what you want but this creates an object, sets some values and it is passed to a function(set of functions). It will wait and check periodically for conditions and ultimately expires.

 

The fine points to consider are handling multiple simultaneous scene executions. There may be better event based methods but I am not sure that's what you are after.

 

hub.debug("====================================================================================================""")
hub.debug("BEGIN SCENE - BEGIN SCENE - BEGIN SCENE - BEGIN SCENE - BEGIN SCENE - BEGIN SCENE - BEGIN SCENE""")
hub.debug("====================================================================================================""")
 
hub.debug("BEGIN FUNCTIONS""")
 
function waitForSleepingTimer(sleepingTimer)
    local timerStartTime = os.time()
    local timerEndTime = timerStartTime + sleepingTimer.timerDurationInSeconds
    sleepingTimer.iterations = sleepingTimer.iterations + 1
    
    notify("waitForSleepingTimer starting...")
    while sleepingTimer.timerIsValid do
        local currentTime = os.time()
 
        if isTimeElapsed(currentTime, timerEndTime) then
                sleepingTimer.timerIsValid = false
                notify(sleepingTimer.timerMessage)
                notify("sleepingTimer.iterations:"..sleepingTimer.iterations)
            break    
        elseif isThereEnoughTimeForSleep(currentTime, timerEndTime, sleepingTimer.sleepDurationInSeconds) then
            sleepThenNotify(sleepingTimer.sleepDurationInSeconds, sleepingTimer.sleepMessageFullDuration)
        else
            local remainingSleep = getRemainingSleep(currentTime, timerEndTime, sleepingTimer.sleepDurationInSeconds)
            sleepThenNotify(remainingSleep, sleepingTimer.sleepMessagePartialDuration)
        end
    end
 
    notify("waitForSleepingTimer completed.")
    return sleepingTimer
end
 
function isTimeElapsed(currentTime, endTime)
    return currentTime >= endTime
end
 
function isThereEnoughTimeForSleep(currentTime, endTime, sleepDurationInSeconds)
    return currentTime + sleepDurationInSeconds < endTime
end
 
function getRemainingSleep(currentTime, endTime)
    return endTime - currentTime
end
 
function sleepThenNotify(durationInSeconds, notificationMessage)
    hub.sleep(durationInSeconds * 1000)
    notify(notificationMessage)
    return
end
 
function notify(notificationMessage)
    hub.debug("MESSAGE", notificationMessage)
end
 
hub.debug("BEGIN MAIN CODE EXECUTION""")
 
local sleepingTimer = {}
sleepingTimer.timerDurationInSeconds = 10 -- how long to wait in total seconds for the timer to complete
sleepingTimer.sleepDurationInSeconds = 3 -- how long to wait in seconds before interrupting sleep and test conditions
sleepingTimer.timerIsValid = true -- assuming the timer is good to go from the get-go
sleepingTimer.timerMessage = "Timer Complete!" -- show this once the timer has fully completed
sleepingTimer.sleepMessageFullDuration = "Waking from sleep and checking conditions (Full Sleep Duration)" -- show this every sleep cycle we wake up in order to test conditions
sleepingTimer.sleepMessagePartialDuration = "Waking from sleep and checking conditions (Partial Sleep Duration)"-- potentially show this on the last sleep cycle
sleepingTimer.iterations = 0 -- We can reuse the object and keep track of how many times we have done so, etc...
 
-- we run this twice and can see the iterations increment. but we have to set timerIsValid = true each time we reuse it. 
hub.debug("MESSAGE""Lets try this timer")
hub.debug("MESSAGE""--------------------------------------------------")
sleepingTimer = waitForSleepingTimer(sleepingTimer)
hub.debug("MESSAGE""--------------------------------------------------")
 
hub.debug("MESSAGE""Lets try this timer again")
hub.debug("MESSAGE""--------------------------------------------------")
sleepingTimer.timerIsValid = true
sleepingTimer = waitForSleepingTimer(sleepingTimer)
hub.debug("MESSAGE""--------------------------------------------------")
 
hub.debug("====================================================================================================""")
hub.debug("END SCENE - END SCENE - END SCENE - END SCENE - END SCENE - END SCENE - END SCENE - END SCENE""")
hub.debug("====================================================================================================""")
Edited by RedRocketFire
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...