How to handle timeouts?
Moderator: leecollings
-
- Posts: 48
- Joined: Tuesday 03 January 2017 0:37
- Target OS: Linux
- Domoticz version: 13939
- Location: USA
- Contact:
How to handle timeouts?
Does anyone have a good method for figuring out if a z-wave switch actually operated as it's supposed to? I have a door lock that I wrote a LUA script for to lock the door at a particular time every night. However sometimes when the z-wave controller sends the switch command the door lock never gets the message. It wouldn't be a big deal but Domoticz thinks the door is locked anyway. So I can't easily put a check in my script for it. Anyone have any ideas on how I might find out if the lock didn't lock even when Domoticz thinks it did? On a side note there is a z-wave timeout for the node after the switch command is sent. So the z-wave controller knows the message didn't through, it's just Domoticz that doesn't seem to.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: How to handle timeouts?
Does a refresh in ozwcp reflect the correct status?
-
- Posts: 48
- Joined: Tuesday 03 January 2017 0:37
- Target OS: Linux
- Domoticz version: 13939
- Location: USA
- Contact:
Re: How to handle timeouts?
OZWCP shows everything correctly. It just seems to be Domoticz that gets a bit lost. So I made a work around in my script to poll the OZWCP. I've got the code below, it works for Kiwkset locks. It also needs a door sensor. Lua code below:
Code: Select all
commandArray = {}
local zwHWID = 2 --CHANGE: The Z-wave node ID for the lock.
local zwnodeID = 14 --CHANGE: The IDX of the Z-wave controller the lock is associated with.
local DoorName = "Porch Door" -- CHANGE: Name of doorlock switch
local DoorSensor = "Office/Porch Door" -- CHANGE: Name of door sensor.
local DoorTimer = "Office/Porch Autolock Timer" -- CHANGE: Name of autolock timer dummy switch
if (otherdevices[DoorTimer] == "On") then
local s1 = otherdevices_lastupdate[DoorSensor]
local s2 = otherdevices_lastupdate[DoorTimer]
local year1 = string.sub(s1, 1, 4)
local month1 = string.sub(s1, 6, 7)
local day1 = string.sub(s1, 9, 10)
local hour1 = string.sub(s1, 12, 13)
local minutes1 = string.sub(s1, 15, 16)
local seconds1 = string.sub(s1, 18, 19)
local year2 = string.sub(s2, 1, 4)
local month2 = string.sub(s2, 6, 7)
local day2 = string.sub(s2, 9, 10)
local hour2 = string.sub(s2, 12, 13)
local minutes2 = string.sub(s2, 15, 16)
local seconds2 = string.sub(s2, 18, 19)
local t1 = os.time()
local t2 = os.time{year=year1, month=month1, day=day1, hour=hour1, min=minutes1, sec=seconds1}
local t3 = os.time{year=year2, month=month2, day=day2, hour=hour2, min=minutes2, sec=seconds2}
local difference1 = t1-t2
local difference2 = t1-t3
if (difference1 > 60) then
-- Load data from ZWCFG we can't get anywhere else, get curl from: https://curl.haxx.se/download.html
local zwcfg = assert(io.popen('curl http://127.0.0.1/zwavegetconfig.php?idx=' .. zwHWID .. ' -la','r'))
local thedata = zwcfg:read('*all')
zwcfg:close()
--done getting zwcfg
-- ver<3.7153 domoticz_applyXPath doesn't work for regular LUA so we get values the hard way.
--local xmlchunk = string.sub(thedata, string.find(thedata, '<Node id="' .. zwnodeID .. '"'), string.len(thedata))
--xmlchunk = string.sub(xmlchunk, string.find(xmlchunk, '<CommandClass id="113" name="COMMAND_CLASS_ALARM"'), string.find(xmlchunk, '<CommandClass id="114"'))
--local alarmtype = string.sub(xmlchunk, string.find(xmlchunk, 'Alarm Type" units="" read_only="true" write_only="false" verify_changes="false" poll_intensity="0" min="0" max="255" value="'), string.find(xmlchunk, 'Value type="byte" genre="user" instance="1" index="1" label="Alarm Level"'))
--alarmtype = string.sub(alarmtype,125,string.find(alarmtype, '" />')-1)
--Done getting values ver<3.7153
-- ver>=3.7153 domoticz_applyXPath works.
local alarmtype = domoticz_applyXPath(thedata,'//Driver/Node[@id="' .. zwnodeID .. '"]/CommandClasses/CommandClass[@name="COMMAND_CLASS_ALARM"]/Value[@label="Alarm Type"]/@value')
--Done getting values ver>=3.7153
alarmtype = tonumber(alarmtype)--these need to be numbers because of LUA.
--if (otherdevices[DoorSensor] == 'Closed' and otherdevices[DoorName] == 'Unlocked') then --should work but doesn't always
if (otherdevices[DoorSensor] == 'Closed' and alarmtype ~= 24) then --so we check OZW instead.
commandArray[DoorName]='On' --if the door is unlocked too long lock it
end
elseif (otherdevices[DoorSensor] == 'Closed' and difference2 < 60) then
commandArray[DoorName]='On' --if the user just clicked the autolock button lock right away
end
end
return commandArray
Who is online
Users browsing this forum: No registered users and 1 guest