We have moved at community.getvera.com

Author Topic: Scheduled events?  (Read 5784 times)

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Scheduled events?
« on: May 02, 2010, 12:00:39 am »
I would like to do the following:
"check at 8am and 11pm: if door is open do something (send notification)"

What is the best way to schedule such a thing?
The usual way - every call sets timer for the next one - seems to me somewhat unreliable for large periods of time between the calls... Is there a way to set permanent schedule like we have in scenes?

guest4690

  • Guest
Re: Scheduled events?
« Reply #1 on: May 02, 2010, 01:06:56 am »
The usual way - every call sets timer for the next one - seems to me somewhat unreliable for large periods of time between the calls... Is there a way to set permanent schedule like we have in scenes?

Well, for something like that, i would just do a scene.

for things a little more complex, initiated from Lua code, i think the best is to not only set the timer, but also save the next scheduled time on a device variable and check it in the startup function (and reschedule if necessary).

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Scheduled events?
« Reply #2 on: May 04, 2010, 12:24:43 am »
What are my options for sending notifications here?
The idea is to check, by timer, if the door is open - notify user.
Can I trigger an event from Luup scene to trigger SMS/email?

guest4690

  • Guest
Re: Scheduled events?
« Reply #3 on: May 04, 2010, 12:35:34 am »
What are my options for sending notifications here?

the easiest is to have a scene do the notifications.  You can either fire the scene from Lua (with luup.call_action()), or use a timer to fire and Lua to prevent.

The idea is to check, by timer, if the door is open - notify user.
Can I trigger an event from Luup scene to trigger SMS/email?

I'd just set the scene to notify the user, have it run by the timer, and in Lua:

Code: [Select]
-- don't fire if door is closed
if variable_get(.....doorstatus) == '0' then
    return false
end

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Scheduled events?
« Reply #4 on: May 04, 2010, 12:48:04 am »
I only see "Notify user" options under events, not scenes.
Could you elaborate how to setup notifications on a scene, without event?
Or... am I missing something?

Offline woodsby

  • Beta Testers
  • Sr. Member
  • *****
  • Posts: 466
  • Karma: +1/-0
Re: Scheduled events?
« Reply #5 on: May 04, 2010, 04:35:18 pm »
I'd like to know the same thing... or even how to send notifications using lua/luup, if that's possible.
Vera1 (1.1142), Vera2 (1.1182), VRI06 (12), VRS15 (3), VRS05 (2), VRF01 (2), VRCS4 (2), ZRW113, ZRF113 (2), 45602, 45603, TZMT400 (2), FE599 (2), 99100, Thinkstick, Harmony 890Pro (2), Harmony RF Extender, Nevo S70, Nevo NC-50, Minimote, SQ Remote, SQ Blaster, EtherRain-8, Cliste ActiveRFID, TED5002

guest4690

  • Guest
Re: Scheduled events?
« Reply #6 on: May 04, 2010, 11:00:08 pm »
I only see "Notify user" options under events, not scenes.
Could you elaborate how to setup notifications on a scene, without event?
Or... am I missing something?

You're right, i had it totally mixed up (not the first time...)  Currently notifications are only on events, either those on a Scene, or directly on a device (for those that implement the 'Notifications' panel)

There's no direct Luup API call to send a notification; but it's simple to make an event fire: just set the associated variable to an appropriate value.

If you're developing a device plugin, you can define a variable and event type just for this use, and in your Lua code simply change the variable's value.  Just like a security sensor works.

If your Lua code isn't tied to a specific device, you could create a sensor, or a binary switch device and link an event to it.  then again, just change the device's variable from Lua.

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Scheduled events?
« Reply #7 on: May 04, 2010, 11:07:23 pm »
Right... and how do we trigger an email using that variable?..

guest4690

  • Guest
Re: Scheduled events?
« Reply #8 on: May 04, 2010, 11:17:30 pm »
I'm not sure if i understand your question; but, this is what i'd do for your example of checking a door at certain hour:

- create a dummy device.  say, a smoke sensor.
- set a notification on that sensor.
- create a scene with a timer, to fire at the required hour
- add Lua code to the scene, there check the lock.  if it's open, set the "Tripped" variable of the sensor.  if not, just return false.

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Scheduled events?
« Reply #9 on: May 05, 2010, 10:59:51 pm »
Let's say I set an event on that dummy sensor.
Is there a minimum time required between Tripped=1 and then Tripped=0 to trigger an event, or I can reset Tripped immediately?

guest4690

  • Guest
Re: Scheduled events?
« Reply #10 on: May 05, 2010, 11:14:20 pm »
Let's say I set an event on that dummy sensor.
Is there a minimum time required between Tripped=1 and then Tripped=0 to trigger an event, or I can reset Tripped immediately?

The very act of changing the variable immediately fires any related event, before the control returns to the calling Lua code.  note that that's only the 'firing' of the event, the execution occurs on a different thread, so by the time the event is executed, the variable might be back a "0".  But the event check and execution uses the 'previous' and 'new' values registered at the variable change, so in theory it should work.

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Scheduled events?
« Reply #11 on: May 08, 2010, 01:30:54 pm »
All Notifications from that dummy sensor are failed. Logic is correct, I see the attempt to send notification as expected, but they all failed
Successfully submited ticket:  2269

Offline 325xi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1101
  • Karma: +0/-0
  • V1, V2, still V2...
Re: Scheduled events?
« Reply #12 on: May 19, 2010, 11:14:03 am »
So, notifications work but incredibly inconsistently.

I eventually set Vera to send me Twitter's direct messages and it work perfectly - getting stable tweet (email or SMS) every 20 minutes, just as asked :)