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!



Smart Home Forum by FIBARO Team

  • 0

Comparing dates...




I've got a (hopefully!) simple request for help!

I'd like to have a Lua scene triggered when a motion sensor activates, which turns a light on and stores the current date/time in a global variable "LastActivatedTime"

I'd like another Lua scene that activates every 1 minute that checks the date/time stored in the global variable "LastActivatedTime" and, if that time if greater than 15 minutes from now, turns off the light.

The bit I'm confused about is how I should store a date/time in a global variable, and how I can read that date/time out of a global variable and back to a Lua date object...

Thanks in advance for your help!!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
Guest Kuuno

this script does what you want probably

create global variable wc_endtimer or your own and change it in the script


%% properties

12 value

445 value

%% globals



local endtime = os.time() + 180 -- +3 minutes



fibaro:setGlobal("wc_endtimer", endtime) --global variable that is always changed when PIR breached

fibaro:debug("EndTime = " .. fibaro:getGlobalValue("wc_endtimer"))

if (fibaro:countScenes() > 1)

then fibaro:abort()

fibaro:debug("aborting dup. scene")

end --exit after another breach

local startSource = fibaro:getSourceTrigger();

if tonumber(fibaro:getValue(12, "value")) == 0


( tonumber(fibaro:getValue(445, "value")) > 0 )


startSource["type"] == "other"


time = os.time()

fibaro:call(12, "turnOn")


while time < tonumber(fibaro:getGlobalValue("wc_endtimer")) do

time = os.time()

fibaro:sleep(10000) --the lower number the better precision

fibaro:debug("Time till off = " ..time-fibaro:getGlobalValue("wc_endtimer"))



fibaro:call(12, "turnOff");

fibaro:debug("Lights off")


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.

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