Author Topic: UI7 vs lua-coding  (Read 277 times)

Offline invenire1

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
UI7 vs lua-coding
« on: August 07, 2018, 12:23:06 pm »
Using UI7 one is able scedule a scene ONCE, specifying a date and time.

Now I've been looking around for hours and I'm not able to find how you can start a scene likewise from LUA.
Example: In scene-1
   calculate new date and time TS
   start scene-2 at calculated date/time TS

My question: can't this be done?
NB: I don't want to use a DELAY whereafter the scene-2 is started IMMEDIATELY.

Online rigpapa

  • Hero Member
  • *****
  • Posts: 674
  • Karma: +101/-1
Re: UI7 vs lua-coding
« Reply #1 on: August 07, 2018, 12:31:57 pm »
The luup.call_timer() function can be used in scene Lua for scene #1 to compute a start time for scene #2 and set a timer to launch it. There's a bit more to it than that, and if you need detail, ask.

Two things, though. When posing questions like this, it's helpful to give us a picture of what you're trying to accomplish overall (e.g. why do you want to do this? what problem are you solving). There's a notion called the X-Y Problem that can often be avoided and give you a better path if we know more about what you're trying to do.

The other caution is that timers in scenes and call_delay/call_timer don't survive Luup restarts, which occur spontaneously and are often idiopathic. That is, you can set a timer, and if Luup restarts while waiting for the set time, your timer is lost and scene 2 will never run. Solving that problem usually requires a more advanced logic solution like Reactor or PLEG.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline akbooer

  • Master Member
  • *******
  • Posts: 6158
  • Karma: +275/-69
  • "Less is more"
Re: UI7 vs lua-coding
« Reply #2 on: August 07, 2018, 01:35:48 pm »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline invenire1

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: UI7 vs lua-coding
« Reply #3 on: August 08, 2018, 06:55:10 am »

- I have scenes for the curtain in my living room
- one for opening
- one for closing
- some stuff to have it closed related to sunset and the maximum time of 21:30
- some stuff to have it opened related to sunrise and a minimum time

I'm just figuring out how in general when the server comes up, how you get the curtain in the right state. One solution:
- have an initialize function started by the Vera-startup-file. The function decides whether to choose the opening function or the closing function
- the opening function opens the curtain and also scedules for a future time the closing function
- the closing function closes the curtain and also scedules for a future time the opening function

But I will start programming this in PLEG in the 'normal' way where closing and opening are seperate and I should try to program the initial state in de startup file. Right?
(I wonder what state PLEG will realise when the server has been down for hours)

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 631
  • Karma: +13/-0
Re: UI7 vs lua-coding
« Reply #4 on: August 08, 2018, 10:24:16 am »
If I was doing this, I would have three scenes: One to open the curtains around Sunrise, one to close the curtains around sunset, and a third to close the curtains at 21:30. If there are problems with attempting to close a already closed curtain, then I would create a Virtual switch that would indicate the state of the curtain (open or closed), and check it in the three scenes before proceeding.

I do not see the reason to have to "schedule" the sunrise or sunset scenes if they are going to run each day anyway. You could add a second Virtual switch that could be used to override (stop) the scenes if you need to keep the curtains closed for some reason.

Like mentioned above, PLEG is the easiest way to accomplish all of this. Also, Virtual switches do survive a Vera reboot.