Get alarm status

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
Post Reply
Emil
Posts: 3
Joined: Friday 07 December 2018 17:37
Target OS: Raspberry Pi
Domoticz version: 4.97
Location: Sverige
Contact:

Get alarm status

Post by Emil » Friday 07 December 2018 17: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!

User avatar
waaren
Posts: 1346
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get alarm status

Post by waaren » Saturday 08 December 2018 0:46

Emil wrote:
Friday 07 December 2018 17: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 ?
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Emil
Posts: 3
Joined: Friday 07 December 2018 17:37
Target OS: Raspberry Pi
Domoticz version: 4.97
Location: Sverige
Contact:

Re: Get alarm status

Post by Emil » Saturday 08 December 2018 9:32

Yes, i want the selector switch to show the level named disarm, home or away.

/Emil
Attachments
Skärmklipp 2018-12-08 08.25.16.jpg
Skärmklipp 2018-12-08 08.25.16.jpg (49.96 KiB) Viewed 72 times

User avatar
waaren
Posts: 1346
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get alarm status

Post by waaren » Saturday 08 December 2018 11:22

Emil wrote:
Saturday 08 December 2018 9: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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Emil
Posts: 3
Joined: Friday 07 December 2018 17:37
Target OS: Raspberry Pi
Domoticz version: 4.97
Location: Sverige
Contact:

Re: Get alarm status

Post by Emil » Monday 10 December 2018 10:35

I will try this, thank you for taking the time to share your knowledge with me.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests