Page 1 of 1
Get alarm status
Posted: Friday 07 December 2018 16:51
by Emil
Hello!
My goal is to get the status of my home alarm into a selector switch.
When I enter this in the browser
https://webehome.com/Public/login.aspx? ... onOnly=yes
then I get one of the following words in response: disarm, home or away
Is there any way to get this status into a selector switch?
Thanks in advance!
Re: Get alarm status
Posted: Friday 07 December 2018 23:46
by waaren
Emil wrote: ↑Friday 07 December 2018 16:51
Hello!
My goal is to get the status of my home alarm into a selector switch.
When I enter this in the browser
https://webehome.com/Public/login.aspx? ... onOnly=yes
then I get one of the following words in response: disarm, home or away
Is there any way to get this status into a selector switch?
Thanks in advance!
can you show the exact response (screenshot) ? Not clear now if the response if json or xml or other format
What do you mean the get the status into a selector switch ? Should the selector switch switch to the level named disarm, home or away or do you mean something else ?
Re: Get alarm status
Posted: Saturday 08 December 2018 8:32
by Emil
Yes, i want the selector switch to show the level named disarm, home or away.
/Emil
Re: Get alarm status
Posted: Saturday 08 December 2018 10:22
by waaren
Emil wrote: ↑Saturday 08 December 2018 8:32
Yes, i want the selector switch to show the level named disarm, home or away.
/Emil
The script below does react to the httpResponse and set the selector switch accordingly but there is no translation in it yet.
So for now the selector labels should be exactly the same as the possible returns from the alarm system.
If you need to translate the strings to home, disarm and and away, I need the exact words that you can get from the http call.
Code: Select all
local alarmResponse = "_alarmResponse"
return {
on = { timer = { 'every minute' },
httpResponses = { alarmResponse }},
logging = { level = domoticz.LOG_DEBUG,
marker = "älarmResponse" },
execute = function(dz, item )
local alarmSelectorIDX = nnn -- Change to the IDX of your selector
local url = 'https://webehome.com/Public/login.aspx?LoginName=username&Password=password&Action=status&ActionOnly=yes' -- Change to real HTTP
local alarmStatus = dz.devices(alarmSelectorIDX)
local levels = {}
local function logWrite(str,level)
dz.log(str,level or dz.LOG_DEBUG)
end
local function findLevel(label)
local level = false
for i = 1,#alarmStatus.levelNames do
logWrite(alarmStatus.levelNames[i])
if alarmStatus.levelNames[i] == label then
level = i * 10 - 10
logWrite("Found: ".. alarmStatus.levelNames[i])
end
end
return level
end
local function getAlarmStatus(url)
dz.openURL ( {
url = url,
method = 'GET',
callback = alarmResponse
} )
end
local function xml2Table(xml)
local dataStart = "<body>"
local dataEnd = "</body>"
local i, j = string.find(xml, dataStart)
local k, i = string.find(xml, dataEnd)
local payLoad= xml:sub(j+1,k-1)
logWrite("payLoad is: " ..payLoad)
return payLoad
end
-- Main code
if not item.isHTTPResponse then
getAlarmStatus(url)
else
logWrite("data from HTTPcall: " .. item.data)
if item.ok then -- statusCode == 2xx
newLevel = findLevel(xml2Table(item.data))
if newLevel and newLevel ~= alarmStatus.level then
alarmStatus.dimTo(newLevel)
end
else
logWrite("Problem with the XML response")
end
end
end
}
Re: Get alarm status
Posted: Monday 10 December 2018 9:35
by Emil
I will try this, thank you for taking the time to share your knowledge with me.