A Home Assistant custom integration to monitor local National Grid power cut information by postcode.
The integration queries the National Grid connected data API:
https://connecteddata.nationalgrid.co.uk/api/3/action/datastore_search
Use the button above, or add it manually:
-
Open HACS.
-
Go to Integrations.
-
Select Custom repositories from the menu.
-
Add this repository URL as an Integration:
https://github.com/djbenson/ha-nationalgrid-powercut -
Install National Grid Power Cut and restart Home Assistant.
Copy custom_components/national_grid_power_cut into your Home Assistant
custom_components directory and restart Home Assistant.
After installing and restarting Home Assistant, use the button above, or add the integration from Settings > Devices & services > Add integration and search for National Grid Power Cut.
The config flow asks for:
Postcode: the UK postcode to search for live outage records.Refresh interval: how often to poll the National Grid API, from 5 to 60 minutes.
The refresh interval can be changed later from the integration's options.
The integration creates these entities for each configured postcode:
binary_sensor.power_cut_reported: on when the API returns one or more matching outage records. Detailed incident records are exposed as attributes.sensor.incident_count: number of matching outage records.sensor.status: status for the most relevant/current incident, orNo power cut reported.sensor.estimated_restoration_time: timestamp from the incidentetrfield.sensor.planned_outage_start: timestamp for a matching planned outage start.
Fields such as fault_id, category, planned, resource_status,
customer counts, voltage, location, reported/restoration dates, and planned
outage details are exposed as attributes on the relevant entities rather than as
standalone sensors.
The automation will fire either when there is a live power cut or a planned power cut is detected.
alias: National Grid Power Cut Alerts
description: Notify when a live or planned National Grid power cut is detected.
mode: single
trigger:
- platform: state
entity_id: binary_sensor.power_cut_reported
from: "off"
to: "on"
id: live_power_cut
- platform: time
at: sensor.planned_outage_start
id: planned_power_cut
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: live_power_cut
sequence:
- service: notify.mobile_app_your_phone
data:
title: Power cut reported
message: >
National Grid has reported a power cut for your postcode.
Status: {{ states('sensor.status') }}.
Estimated restoration:
{% if states('sensor.estimated_restoration_time') not in ['unknown', 'unavailable', 'none'] %}
{{ as_timestamp(states('sensor.estimated_restoration_time')) | timestamp_custom('%H:%M on %d %b') }}
{% else %}
Not currently available.
{% endif %}
- conditions:
- condition: trigger
id: planned_power_cut
sequence:
- service: notify.mobile_app_your_phone
data:
title: Planned power cut
message: >
A planned power cut is scheduled to start now.
Status: {{ states('sensor.status') }}.
Estimated restoration:
{% if states('sensor.estimated_restoration_time') not in ['unknown', 'unavailable', 'none'] %}
{{ as_timestamp(states('sensor.estimated_restoration_time')) | timestamp_custom('%H:%M on %d %b') }}
{% else %}
Not currently available.
{% endif %}