Bridge from P2PQuake to Home Assistant via MQTT https://www.p2pquake.net/
  • Python 98.9%
  • Dockerfile 1.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-30 07:02:55 +00:00
p2pquake Update python Docker tag to v3.14 2026-06-30 03:21:39 +00:00
LICENSE Initial commit 2026-06-29 04:01:46 +00:00
README.md Rename sandbox->test_mode, regions->earthquake_regions, add tsunami_regions 2026-06-30 01:58:55 +09:00
renovate.json Add Renovate config for dependency updates 2026-06-30 10:12:54 +09:00
repository.yaml Restructure as HA add-on repository 2026-06-30 00:22:23 +09:00

P2Pquake Bridge (Home Assistant add-on)

Bridges P2P地震情報 (P2Pquake) Earthquake Early Warning (緊急地震速報・警報, code 556) and Tsunami Warnings (津波予報, code 552) from the v2 WebSocket to your MQTT broker, with Home Assistant MQTT discovery.

It connects to the P2Pquake WebSocket, filters earthquake and tsunami messages, de-duplicates them by id, and republishes to MQTT. Reconnection (including the test endpoint's 10-minute forced disconnect) and broker credential discovery are handled for you.

Not a life-safety system. P2Pquake states the content and delivery quality are unguaranteed and run without redundancy — an outage means no delivery and no catch-up. Keep your phone's cell-broadcast alert as the authoritative source; treat this as a convenience/automation layer.

Install

  1. In Home Assistant, go to Settings → Add-ons → Add-on Store.
  2. Open the ⋮ menu (top-right) → Repositories.
  3. Add https://git.tiuxo.com/brian/ha-p2pquake and click Add.
  4. Close the dialog — P2Pquake Bridge now appears in the store.
  5. Open it → Install → Start. Enable Watchdog and Start on boot on the add-on's info page.

No MQTT settings to enter: with services: mqtt:need the add-on pulls the broker host/credentials from the Supervisor MQTT service — the same Mosquitto your Zigbee2MQTT already uses.

Building locally

To build the image yourself instead of pulling from the registry, clone this repo into /addons/ on your HA host, remove the image: line from p2pquake/config.yaml, and install from the local add-ons section.

Options

Option Default Meaning
test_mode false Use the P2Pquake test WebSocket and publish synthetic test events on startup so you can verify the whole pipeline without waiting for a real quake. Set back to false for live data.
base_topic p2pquake MQTT topic prefix.
earthquake_regions [] (all) List of 府県予報区 regions to monitor for earthquake warnings. Only warnings that predict shaking in at least one listed region are published. An empty list means all regions (nationwide). Cancellations always pass through.
earthquake_expiry 600 Seconds after which the earthquake sensor resets to 待機中 (standing by). Set to 0 to keep the last warning indefinitely.
tsunami_regions [] (all) List of 津波予報区 regions to monitor for tsunami warnings. Only warnings that include at least one listed region are published. An empty list means all regions (nationwide). Cancellations always pass through.
tsunami_expiry 3600 Seconds after which the tsunami sensor resets to 待機中. Set to 0 to keep the last warning indefinitely.
verbose false Debug logging.

What it creates

  • sensor.p2pquake_earthquake — Earthquake Early Warning sensor. State is 待機中 (standing by) when idle, or a summary string during/after a warning. Attributes include max_scale, max_intensity, hypocenter, magnitude, cancelled, test, per-area predictions, and raw. Resets to 待機中 after earthquake_expiry seconds.

  • sensor.p2pquake_tsunami — Tsunami Warning sensor. State is 待機中 when idle, or a summary string during a tsunami advisory. Attributes include grade, grade_label, cancelled, per-area details (grade, arrival time, max height), and raw. Resets to 待機中 after tsunami_expiry seconds.

MQTT topics

Earthquake:

  • p2pquake/earthquake — non-retained, one message per earthquake report. Trigger automations here.
  • p2pquake/earthquake/last — retained, drives the earthquake dashboard sensor.

Tsunami:

  • p2pquake/tsunami — non-retained, one message per tsunami report. Trigger automations here.
  • p2pquake/tsunami/last — retained, drives the tsunami dashboard sensor.

Shared:

  • p2pquake/status — retained online/offline availability (LWT).

Reference values

Earthquake intensity (max_scale / scale_to) uses JMA's ×10 convention: 45 = 震度5弱, 50 = 5強, 55 = 6弱, 60 = 6強, 70 = 7.

Tsunami grade:

API value Japanese English
MajorWarning 大津波警報 Major tsunami warning
Warning 津波警報 Tsunami warning
Watch 津波注意報 Tsunami advisory

Example automations

Earthquake — strong shaking near me

With earthquake_regions configured in the add-on options, every warning that reaches MQTT already affects your area:

alias: Earthquake – strong shaking near me
mode: queued
trigger:
  - platform: mqtt
    topic: p2pquake/earthquake
condition:
  - condition: template
    value_template: >-
      {% set p = trigger.payload_json %}
      {{ not p.cancelled and (p.max_scale | int(-1)) >= 45 }}
action:
  - service: light.turn_on
    target:
      entity_id: light.living_room

Adjust the >= 45 threshold to control the minimum intensity.

If you leave earthquake_regions empty (nationwide) you can filter by prefecture in the condition instead:

      {{ not p.cancelled
         and (p.max_scale | int(-1)) >= 45
         and '東京' in (p.areas | map(attribute='pref') | join('|')) }}

Prefecture strings use the 府県予報区 pref value from the API (e.g. 東京, 北海道道南, 宮城) — not the full 都道府県 name.

Tsunami — any warning or advisory

alias: Tsunami warning
mode: queued
trigger:
  - platform: mqtt
    topic: p2pquake/tsunami
condition:
  - condition: template
    value_template: >-
      {% set p = trigger.payload_json %}
      {{ not p.cancelled }}
action:
  - service: notify.notify
    data:
      title: "Tsunami {{ p.grade_label }}"
      message: "{{ trigger.payload_json.summary }}"

To filter by severity, check grade: MajorWarning, Warning, or Watch.

Verifying

Set test_mode: true and start the add-on. On startup it publishes synthetic test events for both earthquake and tsunami, populating the sensors immediately. The test WebSocket also replays real 2023 data (earthquake warnings, quake info, and tsunami warnings in sequence, ~30 s apart), though code 556 events are sparse in the replay. Confirm your automations fire, then set test_mode: false and restart for live data.