Author Topic: Writing a scene to endlessly loop Action  (Read 2652 times)

Offline Vera3newbie

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Writing a scene to endlessly loop Action
« on: January 18, 2015, 01:19:23 am »
I have been with my Vera 3 for about 2 years now, but put it down besides basic turning various lights on/off in my house.  I came back to it last month only to have a totally new user interface.  I had this scene in the old version which essentially did a set of actions over and over indefinitely.  I am having a hard time trying to mimic that request for the new UI for Vera.  I am running Version1.7.388 . 

Can anybody help me with my request for a simple unlimited repeater at the end of the scene, essentially looping the scene over and over and over and over again?


Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Writing a scene to endlessly loop Action
« Reply #1 on: January 18, 2015, 04:10:27 am »
What does the repeated scene do? Does it use Luup code or just normal device actions with delays? How did you get it to loop previously?

Offline Vera3newbie

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: Writing a scene to endlessly loop Action
« Reply #2 on: January 18, 2015, 09:46:47 am »
It uses just normal device actions with delays.  Here is the logic I had last time for the old UI:

Scene 1 Turn on x and after y minutes Turn OFF - Trigger when x turns  ON

Scene 2 Turn off x and after y minutes Turn ON - Trigger when x Turns OFF


The old UI wasn't as user friendly as the newer one, but i'm still having issues setting up this infinite loop...

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: Writing a scene to endlessly loop Action
« Reply #3 on: January 18, 2015, 01:02:49 pm »
You know your infinite loop will stop if Vera is Restarted ... you will have to manually trigger the switch to get it started again.

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Writing a scene to endlessly loop Action
« Reply #4 on: January 18, 2015, 02:07:15 pm »
Richard is right - this would not survive a restart.

The most robust way to achieve this would be using the Program Logic Event Generator (PLEG) plugin. PLEG automatically restarts its timers if Vera restarts.

If you want to do it using scenes, you could try triggering a scene with a schedule for every y minutes and adding Lua code to toggle the device state. This would not be as precise as PLEG following a restart but it should at least self-start.

Offline Vera3newbie

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: Writing a scene to endlessly loop Action
« Reply #5 on: January 19, 2015, 09:41:12 am »
At this point, I have to babysit the Vera and every few hours I re-trigger the device which runs the scene to make sure it runs correctly.... I know there has to be a more robust way through code and setting things up to make it solid and reliable.  *sigh*

I know zero about LUA Code, looks like i'll have to start diving into it and get a better understanding.  Wish we could just go back to the simpler UI :)


Thanks for responding Guys, its appreciated.

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Writing a scene to endlessly loop Action
« Reply #6 on: January 19, 2015, 09:50:21 am »
The following code, placed in the Luup tab of a scene, will toggle the state of Z-Wave switch device number 123 every time it is run. Change the first line to match your actual device number. The scene does not require any device actions to be selected.

If the device you are controlling is not a Z-Wave switch, let us know what it is and we can give you the appropriate code.

Code: [Select]
local dID = 123           -- Device ID of your Z-Wave Switch
local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",dID)
 if status == "1" then
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue=0},dID)
 else
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue=1},dID)
 end

If you create a trigger for the scene with an appropriate periodic (interval) schedule, it should save you having to babysit your Vera.

Offline Vera3newbie

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: Writing a scene to endlessly loop Action
« Reply #7 on: January 21, 2015, 12:19:06 pm »
Thanks for the code, I will input and see how it reacts.  Is there an Editor I can download for the Luup language? 

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Writing a scene to endlessly loop Action
« Reply #8 on: January 21, 2015, 01:21:02 pm »
Quote
Is there an Editor I can download for the Luup language?

You can use any text editor. Notepad++ is very good and free.

If you want something that can test your code, there are a few choices:

Lua for Windows will run on your PC. It is good for basic Lua but does not support Vera's luup functions. It is free.

ZeroBrane Studio for Vera is a powerful Integrated Development Environment for Lua. It runs on Windows or MAC but runs your Lua code directly on Vera so it supports the luup functions and can see your devices. It is excellent but requires a paid licence.

LuaTest runs on Vera and provides simple editing functions and the ability to test code directly in the same environment as scene Lua code. It isn't a patch on ZeroBrane but it is designed specifically to create and debug code for scenes. Disclosure: I wrote it.