TCP Sensor or HTP Sensor or REST Sensor or aREST? - Old Alarm System

Hi There,

I need a little bit of help trying to figure it out how to integrate HA with my alarm system. I have an old alarm system and to make it work for modern environments I am using alarmdecoder. Once you have this working it offers different ways to connect to your alarm system:

It offers a WEB server with API than can be called this way:

curl -X GET --header 'Accept: application/json' 'http://alarmdecoder.local:5000/api/v1/alarmdecoder?apikey=1111111111': 
{
  "panel_alarming": false,
  "panel_armed": false,
  "panel_bypassed": false,
  "panel_fire_detected": false,
  "panel_on_battery": false,
  "panel_panicked": false,
  "panel_powered": true,
  "panel_relay_status": [],
  "panel_type": "ADEMCO",
  "panel_zones_faulted": [3,
    4
  ]
}

I am interested in getting the panel_zones_faulted [] information. This information is an array, and I want to do some automation based on the status of the zones. Some of them are movement sensors. I managed to connect to the sensor adding the following to the configuration:

sensor 2:
  platform: rest
  resource: http://192.168.1.76:5000/api/v1/alarmdecoder?apikey=11111
  value_template: '{{ value_json.panel_zones_faulted }}'

The problem with this is that I can get 1 or 2 or 3 zones faulting at the same time. How to process this?

Other possibility is to connect to the raw data: http://192.168.1.76:10000

[10000001100000003A--],008,[f70000071008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[00000001100000000A--],004,[f70000071004000028020000000000],"FAULT 04        BASEMENT OFFICE "
[10000001100000003A--],008,[f70000071008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[00000001100000000A--],004,[f70000071004000028020000000000],"FAULT 04        BASEMENT OFFICE "
[10000001100000003A--],008,[f70000071008001c28020000000000]," DISARMED CHIME   Ready to Arm  "
[00000001100000000A--],004,[f70000071004000028020000000000],"FAULT 04        BASEMENT OFFICE "

To do this I am using the following:

sensor 3:
# Example configuration.yaml entry
sensor 3:
  platform: tcp
  name: alarmdecoder
  host: 192.168.1.76
  port: 10000
  timeout: 1
  payload: "" 
  value_template: "{{ value.split(',')[1] }}"
  unit: N

Is this the right way to do this? or should I use an HTP Sensor or REST Sensor or aREST sensor to get this information? With the current definition as a TCP sensor it takes too much time to update the information (minutes).

This is how it looks now in my front page:

It’s for sure that the aREST stuff will not work. The problem that REST and TCP senors are polling and this leads to a delay and missed state changes. For instant notification of Home Assistant the connected systems would need to be able to push state changes.

I think that you could solve your issue with a TCP and a template sensor with a customized scan_interval.

Are you using AD2USB?

Thanks Fabaff. I got things partially working by doing the following:

sensor 2:
platform: rest
scan_interval: 2
name: Ademco
resource: http://192.168.1.76:5000/api/v1/alarmdecoder?apikey=11111111111
value_template: ‘{{value_json.panel_zones_faulted[0]}}’

The only issue with this is that if two zones are faulted at the same time I only got the first one because the value in the template is an array with all the zones that are faulted at the same time.

I had to gave up the TCP option, it was not working as I expected, I am not so sure to what payload to send to the device and the scan_interval was causing me grief with the network.

I am using AD2PI. It offers multiple connectivity options (same software: alarmdecoder).

Cool do share! I want to move my alarm stuff into HA right now it’s in other automation but is shared through serial2sock to AlarmDecoder.

What Platform do you add to configuration, None? Just the code above?

On AlarmDecoder are you using Socket Client? Or Using Socket Server?
My setup is using AlarmDecoder on separate machine so it is using Client but it looks like you are reading the server side of AlarmDecoder for the API, is that right?

Yes that is the only thing that you need to add in your configuration file. One point to note is the fact the Alarmdecoder has two devices (same libraries and same software): one is the serial one: AD2USB, and the other one is AD2PI ( I got this one attached to a RaspberryPi connected to my alarm system (Vista20P)). I am running HASS on a different RaspberryPI and I am connecting to the alarm using the API.

On the picture above, I uses Network, but the connection is local to that device.

So to get this working you are using the AlarmDecoder webbapp for API access?

Yes I am using the API:

Thanks,

Time to setup the webapp! :slight_smile: