Author Topic: Luup Code Help!  (Read 504 times)

Offline CarsonY101

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Luup Code Help!
« on: March 25, 2018, 06:39:58 pm »
Hello all,

I'm really new to the luup coding.  I'd love to have a scene called "Home Mode" and when it's triggered, if during the day triggers only certain devices via another scene, but if at night, triggers a completely different scene that would include a different set of devices.  I'm pretty sure part of the code would include:

local pStart = 0         -- Start of time period, minutes offset from sunset
local pEnd = 0           -- End of time period, minutes offset from sunrise
local allow = true       -- true runs scene during period, false blocks it
local hS, mS = string.match(pStart,"(%d+)%:(%d+)")
local mStart = math.floor( (luup.sunset() % 86400) / 60 ) + pStart
local mEnd = math.floor( (luup.sunrise() % 86400) / 60 ) + pEnd
local tNow = os.date("*t")
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
     return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
     return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

but where would I put if it matches then: luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="ADD_SCENE_NUMBER"},0)

and if it doesn't then: luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="ADD_SCENE_NUMBER"},0)

Sorry for my ignorance and thank you for your time.

Offline reneboer

  • Hero Member
  • *****
  • Posts: 1360
  • Karma: +77/-30
Re: Luup Code Help!
« Reply #1 on: March 26, 2018, 05:25:55 am »
Hi,

On UI7 you can set a time window for a scene trigger without the need for any LUA. Just make tow scenes with the standard time window function.

Cheers Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +12/-4
Re: Luup Code Help!
« Reply #2 on: March 26, 2018, 06:34:32 am »
Backing up what @reneger said, I have a home scene that does a bunch of stuff.  Then a second home scene that has a time restriction of 7am > 7pm which has one extra step in it (open blinds).

Thus during the day both scenes run when arriving home, and if at night only the first will run.

Some day I'll put a multi sensor outside so it can be based on light level instead of time.

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +12/-4
Re: Luup Code Help!
« Reply #3 on: March 26, 2018, 06:39:13 am »
I should mention there is luup.is_night() rather than hardcoding times - but I don't have any faith in it due to Vera having extensive bugs with my timezone.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1313
  • Karma: +34/-32
Re: Luup Code Help!
« Reply #4 on: March 26, 2018, 07:53:01 pm »
Backing up what @reneger said, I have a home scene that does a bunch of stuff.  Then a second home scene that has a time restriction of 7am > 7pm which has one extra step in it (open blinds).

Thus during the day both scenes run when arriving home, and if at night only the first will run.

Some day I'll put a multi sensor outside so it can be based on light level instead of time.

You may want to use sunset/sunrise instead of 7am/7pm. It should be a matter of editing the scene.
Vera 3, 1.7.1030, CT101, Everspring motion sensor, GE/Jasco switch, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, Weatherunderground, LB60Z-1 bulb, Hue, Alexa

Offline CarsonY101

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Luup Code Help!
« Reply #5 on: March 27, 2018, 10:07:02 pm »
I guess I should have mentioned I'd like to manually be able to trigger this scene.  Long story short, I work nights, I'd like for if my wife and kids get home after dark certain lights come on when she triggers the "Home" scene but if they come home during the day those lights don't come on as they're not needed. 

Thanks again for all of your help.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1313
  • Karma: +34/-32
Re: Luup Code Help!
« Reply #6 on: March 28, 2018, 08:46:47 pm »
Without using PLEG, you can set up a combination switch to look at Day/Night and House Mode to turn on the lights.
Vera 3, 1.7.1030, CT101, Everspring motion sensor, GE/Jasco switch, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, Weatherunderground, LB60Z-1 bulb, Hue, Alexa