Olarm integration

Hi @TGouws. Apologies for the delay, it has been a hetic work week and just finished. Oki doki, so high level, this is the steps I took to make sure my webhook works

  1. Create a new Automation. Add a new trigger. The trigger should be webhook.

  2. This will auto generate a webhook ID.

  3. Create a new TEMPLATE Condition in the automation. Mine is a little bit complex. But to get you started, click condition, select template and add the json code. Example: {{trigger.json.eventState == ‘arm’}}. The arm attribute can be replaced by disarm, sleep, bypass etc. More information can be found on Olarm’s API docs Olarm - User Portal

  4. Under action, I setup a delay for 1 minute as the API takes a few seconds to update and show the correct state. This is only needed as i send a actionable notification to my mobile device and would prefer to see the correct state :slight_smile:

  5. Afterwards i set the second action to notify my mobile devices or tablets. Example of this

service: notify.mobile_app_wall_tablet
data:
  message: >-
    Inside Area set to {{states('sensor.olarm_status_for_inside_area')}} and
    Outside Area to {{states('sensor.olarm_status_for_outside_area')}}
  title: ALARM STATUS
  1. Important to note, i setup a separate sensor template to show the status of my Inside and Outside area so that i can display the correct state when the notification is send.

Ok, almost done, for all of this to work we still need to enable the webook for the above and then copy the Nabu Casa webhook to Olarm.

So for the Home Assistant part. Save your automation, then go SETTINGS → HOME ASSISTANT CLOUD. Scroll to the bottom and enable the Webhook. You can give a friendly name so that you do not forgot it.

Once done, click on MANAGE and copy the webhook URL. This URL must be pasted under Olarm under the “Setup Webhook” setting. Add a secret and save.

Test your automation. Hope this helps

IMPORTANT, there could be a much better way of doing this. The community is extremely helpful, and I am sure more people will get involve here.

This currently works in my setup and I am still learning as we go a long aswell :slight_smile:

Hi all, I think this process is driving me to distraction. I have tried both of the main processes above and get the following results:

Option 1:
Using below in configuration.yaml as per Jason

rest:
  - resource: https://apiv4.olarm.co/api/v4/devices
    method: GET
    headers:
      authorization: Bearer !secret olarm_api
    scan_interval: 30
    sensor:
    - name: Olarm_Zone_1
      value_template: "{{ value_json.data[0].deviceState.zones[0] }}"
   - name: OlarmStatus
      value_template: "{{ value_json.data[0].deviceState.areas[0] }}"

gives the following errors in home-assistant.log:

2023-02-23 13:53:47.260 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://apiv4.olarm.co/api/v4/devices
2023-02-23 13:53:47.616 DEBUG (MainThread) [homeassistant.components.rest] Finished fetching rest data data in 0.355 seconds (success: True)
2023-02-23 13:53:47.616 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: Forbidden
2023-02-23 13:53:47.616 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.data[0].deviceState.zones[0] }}'
2023-02-23 13:53:47.621 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: Forbidden
2023-02-23 13:53:47.622 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.data[0].deviceState.areas[0] }}'

In the above, the link seems to be accessing the wrong HTML page link, as that error also comes just using a browser without the correct key and device ID.

Option 2:
Using below in sensors.yaml as per Tim

#### Olarm Data ####
- platform: rest
  name: olarm
  headers:
    content-type: application/json
    authorization: Bearer !secret olarm_api
  resource: https://apiv4.olarm.co/api/v4/devices/aaa9aaa-9999-9a99-9999-9aaa9aaa9999
  scan_interval: 60
  json_attributes:
    - data
    - data.deviceId
    - deviceId
    - deviceName
    - deviceSerial
    - deviceAlarmType
    - deviceAlarmTypeDetail
    - deviceTimestamp
    - deviceStatus
    - deviceState
    - deviceState.zones[]
    - deviceProfile
    - deviceProfile.zonesLimit
    - deviceProfile.zonesLabels[]
  value_template: "OK"

and in templates.yaml

- sensor:
    - name: Olarm_Zone01
      unique_id: zzzzz-Olarm_Zone01
      attributes:
        zone_label: "{{ state_attr('sensor.olarm', 'deviceProfile')['zonesLabels'][0] }}"
      state: >
          {% if 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 %}

gives the following errors in home-assistant.log:

2023-02-23 14:02:55.598 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{% if 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 %}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 457, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1984, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py", line 303, in getitem
    return obj[argument]
jinja2.exceptions.UndefinedError: 'None' has no attribute 'zones'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 575, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 459, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'zones'
2023-02-23 14:02:55.610 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ state_attr('sensor.olarm', 'deviceProfile')['zonesLabels'][0] }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 457, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1984, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py", line 303, in getitem
    return obj[argument]
jinja2.exceptions.UndefinedError: 'None' has no attribute 'zonesLabels'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 575, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 459, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'zonesLabels'
2023-02-23 14:02:55.612 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('UndefinedError: 'None' has no attribute 'zones'') while processing template 'Template("{% if 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 %}")' for attribute '_attr_native_value' in entity 'sensor.olarm_zone01'
2023-02-23 14:02:55.613 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('UndefinedError: 'None' has no attribute 'zonesLabels'') while processing template 'Template("{{ state_attr('sensor.olarm', 'deviceProfile')['zonesLabels'][0] }}")' for attribute 'zone_label' in entity 'sensor.olarm_zone01'

HI All, Goes to show that a break and a few more google searches pays off.

This suggests that the “Bearer” part of the authorisation is moved from the Rest Sensor to the “secret”

In this instance:

authorization: Bearer !secret olarm_api

becomes

authorization: !secret olarm_api

and your secret becomes:

olarm_api: Bearer api_99a9999a9aa9...….. etc

and viola… sensor.olarm now carries all the data as would be expected…

and the log file shows (sanitised):

2023-02-23 19:24:39.575 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {"deviceId":"XXXX-XXXX-XXXX-XXXX-XXXX","deviceName":"Home)","deviceSerial":"XXXXXX","deviceAlarmType":"paradox","deviceAlarmTypeDetail":null,"deviceTimestamp":999999,"deviceStatus":"online","deviceState":{"timestamp":999999,"cmdRecv":0,"type":"","areas":["disarm"],"areasDetail":[""],"areasStamp":[99999],"zones":["c","a","c","c","c","c","c","c","c","c","c","c","c","c","c","c"],"zonesStamp":[99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999],"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":["Zone1","Zone2","Zone3","Zone4","Zone5","Zone6","Zone7","Zone8","Zone9","Zone10","Zone11","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":99999,"areasRemind":[[99,99],[0,0]],"zonesIdle":[0,0],"zonesWatch":[[12,0]]},"deviceTimezone":"Africa/Harare","deviceFirmware":"210.094"}

Once I’ve managed a few sensors, will do a breakdown of what is working for me.

@timjhastie
I’ve been able to setup the rest sensor for the api, I am now moving on to use the webhook for “live” state updates.
Can you perhaps share a sample of the typical automation setup where you use the webhook to update a sensor’s state?

@PieterGH,

Glad to hear you are also winning. Also struggling with the webhook for live state / attribute updates. Want to use this for motion in the house.

Busy with a work around whereby i managed to create an automation using the webhook and then a json value template with condition to trigger if the sensor is Active, Bypassed or Armed. Problem is I forgot to save and know trying to figure out how i wrote the json template :-). Will share once i figured it out again. :slight_smile:

Tim, I have managed to get a large portion of this process working. One of the big pieces that is missing is how to translate the webhook to update the sensor you have shown above.

Sorry for the late reply.

Here you go:

alias: Webhook - Olarm Event
description: Olarm Webhook event update
trigger:
  - platform: webhook
    webhook_id: "{your unique id}"
condition: []
action:
  - service: rest_command.olarm_update_sensor
    data:
      sensor_id: sensor.olarm_event
      state: "{{trigger.json.eventState}}"
      event_action: "{{trigger.json.eventAction}}"
      event_msg: "{{trigger.json.eventMsg}}"
      event_time: "{{trigger.json.eventTime}}"
      event_num: "{{trigger.json.eventNum}}"
  - service: notify.mobile_app_tim_phone
    data:
      message: "{{trigger.json.eventMsg}}"
      title: "{{trigger.json.eventAction}}"
mode: queued
max: 10

1 Like

Hi Tim,
Many thanks for the above. Only piece I can’t understand is olarm_update_sensor, is that another Rest GET call somewhere/

It’s a built in rest command you can perform.
I’ll go through everything in a session. I think it’ll be easier

1 Like

Hi All,

You can have a look at my Olarm Integration here:
It currently has all the same features as the Olarm app. I hope this can be of assistance to some people.

2 Likes

Hi Raine, thank you for your integration works great but I am only struggling with the services on this :grinning:.

Figured it out at last thank you :smiley:

Hi Raine,

Brilliant, thanks! I had a bug on my end due to how olarm might have been set up for me. Happy to do a PR some time?

Hi @Rainepretorius

The integration works 100% and extremely easy to setup. Assit me a lot regarding my current templates.
Busy creating a card in Home Assistant. Still work in progress. Consist mainly out of the custom button card


S

3 Likes

Hi Jakes

The card looks great.
Can you please share the code that you have used for this card, thank you.

Happy to help out any time

Looks amazing.

Thank you Raine , I was able to figure it out eventually :smiley: . Wish we could have had the zone bypass also that would have been great for some additional automations.

I will be working on it as the next feature.