We have moved at community.getvera.com

Author Topic: How to overwrite a prior command 'turn on after 5 min'?  (Read 6918 times)

Offline frankflorida

  • Sr. Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
How to overwrite a prior command 'turn on after 5 min'?
« on: September 24, 2011, 09:49:12 am »
I have two Scenes:
A) Event: press Lock button on Doorlock Command:Arm motion sensor after 5 min.
B) Event: correct code entered at Doorlock Command:Disarm Motion sensor right away

Problem: If I lock the door and unlock the door within 5 minutes then the the motion sensor goes armed ANYWAY after the first 5 minutes have past. That causes my Alarm to come on etc. How can I overwrite comannd A) when I trigger event B)?

Frank

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #1 on: September 26, 2011, 05:10:30 am »
In scene A remove the motion sensor arm command and add the code below in the Luup code input box, replacing DEVICE_NUM's value (currently 35) with the motion sensor device number. DELAY is the number of minutes for the delay; you can change this as well.

Code: [Select]
local DEVICE_NUM = 35
local DELAY = 5

function armMotionSensor()
    local disarmedFlag = luup.variable_get ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", DEVICE_NUM)
    if (disarmedFlag ~= "1") then
        luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, DEVICE_NUM)
    else
        luup.variable_set ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", "0", DEVICE_NUM)
    end
end

local delaySec = DELAY * 60
luup.call_delay ("armMotionSensor", delaySec, "")


Then in the scene B add this code in the Luup code input box, replacing DEVICE_NUM's value (currently 35) with the motion sensor device number:

Code: [Select]
local DEVICE_NUM = 35
luup.variable_set ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", "1", DEVICE_NUM)

Try this and let me know if it worked.

Offline frankflorida

  • Sr. Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #2 on: September 29, 2011, 01:50:26 pm »
Thanks for the code. Right now I have tennants in that vacation rental home but I will test once they have left. I am still wondering about:
The motion sensor is on battery and therefore set to report status every 5 minuts.
Can the Luup code be written to set the motion sensor to "No tripped" and followed right away "ARMED"? The only reason I had to set the 5 minutes delay is because the Sensor stays/reports 5 minutes "Tripped" after I leave the home and if I ARM right away then the Event "Sensor Tripped" comes ON right away (Alarm event). Best solution would be if it can be armed right away after leaving the room while pressing the LOCKED button on my KwickSet look.
Frank

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #3 on: September 30, 2011, 07:08:07 am »
If your motion sensor is hooked directly to the alarm panel it will report it's tripped status directly, so it's not possible to set it to "No tripped" with Lua code.

Offline pkitch

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #4 on: October 10, 2011, 11:06:53 pm »
In scene A remove the motion sensor arm command and add the code below in the Luup code input box, replacing DEVICE_NUM's value (currently 35) with the motion sensor device number. DELAY is the number of minutes for the delay; you can change this as well.

Code: [Select]
local DEVICE_NUM = 35
local DELAY = 5

function armMotionSensor()
    local disarmedFlag = luup.variable_get ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", DEVICE_NUM)
    if (disarmedFlag ~= "1") then
        luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, DEVICE_NUM)
    else
        luup.variable_set ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", "0", DEVICE_NUM)
    end
end

local delaySec = DELAY * 60
luup.call_delay ("armMotionSensor", delaySec, "")


Then in the scene B add this code in the Luup code input box, replacing DEVICE_NUM's value (currently 35) with the motion sensor device number:

Code: [Select]
local DEVICE_NUM = 35
luup.variable_set ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", "1", DEVICE_NUM)

Try this and let me know if it worked.

Hi mcvflorin,

Can you advise the amendment in the code to apply the delayed armed status to multiple motion sensors at the same time? I have played around with it, but can only get it to action one sensor.

Thanks!

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #5 on: October 11, 2011, 11:15:07 am »
The code I previously wrote was unnecessarily complicated. Below is the improved version. Add this code in scene A. No code is necessary for scene B. The values you see in SECURITY_SENSORS and DOOR_LOCK are placeholders. You must put the correct value there. Also, if you don't feel like writing the names of the sensors in SECURITY_SENSORS let me know and I will rewrite the code.

This code works for any number of sensors.

Code: [Select]
-- Device number - device name pairs.
local SECURITY_SENSORS = {
    [12] = "Hall Motion Sensor",
    [23] = "Front Window Sensor",
    [34] = "Stairs Motion Sensor"
}
-- Door lock device number.
local DOOR_LOCK = 45
-- The delay in minutes.
local DELAY = 5

-- Arm all the security sensors only if the door is locked.
function armMotionSensor()
    local status = luup.variable_get ("urn:micasaverde-com:serviceId:DoorLock1", "Status", DOOR_LOCK) or "0"
    if (status == "1") then
        for k, v in pairs (SECURITY_SENSORS) do
            luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, k)
        end
    end
end

-- Compute the number of seconds for the delay.
local delaySec = DELAY * 60

-- Arm the security sensors in 'delaySec' seconds.
luup.call_delay ("armMotionSensor", delaySec, "")

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #6 on: October 11, 2011, 12:18:37 pm »
@mcvflorin, many thanxs for the updated code.  Question in reference to events;

I'm assuming that;
Scene A: the Event selected is "Lock Button is pressed" option and for,
Scene B: Event selected is "A PIN Code is Entered?" followed by "Which PIN Code number? 0-X" for correct code sequence number as I can't find any other option that come close (at least for Kwiklocks). Mike
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #7 on: October 11, 2011, 01:09:58 pm »
Your assumptions are correct. The events are the same for all the door locks, so it doesn't matter what door lock you have.

Offline pkitch

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #8 on: October 11, 2011, 11:36:42 pm »
The code I previously wrote was unnecessarily complicated. Below is the improved version. Add this code in scene A. No code is necessary for scene B. The values you see in SECURITY_SENSORS and DOOR_LOCK are placeholders. You must put the correct value there. Also, if you don't feel like writing the names of the sensors in SECURITY_SENSORS let me know and I will rewrite the code.

This code works for any number of sensors.

Code: [Select]
-- Device number - device name pairs.
local SECURITY_SENSORS = {
    [12] = "Hall Motion Sensor",
    [23] = "Front Window Sensor",
    [34] = "Stairs Motion Sensor"
}
-- Door lock device number.
local DOOR_LOCK = 45
-- The delay in minutes.
local DELAY = 5

-- Arm all the security sensors only if the door is locked.
function armMotionSensor()
    local status = luup.variable_get ("urn:micasaverde-com:serviceId:DoorLock1", "Status", DOOR_LOCK) or "0"
    if (status == "1") then
        for k, v in pairs (SECURITY_SENSORS) do
            luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, k)
        end
    end
end

-- Compute the number of seconds for the delay.
local delaySec = DELAY * 60

-- Arm the security sensors in 'delaySec' seconds.
luup.call_delay ("armMotionSensor", delaySec, "")

Can you please advise where to insert the following command - setting of a virtual switch as an 'armed' flag - so that it too is now conditional on the status of the lock"

local DEVICE = 32
luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", 1, DEVICE)

Thanks so much!

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #9 on: October 12, 2011, 04:28:13 am »
You mean if the door is locked, then the virtual switch is ON?

Offline pkitch

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #10 on: October 12, 2011, 08:13:19 am »
You mean if the door is locked, then the virtual switch is ON?

No , actually I mean't that the sensors are armed, so the virtual switch is only set to 'On' if the sensors are armed - which are dependent on the lock status.

Hope this makes sense and thanks again.

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #11 on: October 13, 2011, 08:12:18 am »
Here is the modified code to update an Armed flag (virtual switch) if all the sensors are armed.

Code: [Select]
-- Device number - device name pairs.
local SECURITY_SENSORS = {
    [12] = "Hall Motion Sensor",
    [23] = "Front Window Sensor",
    [34] = "Stairs Motion Sensor"
}
-- Door lock device number.
local DOOR_LOCK = 45
-- The delay in minutes.
local DELAY = 5
-- The virtual switch (Armed flag) device number.
local VIRTUAL_SWITCH = 32

-- Update the Armed flag. If all the sensors are armed, the flag is "1", otherwise the flag is "0".
function updateArmedFlag()
    -- Assume that all the sensors are armed.
    local armedFlag = "1"

    for k, v in pairs (SECURITY_SENSORS) do
        local armed = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", k) or "0"
        if (armed == "0") then
            armedFlag = "0"
            break
        end
    end
    luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", armedFlag, VIRTUAL_SWITCH)
end

-- Arm all the security sensors only if the door is locked.
function armMotionSensor()
    local status = luup.variable_get ("urn:micasaverde-com:serviceId:DoorLock1", "Status", DOOR_LOCK) or "0"
    if (status == "1") then
        for k, v in pairs (SECURITY_SENSORS) do
            luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, k)
        end
        -- Update the Armed flag in 3 seconds, to be sure that all the sensors are armed.
        luup.call_delay ("updateArmedFlag", 3, "")
    end
end

-- Compute the number of seconds for the delay.
local delaySec = DELAY * 60

-- Arm the security sensors in 'delaySec' seconds.
luup.call_delay ("armMotionSensor", delaySec, "")

Offline pkitch

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +0/-0
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #12 on: October 13, 2011, 10:19:10 pm »
Here is the modified code to update an Armed flag (virtual switch) if all the sensors are armed.

Code: [Select]
-- Device number - device name pairs.
local SECURITY_SENSORS = {
    [12] = "Hall Motion Sensor",
    [23] = "Front Window Sensor",
    [34] = "Stairs Motion Sensor"
}
-- Door lock device number.
local DOOR_LOCK = 45
-- The delay in minutes.
local DELAY = 5
-- The virtual switch (Armed flag) device number.
local VIRTUAL_SWITCH = 32

-- Update the Armed flag. If all the sensors are armed, the flag is "1", otherwise the flag is "0".
function updateArmedFlag()
    -- Assume that all the sensors are armed.
    local armedFlag = "1"

    for k, v in pairs (SECURITY_SENSORS) do
        local armed = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", k) or "0"
        if (armed == "0") then
            armedFlag = "0"
            break
        end
    end
    luup.variable_set ("urn:upnp-org:serviceId:SwitchPower1", "Status", armedFlag, VIRTUAL_SWITCH)
end

-- Arm all the security sensors only if the door is locked.
function armMotionSensor()
    local status = luup.variable_get ("urn:micasaverde-com:serviceId:DoorLock1", "Status", DOOR_LOCK) or "0"
    if (status == "1") then
        for k, v in pairs (SECURITY_SENSORS) do
            luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, k)
        end
        -- Update the Armed flag in 3 seconds, to be sure that all the sensors are armed.
        luup.call_delay ("updateArmedFlag", 3, "")
    end
end

-- Compute the number of seconds for the delay.
local delaySec = DELAY * 60

-- Arm the security sensors in 'delaySec' seconds.
luup.call_delay ("armMotionSensor", delaySec, "")

Thanks!

Offline frankflorida

  • Sr. Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #13 on: October 30, 2011, 01:33:55 pm »
Just wondering if the code in window (B) overwrites a "pending" 5-minute-delay in code window (A) ?
I still having the problem if I return within 5 minutes into my home after I looked the door that the
alarm goes on even I entered the right code and send the "Disarm" to the sensors. Looks like that a PENDING 5 minutes delay ARMS my sensors anyway.... any way to stop a prior PENDING delay command? Frank

In scene A remove the motion sensor arm command and add the code below in the Luup code input box, replacing DEVICE_NUM's value (currently 35) with the motion sensor device number. DELAY is the number of minutes for the delay; you can change this as well.

Code: [Select]
local DEVICE_NUM = 35
local DELAY = 5

function armMotionSensor()
    local disarmedFlag = luup.variable_get ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", DEVICE_NUM)
    if (disarmedFlag ~= "1") then
        luup.call_action ("urn:micasaverde-com:serviceId:SecuritySensor1", "SetArmed", {newArmedValue = "1"}, DEVICE_NUM)
    else
        luup.variable_set ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", "0", DEVICE_NUM)
    end
end

local delaySec = DELAY * 60
luup.call_delay ("armMotionSensor", delaySec, "")


Then in the scene B add this code in the Luup code input box, replacing DEVICE_NUM's value (currently 35) with the motion sensor device number:

Code: [Select]
local DEVICE_NUM = 35
luup.variable_set ("urn:micasaverde-com:serviceId:Flags1", "DisarmedFlag", "1", DEVICE_NUM)

Try this and let me know if it worked.

Hi mcvflorin,

Can you advise the amendment in the code to apply the delayed armed status to multiple motion sensors at the same time? I have played around with it, but can only get it to action one sensor.

Thanks!

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: How to overwrite a prior command 'turn on after 5 min'?
« Reply #14 on: November 01, 2011, 02:51:27 pm »
@frankflorida

Please use the code and the instructions from Reply #5.