Template binary sensor ajax event

Hi all,

I have made a template from a different thread. But there is one issue, it only respond to one trigger and then goes to auto_off even if the door is still open.

I would like i to open based on one trigger and closed based on the other.

When the event send code “BA” and message “1” its open
When the event sends code “BR” and the message is “1” its closed.

Can someone help me change this template?

template:
  trigger:
    platform: event
    event_type: sia_event_8124_ABCDEF
    event_data:
      code: 'BA'
      message: '1' # This is the device number
  binary_sensor:
    - name: Utgangsdør_ajax
      device_class: door
      auto_off: 5 #just set to off after 5s when is triggered
      state: "true"

Incase the event is needed:

Event 38 fired 8:41 PM:
{
“event_type”: “sia_event_8124_ABCDEF”,
“data”: {
“message_type”: “SIA-DCS”,
“receiver”: null,
“line”: “L0”,
“account”: “ABCDEF”,
“sequence”: “9987”,
“content”: “#ABCDEF|Nri1/BA1]_19:41:06,01-06-2022”,
“ti”: null,
“id”: null,
“ri”: “1”,
“code”: “BA”,
“message”: “1”,
“x_data”: null,
“timestamp”: “2022-01-06T19:41:06+00:00”,
“event_qualifier”: null,
“event_type”: null,
“partition”: null,
“extended_data”: null,
“sia_code”: {
“code”: “BA”,
“type”: “Burglary Alarm”,
“description”: “Burglary zone has been violated while armed”,
“concerns”: “Zone or point”
}
},
“origin”: “LOCAL”,
“time_fired”: “2022-01-06T19:41:44.491862+00:00”,
“context”: {
“id”: “48ee2c1ae2c7676bf133b20e4db6f8d2”,
“parent_id”: null,
“user_id”: null
}
}
“origin”: “LOCAL”,
“time_fired”: “2022-01-06T19:41:49.503809+00:00”,
“context”: {
“id”: “e6c3e7345f6200a8c7f98d67348913aa”,
“parent_id”: null,
“user_id”: null
}
}

Event 39 fired 8:41 PM:
{
“event_type”: “sia_event_8124_ABCDEF”,
“data”: {
“message_type”: “SIA-DCS”,
“receiver”: null,
“line”: “L0”,
“account”: “ABCDEF”,
“sequence”: “9988”,
“content”: “#ABCDEF|Nri1/BR1]_19:41:11,01-06-2022”,
“ti”: null,
“id”: null,
“ri”: “1”,
“code”: “BR”,
“message”: “1”,
“x_data”: null,
“timestamp”: “2022-01-06T19:41:11+00:00”,
“event_qualifier”: null,
“event_type”: null,
“partition”: null,
“extended_data”: null,
“sia_code”: {
“code”: “BR”,
“type”: “Burglary Restoral”,
“description”: “Alarm/trouble condition has been eliminated”,
“concerns”: “Zone or point”
}
},
“origin”: “LOCAL”,
“time_fired”: “2022-01-06T19:41:49.503809+00:00”,
“context”: {
“id”: “e6c3e7345f6200a8c7f98d67348913aa”,
“parent_id”: null,
“user_id”: null
}
}

Try something like this:

template:
  trigger:
    - id: 'on'
      platform: event
      event_type: sia_event_8124_ABCDEF
      event_data:
        code: 'BA'
        message: '1' # This is the device number
    - id: 'off'
      platform: event
      event_type: sia_event_8124_ABCDEF
      event_data:
        code: 'BR'
        message: '1' # This is the device number
  binary_sensor:
    - name: Utgangsdør_ajax
      device_class: door
      state: "{{ trigger.id == 'on' }}"
1 Like

Thank you!

I get this error:

Logger: homeassistant.config
Source: config.py:464
First occurred: 8:11:57 PM (1 occurrences)
Last logged: 8:11:57 PM

Invalid config for [template]: expected str for dictionary value @ data[‘trigger’][0][‘id’]. Got True. (See /config/configuration.yaml, line 272).

on and off translate to true/false when they aren’t wrapped in quotes. Wrap the on and off in quotes for the trigger id’s in each trigger.

1 Like

Excellent! Thank you! Works like a charm :slight_smile:

can you share with us the corrected script? I am having a hard time understanding where I should add the quotes, thank you very much