Olarm integration

That would be great if you can share. I just fumbled this together so if there is a better way, easier way or just a different way it would be great to see.

Thanks

HI Jason,

Can you maybe do a start to your of your process. I can see my full file view a curl command, but the sensors created from your earlier mail don’t pick up any data.

I’m not programmer, but I can see the logic in the way you query the json file, but I get no data. Your script should be easily moifyable to pick up almost all if I I coudl see my erro?

Any help appreciated from all parties,

Regards,
James

Using curl https://apiv4.olarm.co/api/v4/devices?accessToken=api_ACCESS_TOKEN provides the following output file (slighly sanistised).

{
    "page": 1,
    "pageLength": 40,
    "pageCount": 1,
    "search": "",
    "data": [{
        "deviceId": "XXXX-XXXX-XXXX-XXXX-XXXX",
        "deviceName": "Home",
        "deviceSerial": "AAANAN",
        "deviceAlarmType": "paradox",
        "deviceAlarmTypeDetail": null,
        "deviceTimestamp": 9999,
        "deviceStatus": "online",
        "deviceState": {
            "timestamp": 1675979853713,
            "cmdRecv": 0,
            "type": "",
            "areas": ["stay"],
            "areasDetail": [""],
            "areasStamp": [9999],
            "zones": ["c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c"],
            "zonesStamp": [9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999],
            "pgm": ["c", "c", "c", "c", "c", "c", "c", "c"],
            "pgmOb": ["c", "c"],
            "ukeys": [],
            "power": {
                "AC": "1",
                "Batt": "1"
            }
        },
        "deviceProfile": {
            "areasLimit": 2,
            "areasLabels": ["House", "Garden"],
            "zonesLimit": 16,
            "zonesLabels": ["PIR", "PIR", "BEAM", "ROOM", "BEAM", "PIR", "PIR", "PIR", "BEAM", "BEAM", "DOOR", "Zone12", "Zone13", "Zone14", "Zone15", "Zone16", "Zone17", "Zone18", "Zone19", "Zone 20", "Zone 21", "Zone 22", "Zone 23", "Zone 24", "Zone 25", "Zone 26", "Zone 27", "Zone 28", "Zone 29", "Zone 30", "Zone 31"],
            "zonesTypes": [20, 20, 21, 20, 21, 20, 20, 20, 21, 21, 10, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            "pgmLimit": 8,
            "pgmLabels": ["Panic Radio", "Burglary Radio", "Status LED", "OpenClose Radio", "Output 05", "Output 06", "Output 07", "Output 08"],
            "pgmControl": ["000", "000", "000", "000", "000", "000", "000", ""],
            "pgmObLimit": 2,
            "pgmObLabels": ["", ""],
            "pgmObControl": ["000", "000"],
            "ukeysLimit": 4,
            "ukeysLabels": ["", "", "", ""],
            "ukeysControl": [0, 0, 0, 0]
        },
        "deviceTriggers": {
            "ver": 1,
            "lastCheck": 9999,
            "areasRemind": [
                [99, 9999],
                [0, 0]
            ],
            "zonesIdle": [0, 0],
            "zonesWatch": [
                [12, 0]
            ]
        },
        "deviceTimezone": "Africa/Harare",
        "deviceFirmware": "999.999"
    }]
}

I’m interested.

1 Like

Morning,

Have you created your sensors in HA as per my original post? Could you post a copy of that section in your configuration.yaml so we can take a look.

You an also browse to that URL instead of using curl and you will be able to see the actual numbering of your zones to make sure they are matching what is in your configuration.yaml.

A previous post in this thread mentioned issues with the sensors and after clearing up their configuration.yaml file things started working so you also need to make sure the format etc. of your file is correct and there are no issues.

Unfortunately I am also not a programmer so this has all been done through many hours of searching and reading many many posts and piecing things together but I can definitely try and help as best I can.

I am also interested in your solution Tim :grinning:

HI Jason,

configuration.yaml with your sensors is as follows:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
# base_url: X.X.X.X:8123

# Text to speech
tts:
  - platform: google_translate
#    language: 'en'

##### YAML File Locations ##################################
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml


#########################################################
# OLARM INTEGRATION TRIAL
#########################################################
#### Olarm Data ####
rest:
  - resource: https://apiv4.olarm.co/api/v4/devices
    method: GET
    headers:
      Authorization: Bearer !secret olarm_api
    scan_interval: 5

    sensor:
    - name: OlarmName
      value_template: "{{ value_json.deviceName }}"
      unique_id: UniqueID-XXXX
    - name: getolarmstatus

      value_template: "{{ value_json.data[0].deviceState.areas[0] }}"

    - name: get-olarm-status
      value_template: "{{ value_json.data[1] }}"
    - name: OlarmStatus
      unique_id: UniqueID-XXXX-OlarmStatus
      value_template: "{{ value_json.data[7] }}"

#      value_template: "{{ value_json.data[0].deviceState.areas[0] }}"
#      value_template: >
#        {% if states('switch.upstairs_cam_motion_detection') == "On" %}
#          Motion Detected
#        {% else %}
#          No Motion Detected
#        {% endif %}  

    - name: Zone 01 - Olarm - BackdoorBeam
      value_template: "{{ value_json.data[0].deviceState.zones[0] }}"
      unique_id: XXXX-Zone01

    - name: Zone 02 - Olarm - Bedroom
      value_template: "{{ value_json.data[0].deviceState.zones[1] }}"

    - name: Zone 03 - Olarm - PoolBeam
      value_template: "{{ value_json.data[0].deviceState.zones[2] }}"

    - name: Zone 04
      value_template: "{{ value_json.data[0].deviceState.zones[3] }}"

    - name: Zone 05
      value_template: "{{ value_json.data[0].deviceState.zones[4] }}"

    - name: Zone 06
      value_template: "{{ value_json.data[0].deviceState.zones[5] }}"

    - name: Zone 07
      value_template: "{{ value_json.data[0].deviceState.zones[6] }}"

    - name: Zone 08
      value_template: "{{ value_json.data[0].deviceState.zones[7] }}"

    - name: Zone 09
      value_template: "{{ value_json.data[0].deviceState.zones[8] }}"

    - name: Zone 10
      value_template: "{{ value_json.data[0].deviceState.zones[9] }}"

    - name: Zone 11
      value_template: "{{ value_json.data[0].deviceState.zones[10] }}"

    - name: Zone 12
      value_template: "{{ value_json.data[0].deviceState.zones[11] }}"

    - name: Zone 13
      value_template: "{{ value_json.data[0].deviceState.zones[12] }}"

    - name: Zone 14
      value_template: "{{ value_json.data[0].deviceState.zones[13] }}"

    - name: Zone 15
      value_template: "{{ value_json.data[0].deviceState.zones[14] }}"

    - name: Zone 16
      value_template: "{{ value_json.data[0].deviceState.zones[15] }}"

#########################################################
## CAMERA SETTINGS
#########################################################
stream:
ffmpeg:

#########################################################
# SONOFF GENERIC CAMERA
#########################################################

camera:
  - platform: generic
    name: Sonoff_Camera
    still_image_url: http://192.168.20.30/jpg/image.jpg
    stream_source: rtsp://rtsp:[email protected]:554/av_stream/ch0

Balance is camera related and not causing errors.
I’m a real novice on this, so just can’t see the errors.

In states I see as below:

In settings entities, I get

image

Driving me insane.

and finally, blank sensor
image

Very interested Tim.

Hi, will you please share your configuration with me. Really struggling to get this working.

I’m also interested

Okay so I will try explain as well as provide some config examples.

First I created a REST sensor (Simply a sensor that is based off a REST API call). This is created in your sensors.yaml file.

Example:

- platform: rest
  name: Olarm
  resource: https://apiv4.olarm.co/api/v4/devices/{your-olarm-device-id}
  scan_interval: 300
  headers:
    authorization: !secret olarm_access_key
  json_attributes:
    - deviceId
    - deviceName
    - deviceSerial
    - deviceAlarmType
    - deviceTimestamp
    - deviceStatus
    - deviceState
    - deviceProfile
  value_template: "OK"

In the above sensor, I set the header to contain your API key (Saved in your secrets.yaml. This is to authenticate the request.
I then set the scan interval to 300 seconds (5min). So it will call the endpoint (the resource), every 5 min to get the latest state of the device. You can set this to a longer interval if you want.

Then you will notice I set the state of this sensor as a value template and set it to just “OK”.
This is very important!!
You cannot set the full response object of the REST call as the state of a sensor (It’s too large). A sensor state has a length limit of 255 characters.
Instead, you create attributes for the sensor and set them to parts of the response object that you want to use. Attributes do not have this limit of 255 characters.

The attributes I use are explained below.

For the device details:

  • deviceId - The id of your olarm device
  • deviceName - Name of the device
  • deviceSerial - Serial of the device
  • deviceAlarmType - Type of device
  • deviceTimestamp - Current date from the device
  • deviceStatus - Status of the device

Then there are 2 sections/inner objects in the response:

  • deviceState - This contains the states of each zone, area, alarm, etc.
  • deviceProfile - This contains the labels of each zone, area labels, zone types etc.

You can check the above for yourself by using insomnia or postman and send a HTTP GET request to get your device. (You will see the structure in the response and where these sections are from.

From the above attributes, you then create template sensors for your Zones, and areas:

For example (in your templates.yaml file:

# Olarm Zones
# Electric Fence
- sensor:
    - name: Olarm Zone 1
      attributes:
        zone_label: "{{ state_attr('sensor.olarm', 'deviceProfile')['zonesLabels'][0] }}"
      state: >
        {% if is_state('binary_sensor.olarm_zone_alarm', 'on')
          and is_state_attr('sensor.olarm_event', 'event_num', '1' ) %}
          Alarm
        {% elif state_attr('sensor.olarm', 'deviceState')['zones'][0]=='c' %}
          Closed
        {% elif state_attr('sensor.olarm', 'deviceState')['zones'][0]=='a'%}
          Active
        {% elif state_attr('sensor.olarm', 'deviceState')['zones'][0]=='b'%}
          Bypassed
        {% endif %}

My setting of the state is a bit complex as it can come from different sources (The main REST sensor - called sensor.olarm that I explained above, but also from events that Olarm send out via a Webhook that you regiser on their API. This allows you to get real time states from the system.
Otherwise you will only see updates to the zones, areas etc once every 5min (When the REST sensor runs).
So I basically check when the webhook comes in if it relates to zone 1 (Electric fence). If it does, then I update the state (Usually an alarm).
If not, then it could be an event like disarming an area, then I do not care about it and set the Electric fence sensor to what it was in the REST sensors last response:

state_attr('sensor.olarm', 'deviceState')['zones'][0]

This is just the notation to get to the inner child object(In this case, my electric fence zone of the deviceState attribute in the REST sensor.

And this zone only has 3 states: closed, active, or bypassed (c,a, or b) - This cab be found in the Olarm API docs.

Here is an example of a sensor I created that is basically set everyime Olarm sends me an event via a webhook :

# Olarm Event Sensor
- sensor:
    - name: Olarm Event
      attributes:
        event_action: "na"
        event_num: "na"
        event_msg: "na"
        event_time: "na"
      state: "na"

These attributes I set from the webhook response, this is done via an automation that listens for a webhook from Olarm. Which sets each of those values. The default values are set as “na” before I get the actual values from an event (On HA startup for example). Once I get at least 1 event, they will be updated with the correct values from the Webhook.

Then one more type of sensor I created which can also update my zone sensors, and area sensors, this is a zone alarm sensor.
This is because after some testing, Olarm can send the following types of events:

  • Area events - Arm/Disarm/Stay/Sleep/Area Alarm/Emergeancy/
  • Power events - Power restore or failure
  • Zone Alarms - These are alarms specific to a zone (Like door being opened).
  • A Alarm - This is a strange one, seems Panics come in as this type, and not any of the above. Not sure why.

So basically I create additional sensors for the above events, these then update the correct zone/area when they are triggered.

This provides all you should need to get status from your system.

However there is one more thing, that is the ability to arm/disarm from home assistant.
This I do with REST commands in home assistant.
These can be executed in an automation (Like pressing a button).

Here is an example of one that arms my one ares:

olarm_area_1_arm:
  url: "https://apiv4.olarm.co/api/v4/devices/{your-olarm-device-id}/actions"
  method: post
  headers:
    authorization: !secret olarm_access_key
  content_type: "application/json"
  payload: '{"actionCmd":"area-arm","actionNum":1}'

This is not a sensor, as we are not storing the result, like in my REST sensor, here we are performing a command (HTTP POST).
This allows you to send a request to arm, and then Olarm will send an event via the webhook confirming that Area 1 is armed.
And hence update the area 1 sensor.

I then have a dashboard with all this wired up (Perhaps another post to explain that one).
But here is a screenshot of my Olarm dashboard with 2 tabs:

The first tab is where I can send commands (Arm, disarm etc) - The top shows the state of each area.
In the second tab you can see the current state of each zone (Closed, Active, Bypassed, or Alarm)
I also added the power state so I know when the power is off or on from the dashboard too.

The above is quite a lot to digest.
I am happy to actually take anyone through my entire setup and show you how it all works and is wired up and provide some help in setting yours up to work.
Just let me know. We can do a Discord/Zoom call.

Hope this helps some of you.

Many thanks. My initial attempts to get this working are not so good. I think I must book an afternoon to check more closely!

Sure. Just let me know when. I’m free this coming week

Hi Tim

Just a BIG THANK YOU for sharing your method. Never worked with Webhooks before, but after 2days of playing and learning I am starting to win.

Webhook notification workings. Going to see how to update the status in realtime for the sensors (currently making use of the rest platform)

2 Likes

Hi Jakes, can you maybe help me with the steps to set up my webhooks as i tried but had no success with this :grinning:

Hi there. Happy to help where possible with this. Note i am still learning aswell. How do you access your home assistant instance remotely.

Nabu Casa Jakes

Thanks for all the work into this. I just wanted to confirm what the expected update interval is from opening a zone and having it update in your HA ? Mine currently takes around 2-4 minutes before the state updates.

image

Hi there, My apologies for the late response. Working just keeping me busy. Will send through some steps later tonight.

Thank you Jakes :blush: