Scheduled events?

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?

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

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?

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

[quote=“325xi, post:3, topic:165885”]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?[/quote]

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

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

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?

I’d like to know the same thing… or even how to send notifications using lua/luup, if that’s possible.

[quote=“325xi, post:5, topic:165885”]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?[/quote]

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.

Right… and how do we trigger an email using that variable?..

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.

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?

[quote=“325xi, post:10, topic:165885”]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?[/quote]

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.

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

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 :slight_smile: