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

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #45 on: February 28, 2014, 05:42:42 pm »
It a straight up GE/JASCO single pole on/off zwave switch
Will you copy the code from your scene's Luup tab and post it?

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #46 on: February 28, 2014, 06:15:11 pm »
@keithr, try this code and post the section from LuaUPnP.log where you test it.

Code: [Select]
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

See Logs Explained.
« Last Edit: February 28, 2014, 06:17:43 pm by RexBeckett »

Offline kiethr

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-2
Re: Conditional Scene Execution: Some Examples
« Reply #47 on: February 28, 2014, 11:07:32 pm »
@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.

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #48 on: March 01, 2014, 03:06:42 am »
@kiethr, the code is working correctly but Vera thinks sunset in your parts is at 23:24...

Check SETUP -> Location -> Timezone and Currentcity

Offline kiethr

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-2
Re: Conditional Scene Execution: Some Examples
« Reply #49 on: March 01, 2014, 07:23:04 am »
its just like I set it up, time zone is correct, city is correct.  Screen shot attached

Offline kiethr

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-2
Re: Conditional Scene Execution: Some Examples
« Reply #50 on: March 01, 2014, 09:38:22 am »
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.

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #51 on: March 01, 2014, 12:35:54 pm »
@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:

Code: [Select]
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.
 

Offline kiethr

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-2
Re: Conditional Scene Execution: Some Examples
« Reply #52 on: March 01, 2014, 02:00:00 pm »
Sure did I even entered the lat and Lon into Google and it pointed to the city I live in


Sent from my iPhone

Offline kiethr

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-2
Re: Conditional Scene Execution: Some Examples
« Reply #53 on: March 01, 2014, 08:57:16 pm »
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

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #54 on: March 02, 2014, 03:22:17 am »
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?
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.

Offline kiethr

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-2
Re: Conditional Scene Execution: Some Examples
« Reply #55 on: March 02, 2014, 07:55:51 am »
Okay, thank you. I did submit the ticket and will report back when I get a response.

Offline Ramiii

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #56 on: March 05, 2014, 05:04:16 am »
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 ?

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #57 on: March 05, 2014, 06:01:17 am »
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 ?
@Ramiii, would you mind posting this question on the Program Logic Plugins board? Thanks.

Offline Ramiii

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #58 on: March 05, 2014, 06:04:38 am »
@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

Offline RexBeckett

  • Master Member
  • *******
  • Posts: 3888
  • Karma: +478/-10
Re: Conditional Scene Execution: Some Examples
« Reply #59 on: March 05, 2014, 06:21:35 am »
@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.