Conditional Scene Execution: Some Examples

Hello @RexBeckett

I did add the updated code to my veralite. The light that would normally trigger will not trigger. If the light that is being triggered is already on when triggered it doesn’t go off after the delay in the scene is reached.

Any thoughts?

Sent from my iPad using Tapatalk HD

[quote=“kiethr, post:41, topic:178331”]Hello @RexBeckett

I did add the updated code to my veralite. The light that would normally trigger will not trigger. If the light that is being triggered is already on when triggered it doesn’t go off after the delay in the scene is reached.
Any thoughts?[/quote]
Sorry @kiether, I don’t understand what your problem is. Are you saying that the scene does not now turn on the light at all? Even when the door is opened during the specified time period?

If the light that is being triggered is already on when triggered it doesn't go off after the delay in the scene is reached.
Isn't that what you wanted to happen?

Maybe I don’t understand what you want to happen. Can you explain how you want it to work?

I guess i was trying to give to much information. You are correct the trigger to turn on the light when the door is open is not working after i added the code.

Sent from my iPad using Tapatalk HD

You are correct the trigger to turn on the light when the door is open is not working after i added the code.
Is the light using a regular Z-Wave switch or is it a dimmer? Some dimmers don't update [b]SwitchPower1 Status[/b] in which case you may need to check [b]LoadLevelStatus[/b] instead.

It a straight up GE/JASCO single pole on/off zwave switch

Sent from my iPhone

Will you copy the code from your scene’s Luup tab and post it?

@keithr, try this code and post the section from LuaUPnP.log where you test it.

[code]local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 32)
if (switchOnOff == “1”) then
luup.log(“Scene Debug: Light is already on.”)
return false
end
luup.log(“Scene Debug: Light is off.”)
local endTime = “23:59”

local ssTime = luup.sunset() % 86400

local hour = math.floor(ssTime / 3600)
local minute = math.floor((ssTime % 3600) / 60)

local startTime = hour * 100 + minute

hour = tonumber( endTime:sub( endTime:find(“%d+”) ) )
minute = tonumber(endTime:sub(-2))

if hour and minute then
endTime = hour * 100 + minute
else
luup.log(“ERROR: invalid end time”)
return false
end

local currentTime = os.date(“*t”)
currentTime = currentTime.hour * 100 + currentTime.min

luup.log("Scene Debug: startTime = " … startTime … "; currentTime = " … currentTime … "; endTime = " … endTime)

if startTime <= endTime then
– Both the start time and the end time are in the same day:
– if the current time is in the given interval, run the scene.
if startTime <= currentTime and currentTime <= endTime then
return true
end
else
– The start time is before midnight, and the end time is after midnight:
– if the current time is not outside the given interval, run the scene.
if not (endTime < currentTime and currentTime < startTime) then
return true
end
end
luup.log(“Scene Debug: Skipping actions.”)
return false[/code]

See Logs Explained.

@RexBeckett

Attached is the log, I think it captured it correctly. The first part of the log is with the triggered light off when the door sensor is tripped. The second part is with the triggered light on when the door sensor is tripped.

Thank you again for taking time to help me with this.

@kiethr, the code is working correctly but Vera thinks sunset in your parts is at 23:24…

Check SETUP → Location → Timezone and Currentcity

its just like I set it up, time zone is correct, city is correct. Screen shot attached

I changed the time zone to mexico, when my veralite restarted i confirmed it was showing the correct time in mexico. I then reset it back to where it should be, reloaded the code you supplied and we will see what happens this evening.

@RexBeckett If you have any other suggestions please let me know.

@kiethr, paste the following code into APPS → Develop Apps → Test Luup code (Lua) then click GO. Check the log and see if it is all correct:

luup.log("Timezone: " .. luup.timezone .. " hours") luup.log("City: " .. luup.city) luup.log("Latitude: " .. luup.latitude) luup.log("Longitude: " .. luup.longitude) local srtime = os.date("%c",luup.sunrise()) luup.log("Sunrise: " .. srtime) local sstime = os.date("%c",luup.sunset()) luup.log("Sunset: " .. sstime)

If your Timezone, City, Latitude and Longitude are all correct but Sunrise and Sunset are still wrong, I have no idea what’s broken - raise an MCV Support ticket.

Sure did I even entered the lat and Lon into Google and it pointed to the city I live in

Sent from my iPhone

One last thought before i submit a help ticket. I have the day/night app installed and i use it to turn on and off outdoor lights. It works fine. Doesn’t the sunset/sunrise information that app uses come from the same place the code here gets its information?

Sent from my iPad using Tapatalk HD

Day/Night uses Vera’s luup.call_timer(…) function to get callbacks for sunrise and sunset. The times should be the same as those returned by luup.sunrise() and luup.sunset() but, on your system, are apparently not.

Okay, thank you. I did submit the ticket and will report back when I get a response.

Here is my scenario

I have a smart switch that turn on the living room lights if a motion is detected and turn it off after 1 minute. But whenever I’m watching tv and someone walks in the light goes on. I want to convert the smart switch to a PLEG action ( which I can easily do ) but I want this scene to only run if XBMC is not playing. I have the XBMC addon installed. Any help with that ?

[quote=“Ramiii, post:57, topic:178331”]Here is my scenario

I have a smart switch that turn on the living room lights if a motion is detected and turn it off after 1 minute. But whenever I’m watching tv and someone walks in the light goes on. I want to convert the smart switch to a PLEG action ( which I can easily do ) but I want this scene to only run if XBMC is not playing. I have the XBMC addon installed. Any help with that ?[/quote]
@Ramiii, would you mind posting this question on the Program Logic Plugins board? Thanks.

@RexBeckett no problem. But I don’t want this to be done using PLEG. I mean the condition. I’ll just use PLEG for the lights and Luup code for the condition , that’s why I posted here

Well you got me confused. Smartswitch, PLEG, XMBC…

If your problem is with determining if XMBC is playing, I cannot help you as I don’t use it. You may have more success posting your question on the XMBC plugin thread so another user can assist you.