We have moved at community.getvera.com

Author Topic: run a trigger only during a range of time.  (Read 1882 times)

Offline 4vera

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
run a trigger only during a range of time.
« on: February 26, 2014, 09:02:26 am »
Enjoying my new vera and happy I?ve found this forum.
I?m using vera alerts for when the garage or back door opens it plays a sound on my android device upstairs.  That?s working fine.  What I?m trying to do is to only play the sound during the hours of 8am to 10pm (so I don?t wake up the family if I leave early).  I can?t seem to find a way to do this.  Can some provide some thoughts on how to make this happen, if I have to use ?code?, samples would be greatly appreciated.
Thanks again


Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: run a trigger only during a range of time.
« Reply #1 on: February 26, 2014, 09:28:50 am »
Take a look at Conditional Scene Execution. It includes an example that does just what you want.

When you get to more advanced automation, you would find the Program Logic Event Generator (PLEG) plugin a great help. See PLEG Basics for an introduction.

Offline 4vera

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: run a trigger only during a range of time.
« Reply #2 on: February 26, 2014, 10:04:04 am »
perfect! thanks!

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: run a trigger only during a range of time.
« Reply #3 on: February 26, 2014, 10:37:21 am »
In case it isn't clear, this is how you could achieve a time-limit for your Vera Alerts:

Create a Vera scene that is triggered by the door being opened. Add Lua code that only allows the scene to run when you want (see examples) to the scene's Luup tab. Add a SendAlert action to the scene for your Vera Alerts device.

Offline 4vera

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: run a trigger only during a range of time.
« Reply #4 on: February 26, 2014, 05:38:10 pm »
I must still be missing something..
pasted in this code under the LUUP tab on the scene, but still sends alert at 17:30, just tested

local pStart = "07:30"   -- Start of time period
local pEnd = "21:00"     -- End of time period
local allow = false       -- true runs scene during period, false blocks it
local hS, mS = string.match(pStart,"(%d+)%:(%d+)")
local mStart = (hS * 60) + mS
local hE, mE = string.match(pEnd,"(%d+)%:(%d+)")
local mEnd = (hE * 60) + mE
local tNow = os.date("*t")
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
     return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
     return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

Is there a place I can get some docs on lua coding and how it works, admin/user guide?  It looks like it's pretty powerful but I need some kick starting :)
Thanks agian
« Last Edit: February 26, 2014, 05:40:31 pm by 4vera »

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: run a trigger only during a range of time.
« Reply #5 on: February 26, 2014, 06:12:20 pm »
Quote
I must still be missing something..
pasted in this code under the LUUP tab on the scene, but still sends alert at 17:30, just tested
Did you remove the original trigger for Vera Alerts? The Luup code will only block actions from the scene in which you placed it.

Quote
Is there a place I can get some docs on lua coding and how it works?
The best starting place is Programming in Lua. There are some downloadable pdfs out there but buying the book helps to fund Lua development.

Offline 4vera

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: run a trigger only during a range of time.
« Reply #6 on: February 26, 2014, 08:13:02 pm »
Sorry for the novice questioning,
The only trigger I have for Vera Alerts is within the scene where I have the luup code.  When you mentioned
"Add a SendAlert action to the scene for your Vera Alerts device." do you mean a trigger in the scene, or something else?

Again thanks for your patience, book is on order.  Just hope i have enough basic understanding for it to be useful ;)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: run a trigger only during a range of time.
« Reply #7 on: February 27, 2014, 12:35:11 am »
Sorry for the novice questioning,
The only trigger I have for Vera Alerts is within the scene where I have the luup code.  When you mentioned
"Add a SendAlert action to the scene for your Vera Alerts device." do you mean a trigger in the scene, or something else?

Again thanks for your patience, book is on order.  Just hope i have enough basic understanding for it to be useful ;)
I just re-read your post:
Quote
I must still be missing something..
pasted in this code under the LUUP tab on the scene, but still sends alert at 17:30, just tested
The Lua code is set to allow the alert between 07:30 and 21:00 so it should work at 17:30. Change the start and end times to suit your requirements.