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

Offline CarsonY101

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #285 on: March 23, 2018, 10:05:11 pm »
Hello all,

I'm really new to the luup coding.  I would like to have certain lights turn on at sunset to sunrise when home mode is activated. I know this code will be needed:

I'm thinking it'll 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.
« Last Edit: March 24, 2018, 12:18:43 am by CarsonY101 »

Offline stardobas

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #286 on: April 18, 2018, 05:59:04 pm »
Sorry, I've a problem and need to solve;
I have vera plus UI7 and using fibaro FGMS-001;
I've set up a scene where when sensor detect motion turn light on; I need to play this scene only when room light is under 50 lux...
so, using you expample I add in a scene this lua script (into "add lua code " inside a scene after trigger)
this is a lua code copy/past from scene:

local dID = 94           -- Device ID of your light sensor
local lLow = 0           -- Lowest level of range
local lHigh = 50         -- Highest level of range
local allow = true       -- true runs scene when in range, false blocks it
local lCurrent = tonumber((luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1","CurrentLevel",dID)))
return (((lCurrent >= lLow) and (lCurrent <= lHigh)) == allow)


using this link: http://192.168.1.205:3480/data_request?id=status&output_format=xml

I obtain this:

<device id="94" PendingJobs="0" status="-1">
<states>
<state id="10" service="urn:micasaverde-com:serviceId:LightSensor1" variable="CurrentLevel" value="60"/>
<state id="11" service="urn:micasaverde-com:serviceId:HaDevice1" variable="Configured" value="0"/>
<state id="12" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="SensorMlType" value="3"/>
<state id="13" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="SensorMlScale" value="2"/>
<state id="14" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="VariablesGet" value=""/>
<state id="15" service="urn:micasaverde-com:serviceId:ZWaveDevice1" variable="ManufacturerInfo" value="0,0,0"/>
</states>

this is a sensor I use....
How you can see the sensor light value is 60 for LUX..but the scene is played ignoring the lux value..

PLEASE HELP TO SOLVE
« Last Edit: April 18, 2018, 06:02:16 pm by stardobas »

Offline jsauser11

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #287 on: July 29, 2018, 01:42:56 pm »
Hi,
Trying to leverage some code found above to accomplish the following:
Scene trigger is Thermostat mode switches from "idle" to "cooling".
LUUP code to check multiple security sensors for the "tripped" state, and continue scene exicution if any of them are tripped (doors or windows open).
Code will then broadcast a message over Sonos to close the open doors or windows.
Here is what I have so far for the code:

local tripped_frontdoor = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 34)
local tripped_patiodoor = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 132)
local allow = true

return (((tripped_frontdoor == "1") or (tripped_patiodoor == "1")) == allow)

luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say",
                 {Text="Air conditioning is turning on, please close all open doors and windows", Language="en"},
                 145)
But, get errors when I run it it the "test LUUP code" on my VeraPlus. Do I need to put this into a function for it to work?
Thanks for any help in coding this.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 758
  • Karma: +115/-1
Re: Conditional Scene Execution: Some Examples
« Reply #288 on: July 29, 2018, 01:50:23 pm »
You call_action follows an unconditional return, so will never be executed. Lua certainly won't like that.
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.