Author Topic: Conditional Scene Execution: Some Examples  (Read 186134 times)

Offline zedrally

  • Hero Member
  • *****
  • Posts: 945
  • Karma: +3/-1
  • Black Cat Controllers & Control Systems
    • Black Cat Control Systems
Re: Conditional Scene Execution: Some Examples
« Reply #270 on: November 05, 2017, 10:11:55 pm »
There is no benefit of one vs the other.
You already have LUA code .. so it's up to you.

Richard,
What would this look like in PLEG?
The similarity to my awning problem is striking and could be the solution I was looking for.
Living in the Land of Oz, give me a vegemite sandwich. Home Seer, Vera Lite & Edge, Popp, Black Cat Smart Hub & Vera G, Black Cat Lite 1 & 2's a Black Cat Dimmer or 2, then some  Black Cat Cat's Eye PIR's & Door-Window Sensors, Broadlink RMPro & Mini plus a Z-UNO or 2.

Online RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9922
  • Karma: +749/-141
    • RTS Services Plugins
Re: Conditional Scene Execution: Some Examples
« Reply #271 on: November 05, 2017, 11:06:47 pm »
Input
LightLevel        Current Light Level

Schedule
NextStepTimer            On - Self Trigger, Off After 30 sec interval
OffTimer                    On - Self Trigger, Off after 30 minutes

Condition
Start                  What every you use to start this (i.e. some Multi-Switch turns on
KeepGoing          (Start; !NextStepTimer) and !NextStepTimer and (LightLevel > 5) and (LightLevel <= 25)
AllOff                  (Start;OffTimer) and (LightLevel == 5)

Actions:
Start                  - Set light to 25 %    and trigger NextStepTimer with an interval of 30 and trigger OffTimer with an interval of 30:00
KeepGoing           Set Light to  {(LightLevel - 1}} and  trigger NextStepTimer with an interval of 30
AllOff                   Turn Off Light


NOTE: THis works even if Vera is reloaded!!!
With this code ... if you manually change the light > 25 ... this will disable the logic. You will have to retrigger the Start condition.

Offline babgvant

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #272 on: November 17, 2017, 11:14:28 am »

For triggers:
   1) If Trigger LUA exists, run it, if it returns FALSE then stop,  otherwise (TRUE, or nothing returned) continue.
   2) If Scene LUA exists, run it, if it returns FALSE then stop, otherwise (TRUE, or nothing returned) continue.
   3) Run Actions (Immediate and delayed)

For Manual and Schedule started scenes, skip step 1.


Is 2 the highlighted section

Online RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9922
  • Karma: +749/-141
    • RTS Services Plugins
Re: Conditional Scene Execution: Some Examples
« Reply #273 on: November 17, 2017, 03:43:19 pm »
Yes!

I think MCV left out the ability for LUA on triggers like they did in UI5 ....
But the runtime still supports it. (i.e. Scenes migrated from UI5 to UI7 that used this feature still work).

I have not looked to see if AltUI provides scene definition with this ability.


Offline babgvant

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #274 on: November 17, 2017, 04:14:44 pm »
Yes!

I think MCV left out the ability for LUA on triggers like they did in UI5 ....
But the runtime still supports it. (i.e. Scenes migrated from UI5 to UI7 that used this feature still work).

I have not looked to see if AltUI provides scene definition with this ability.

Thank you

Offline whited

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #275 on: December 18, 2017, 10:29:37 am »
Hi,
I am trying to execute my irrigation every other day at 3am. I am running UI5. I believe there are several ways to go about this.
I have first attempted in modifying your code and plugging it in to startup luup without success.
Code: [Select]
-- Schedule irrigation (Scene#94) every other day at 3am.
local tStart = "03:00"   -- Start watering
local tDelay = 48        -- Delay until next time watered in hours
local hS, mS = string.match(tStart,"(%d+):(%d+)")
local mStart = (hS * 60) + mS
local tNow = os.date("*t")
local mNow = (tNow.hour * 60) + tNow.min
local varD94 = 0
local lastHourD94 = 0
if (tNow.hour ~= lastHourD94) then
varD94 = varD94 + 1
lastHourD94 = tNow.hour
end
if ((varD94 >= tDelay) and (mNow >= mStart)) then
varD94 = 0
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", { SceneNum= "94"}, 0)
end
I then tried allowing the scene scheduled to run every day at 3am then added luup code within the scene to return false every other time. This attempt was successful when triggering the scene manually but when run through the schedule, it never gets executed.
Code: [Select]
-- Bypass scene every other day
if (everyOtherDayScene94 == 0) then
everyOtherDayScene94 = 1
else
everyOtherDayScene94 = 0
return false
end

Online RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9922
  • Karma: +749/-141
    • RTS Services Plugins
Re: Conditional Scene Execution: Some Examples
« Reply #276 on: December 18, 2017, 11:31:02 pm »
Your assuming your Vera does not restart ...
Every time it does ... the next time it evaluates:
      (everyOtherDayScene94 == 0)

This will be false ... because  everyOtherDayScene94 is undefined.
So it will skip ... and if Vera restarts the next day ... it will skip again.
If you really want schedule/timer reliability ... you should use PLEG

Offline whited

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #277 on: December 19, 2017, 10:14:34 am »
Richard,
I agree with you 100% about vera restarting and having an undefined value.
What if I somehow used luup.variable_set?

I found this link addressing the memory problem that you and Rex discussed:
http://forum.micasaverde.com/index.php/topic,17791.0.html

I am still working on a solution.

Offline whited

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #278 on: December 19, 2017, 11:00:46 am »
Can a variable be saved in eePROM or to usb memory stick?

Offline whited

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #279 on: December 19, 2017, 06:16:11 pm »
I believe I may have solved my problem. I like to keep my system with minimal apps so I found one I am currently using called MultiString.
It is a variable container. I changed my code to this:
Code: [Select]
-- Bypass scene every other day
local value = luup.variable_get("urn:upnp-org:serviceId:VContainer1", "Variable5", YourDeviceID) or "0"
if (value == "0") then
luup.variable_set("urn:upnp-org:serviceId:VContainer1", "Variable5", "1", YourDeviceID)
else
luup.variable_set("urn:upnp-org:serviceId:VContainer1", "Variable5", "0", YourDeviceID)
return false
end
I have tested it by rebooting my Vera3 and the value in Variable5 doesn't change, which is a good thing!
I will keep you informed if it doesn't work after a few days. :o