How to run this LUA code every 15 minutes within day / time restrictions?

I have a TKB TZ77 RGBW controller which is pretty rubbish to be honest. I don’t know if its the module itself or Vera’s control over it but its not great and has issues.

However I have created several Vera scenes that each change the colour of the connected LED RGBW strip.

I then found this code on the forum for randomising running scenes. So random colours in my case.

local scenes = {"172", "173", "174", "175", "176", "271", "272"}
local tmp_random_number = math.random(1,7)
local  scene_id_to_launch = scenes[tmp_random_number]
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = scene_id_to_launch}, 0)

This code works fine and randomly runs my change colour scenes.

The LED strip has an On / Off schedule in PLEG.

“Schedule - Turns on the front garden LED lights every Friday Saturday Sunday after sunset +2 hours”

And I have an off schedule set for 00:30 am.

So whilst this LED strip is turned on according to its schedule, I’d like to run the above Lua code every 15 minutes to change the colour randomly.

I’m not sure how to set this up in PLEG. or via another scene with script.

In PLEG there are counters which I have never used or understood before. I can however create a new counter and start that counter when my turn on LED strip schedule is run.

Ordinal Counter:

Time Counter:

What is the value 161.47726893425? Using a Unix time convertor they are all 1st of Jan 1970. Yet the date is correct on my Vera unit when I SSH in and issue the “date” command. So not sure what time stamp that is meant to be on the counter in PLEG ?

But I am not sure about the PLEG Condition syntax to use to monitor that counter for when it reaches every 15 minutes. Counters are not covered in the PLEG basics user manual.

Any other ideas ?

Thanks.

I’ve got this working using an additional Schedule Timer instead.

When the regular schedule sFrontLEDsOn runs to turn on the LED strip, I am now starting a 30 second timer in that action.

For the condition, if the LED strip is turned On (Switch Device Property = 1) and the timer are both true, then an action runs the LUA code to select a random scene to change the colour.

In this same action, it also restarts the timer after 30 seconds, so it continues and loops.

I never really understood how timers and counters worked in PLEG.

DEVICE PROPETY - Is the switch for the LED strip ON (1) or OFF (0)

SCHEDULE (TIMER) sFrontGardenLEDsTimer

I’ve got it set to 30 seconds at the moment just to test it was working and the colours are changing every 30 seconds currently.

sFrontLEDsOn - is the regular schedule that turns on the LED strip 2 hours after sunset.

and

sFrontLEDsOff - is the regular schedule that turns off the LEDs at 00:30 am.

CONDITION:

Is the switch for the LEDs ON ? and is the timer true ? If both conditions are met, then the condition is true and its action cFronttGardenLEDsRandomColours will be carried out.

ACTION 1:

cFrontLEDsOn

This action turns on the LED light strip and starts the timer

ACTION 2:

cFronttGardenLEDsRandomColours

This action runs the LUA code to randomly start a scene to change the colour of the LED strip and it also restarts the timer every 30 seconds.


It works its changing the colours every 30 seconds by running one of my 7 Vera scenes.

I just need to change the timing for every 15 minutes now etc.

However all of this feels a bit of a hokey way of setting this up.

I am sure I’m likely not using Schedule Timers correctly in PLEG.

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules