Author Topic: Conditional Scene Execution: Some Examples  (Read 211891 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: 21
  • 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 »