Page 1 of 1

MQTT and Security Panel

Posted: Monday 30 November 2020 22:36
by FireWizard
The "Security Panel" is able to communicate with the outside world by means of the JSON API.

See: https://www.domoticz.com/wiki/Domoticz_ ... s#Security

To get the Security Status, you can can do a simple HTTP GET request, while to disarm, arm home or arm away you can PUT that information to Domoticz. However, whether this Security Panel also communicates by means of MQTT is fully undocumented. At least I was not able to find it.

However a status change from the Security Panel is published to MQTT domoticz/out.

Screenshot_sec_panel.png
Screenshot_sec_panel.png (14.23 KiB) Viewed 723 times
where nvalue = 0 => Disarmed, nvalue = 11 => Armed Home and nvalue = 9 => Armed Away.

Does anyone know, whether it is also possible to send a JSON command to domoticz/in, in order to Disarm, Arm Home or Arm Away the Security Panel?
If so, do you know the JSON commands?

Regards

Re: MQTT and Security Panel

Posted: Tuesday 01 December 2020 2:18
by waaren
FireWizard wrote: Monday 30 November 2020 22:36 Does anyone know, whether it is also possible to send a JSON command to domoticz/in, in order to Disarm, Arm Home or Arm Away the Security Panel?
If so, do you know the JSON commands?
Security panel is internally for the bigger part just another device. So the normal udevice commands do work.

Code: Select all

mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 0, "svalue": "" }'  -t domoticz/in # Normal
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 1, "svalue": "" }'  -t domoticz/in # Normal Delayed
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 2, "svalue": "" }'  -t domoticz/in # Alarm
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 3, "svalue": "" }'  -t domoticz/in # Alarm Delayed
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 4, "svalue": "" }'  -t domoticz/in # Motion
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 5, "svalue": "" }'  -t domoticz/in # No Motion
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 6, "svalue": "" }'  -t domoticz/in # Panic
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 7, "svalue": "" }'  -t domoticz/in # Panic end
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 8, "svalue": "" }'  -t domoticz/in # ??
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 9, "svalue": "" }'  -t domoticz/in # Arm Away
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 10, "svalue": "" }' -t domoticz/in # Arm Away Delayed
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 11, "svalue": "" }' -t domoticz/in # Arm Home
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 12, "svalue": "" }' -t domoticz/in # Arm Home Delayed
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 13, "svalue": "" }' -t domoticz/in # Disarm 
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 14, "svalue": "" }' -t domoticz/in # ??
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 15, "svalue": "" }' -t domoticz/in # ??
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 16, "svalue": "" }' -t domoticz/in # Light On
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 17, "svalue": "" }' -t domoticz/in # Light Off
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 18, "svalue": "" }' -t domoticz/in # Light 2 Off
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 19, "svalue": "" }' -t domoticz/in # Light 2 On
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 20, "svalue": "" }' -t domoticz/in # Dark detected
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 21, "svalue": "" }' -t domoticz/in # Light detected
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 22, "svalue": "" }' -t domoticz/in # Battery low MS10 or XX18 sensor
mosquitto_pub -h <IP mqtt broker> -m '{"idx": <alarm panel idx>, "nvalue": 22, "svalue": "" }' -t domoticz/in # Pair KD101



Re: MQTT and Security Panel

Posted: Tuesday 01 December 2020 12:38
by FireWizard
Hello @waaren,

Thank you very much for your quick response. Your contribution is again appreciated.
This commands change the indication on the icon, but not the indication in the security panel itself.
But it is Okay for me.

Remains one question.

Where did you find that information? Try and error? No, I do not believe that.
I checked some files in the source code, but could not find anything.

Do you think that it is a good idea to add it to the Wiki.

Thanks again and regards

Re: MQTT and Security Panel

Posted: Tuesday 01 December 2020 14:58
by waaren
FireWizard wrote: Tuesday 01 December 2020 12:38 Where did you find that information?
Indeed trial and error. And the existing knowledge that the panel is also a device with a record in table DeviceStatus.
This commands change the indication on the icon, but not the indication in the security panel itself.
The security of the panel device is changed by this command. I checked that with an outgoing MQTT (set MQTT to allow looping :) )
An issue is that the securitystatus record in the Preferences table of the database is not changed.

I don't know how / when you are using this security panel / security status but please make sure you test all possible scenarios with it before considering to use this safe for you to use in a none test environment.

As dzVents can change the security status (including the status in the database) I would suggest you use below
mosquitto commands

Code: Select all

    mosquitto_pub -h <MQTT Broker IP> -m '{"command":"customevent", "event":"manage security","data":"Armed Home"}'  -t domoticz/in 
    mosquitto_pub -h <MQTT Broker IP> -m '{"command":"customevent", "event":"manage security","data":"Disarmed"}'  -t domoticz/in
    mosquitto_pub -h <MQTT Broker IP> -m '{"command":"customevent", "event":"manage security","data":"Armed Away"}'  -t domoticz/in
Combined with this dzVents script.

Code: Select all

--[[ Alarm / security

    mosquitto_pub -h <MQTT Broker IP> -m '{"command":"customevent", "event":"manage security","data":"Armed Home"}'  -t domoticz/in 
    mosquitto_pub -h <MQTT Broker IP> -m '{"command":"customevent", "event":"manage security","data":"Disarmed"}'  -t domoticz/in
    mosquitto_pub -h <MQTT Broker IP> -m '{"command":"customevent", "event":"manage security","data":"Armed Away"}'  -t domoticz/in

]] -- 


local scriptVar = 'manage security'

return
{
    on =
    {
        customEvents =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
        marker = scriptVar
    },

    execute = function(dz, item )

        local securityPanel  = dz.devices(1280) -- change to your panel idx or 'panel name'

        dz.log('Current security level: ' .. securityPanel.state, dz.LOG_DEBUG )
        dz.log('Requested security level: ' .. item.data, dz.LOG_DEBUG )

        if item.data == dz.SECURITY_DISARMED and securityPanel.state ~= dz.SECURITY_DISARMED then
            securityPanel.disarm()
        elseif item.data == dz.SECURITY_ARMEDAWAY and securityPanel.state ~= dz.SECURITY_ARMEDAWAY then
            securityPanel.armAway().afterSec(30) -- run !
        elseif item.data == dz.SECURITY_ARMEDHOME and securityPanel.state ~= dz.SECURITY_ARMEDHOME then
            securityPanel.armHome()
        else
            dz.log('No new level set', dz.LOG_DEBUG )
        end
    end
}
Do you think that it is a good idea to add it to the Wiki.
Not the part where only the panel state is changed.

Re: MQTT and Security Panel

Posted: Thursday 03 December 2020 22:26
by FireWizard
Hello @waaren

First of all I like to say thanks for your reply and the provided dZVents script.
I don't know how / when you are using this security panel / security status but please make sure you test all possible scenarios with it before considering to use this safe for you to use in a none test environment.
Indeed it is something I look at and it is in a test environment. I am not sure, yet, if I will use this in production.
Probably, if I use it, I will only use the part from Domoticz as a trigger, but not to Domoticz.
I think the http command is more reliable as it contains the encoded password, but even that I don't think I will use it.

Best regards