Adding Shared-Notification to Home Assistant

If you’re like me, wasting money and depending on an obsolete archaic technology to monitor my home isn’t my cup of tea.  So instead of wasting money on ineffective monitoring, my friend and I setup a SharedNotification Neighbourhood Watch. I’ve dabbled with Home Assistant in the past while my friend is a OpenHAB fan so we assist others in our community to setup an SharedNotification Neighbourhood Watch. I’ll only discuss how to setup SharedNotification with Home Assistant. In a future blog I’ll do the same for OpenHAB.

Our traditional Commercial Monitoring Centre (CMC) was developed over 70 years ago and their method of monitoring require revolutionizing.  Let us begin by first considering totally abandoning CMC for home monitoring in urban community and reverting to a more effective method of deterrent – Neighbourhood Monitoring Centre (NMC).

If your alarm system is capable of sending and receiving HTTP request, most specifically GET and POST request, then let’s start by first registering for a SharedNotification account or by asking someone who already have a SharedNotification account for API-Key and NID.

 With and API-Key and NID (optional), posting your alert to Shared-Notification server is very simple. For example, the server assigned you the following information:

NID: 1682389630392-42177

API-Key: 66c5b8a0-e30c-11ed-bc4f-053451ed971b

HID: 1682706990354-17286

You’ll also need to choose a broadcast name, enter your address and a non-specific address. This information will be display to your neighbours so care should be taken when choosing it.  Non-Specific Address are used in communities where retaliation is a strong possibility.

Broadcast Name (bcname): ELZINIE

Address (from): 123 Evergreen Terrace

Non-Specific Address (ns_address): 100 – 140 Evergreen Terrace

An example of how to shared a PANIC alert with your community: create an automation that is triggered when the panic button is a long_press. There is no condition on this automation. The automation will execute a script to send this alert to SharedNotification.

Automation’s action will be to execute a script to post this panic alert, notify all devices, and turn_on siren for a specific duration and audio level. Home Automation is capable of preforming tons of actions but I limit this example to something simple.

The script uses the above information, obtain during registration for a ShareNotification account, to communicate with it.

rest_command.yaml

post_panic_request:
  url: https://sharenotification.com/api/notifier?apikey={{API_KEY}} 
  method: POST
  headers:
    accept: "application/json"
  content_type:  'application/json; charset=utf-8'      
  payload: '{"type": "{{PAYLOAD_TYPE}}", "bcname": "{{PAYLOAD_BCNAME}}", "msg": "{{PAYLOAD_MSG}}", "tt": "{{PAYLOAD_TT}}", "hid": "{{PAYLOAD_HID}}", "location": {"position": {"latitude": {{PAYLOAD_LATITUDE}}, "longitude": {{PAYLOAD_LONGITUDE}}}}}'

scripts.yaml

execute_panic_alert:
  alias: 'Transmit PANIC alert to server'
  sequence:
  - service: rest_command.post_panic_request    
    data: 
      {"PAYLOAD_TYPE": PANIC, 
      "PAYLOAD_BCNAME": ELZINIE, 
      "PAYLOAD_MSG": Panic Alert Triggered, 
      "PAYLOAD_TT": "{{ now().timestamp() | timestamp_custom('%a %m-%d-%Y %-I:%M %p') }}",
      "PAYLOAD_HID": 1689789583296-98503, 
      "PAYLOAD_LATITUDE": 43.788013441318974, 
      "PAYLOAD_LONGITUDE": -79.66491194227804,
      "API_KEY": 66c5b8a0-e30c-11ed-bc4f-053451ed971b} 
  mode: single

automations.yaml

- id: '1689090843657'
  alias: handle_panic_button
  description: Send PANIC Alert to Shared-Notification server
  trigger:
  - device_id: 091f77a709485d572fbdcd2c8b2bab1b
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: button
  condition: []
  action:
  - service: siren.turn_on
    data:
      volume_level: 0.45
      duration: '60'
    target:
      device_id: 15ed99c05b3ffe4c768541d5e5246c1a
  - service: notify.mobile_app_mani_iphone
    data:
      message: Panic Alert was triggered - 44 Oklahoma Drive
      title: Neighbourhood Watch (ELZINIE) 
  - service: notify.mobile_app_noahs_iphone
    data:
      title: Neighbourhood Watch (ELZINIE)
      message: Panic Alert was triggered - 44 Oklahoma Drive
  - service: script.execute_panic_alert
    data:
      title: Neighbourhood Watch (ELZINIE)
      message: Panic Alert was triggered - 44 Oklahoma Drive
  - type: turn_off
    device_id: 49accc88f383f1ce7b6903b07e3f2a07
    entity_id: bf4aab00641bd93a005977e35f8b73b6
    domain: light
  mode: single

To receive updates from SharedNotification server, you can either periodically request updates or the server can push updates to you when it’s available. Updates are alerts from your neighbours who are in your neighbourhood network. You have the option to block update from any neighbour if desire.

For SharedNotification to push updates to you, you need to create a webhook automation with HID be the webhook ID (webhook_id).

Automations.yaml

- alias: sharednotification will send neighbourhood alerts to this webhook
  trigger:
  - platform: webhook
    webhook_id: 1682706990354-17286
    allowed_methods:
    - POST
    local_only: true
  action:
  - service: notify.persistent_notification
    data:
      title: Neighbourhood Watch - {{ trigger.json.bcname }}
      message: '{{ trigger.json.msg }} - {{ trigger.json.from }}'
  - service: notify.mobile_app_mani_iphone
    data:
      title: Neighbourhood Watch - {{ trigger.json.bcname }}
      message: '{{ trigger.json.msg }} - {{ trigger.json.from }}'
  - service: siren.turn_on
    data:
      volume_level: 0.45
      duration: '15'
    target:
      device_id: 15ed99c05b3ffe4c768541d5e5246c1a

  id: 2465443cf382444f9e8d3a7dace8616d

For periodically requesting updates, you need to create a REST sensor with a long scan interval (scan_interval). This example uses a 1-year interval (31557600 seconds) and uses automation to force the periodical request for updates. Home Assistant uses homeassistant.update_entity to force reset.

automations.yaml

- alias: update_request
  trigger:
  - platform: time_pattern
    minutes: /1
  action:
  - service: homeassistant.update_entity
    entity_id: sensor.sharednotification
  - service: notify.mobile_app_mani_iphone
    data:
      message: '{{ state_attr(''sensor.sharednotification'',''msg'') }}'
      title: '{{ state_attr(''sensor.sharednotification'',''bcname'') }}'
  - service: persistent_notification.create
    data:
      message: '{{ state_attr(''sensor.sharednotification'',''msg'') }}'
      title: '{{ state_attr(''sensor.sharednotification'',''bcname'') }}'
  id: 45360775688a4f9ab39865aaa8f9ff9f 

sensor.yaml

- platform: rest
  name: sharednotification
  scan_interval: 31557600
  resource_template: "http://sharednotification.com/api/inbox/gethidanddelete?hid=1689789583296-98503&apikey=66c5b8a0-e30c-11ed-bc4f-053451ed971b"
  json_attributes:
      - bcname
      - message
      - from
      - msg
    value_template: '{{ value_json }}' 

Good luck. I hope this example was useful.