Author Topic: Can anyone explain this?  (Read 441 times)

Offline ohecht

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Can anyone explain this?
« on: December 18, 2017, 11:11:52 pm »
I'm about to throw in the towel and go back to my stable Vera 3 and UI5...UI7 on a VeraPlus has been an absolute nightmare.

Here's just one of several major issues I've been dealing with.  I have some code (below) that is in a scene set to run when the door sensor is closed.  The code runs fune when I test it in the Develop Apps code testing function, but absolutely won't work as part of the scene.  The only trigger for the scene is the door closing, and I know the scene is working as I get text messages when it's triggered and I've even added an action to flash a random light in the living room so I know the scene is capable of actually doing something.  The code is in the main part of the scene, not in the Triggers section...the part in the last step of the scene creation where you enter code to run when the scene executes.

Can anyone explain this?

Code:

local SENSOR = 250    -- The door sensor device number
local DOORLOCK = 77 -- The lock device number
local DELAY = 20    -- Seconds to wait before locking the door
 
local SES_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
local LOCK_SID = "urn:micasaverde-com:serviceId:DoorLock1"
 
luup.call_delay( "LockDoor", DELAY)
 
-- Lock the door if it's been closed for the DELAY period
function LockDoor()
    local tripped = luup.variable_get( SES_SID, "Tripped", SENSOR) or "0"
    local lastTrip = luup.variable_get( SES_SID, "LastTrip", SENSOR) or os.time()
    if (tripped == "0" and (os.time() - lastTrip >= DELAY)) then
        luup.call_action(LOCK_SID, "SetTarget", {newTargetValue = "1"}, DOORLOCK)
    end
end

Offline Jamr

  • Hero Member
  • *****
  • Posts: 762
  • Karma: +24/-8
Re: Can anyone explain this?
« Reply #1 on: December 19, 2017, 12:54:04 am »
Sorry as I don't speak computer language.

It looks like you are just trying to automate locking the door when the door closes?

Offline ohecht

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Can anyone explain this?
« Reply #2 on: December 19, 2017, 02:46:31 pm »
Yes, but this code is supposed to prevent the door from locking if the door is only closed momentarily and then opened again.  It basically compares the time since the last trip with the current time and, once the difference between the two exceeds the set delay period, it "knows" that the door has remained closed for that long and then locks the door.

I don't want the door to lock instantly when I close it for a couple of reasons, and I've found that a simple trigger works OK, but there are lots of times the deadbolt ends up in the locked position with the door open.

The code works fine in the test area, just not within a scene, and I don't see any of the "http encoding" issues that I think can cause code to not work within a scene despite working otherwise.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1306
  • Karma: +34/-32
Re: Can anyone explain this?
« Reply #3 on: December 19, 2017, 07:46:22 pm »
With a door sensor, you can have the lock stay unlocked if the door is open.
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 kigmatzomat

  • Sr. Member
  • ****
  • Posts: 343
  • Karma: +15/-0
Re: Can anyone explain this?
« Reply #4 on: December 19, 2017, 09:06:35 pm »
Scenes with timing are problematic in luup.

Try PLEG.
Set a trigger for door closed (tfrontDoorClosed) and door unlocked (tFr_unlocked)

Then add a condition that checks to make sure the door is closed now and is unlocked now, and that it was closed more than 3 minutes ago.

      tfrontDoorClosed and tFr_unlocked and ( tFrontDoorClosed ; Now >3:00) and (tFr_unlocked ; Now >3:00)

Then make a simple scene that locks the lock with the PLEG condition as a trigger.

Offline ohecht

  • Sr. Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Re: Can anyone explain this?
« Reply #5 on: December 22, 2017, 01:24:25 pm »
OK, thanks.  I will have to try that but it will be my first foray with PLEG...

Any idea why the exact same luup would work in UI5/Vera 3 but not in UI7/VeraPlus?