Hi,
First time poster here. I’m a bit stuck and was just wanting to hopefully be pointed in the right direction please. I’m not 100% if there’s a limit on the amount of data that can be returned to the REST sensor or something else that may be stopping me. There’s a bit of text that follows, so I will thank any and all responses in advance - thanks!
I’m looking to be able to tell when a power outage is occurring by pointing to the supplier’s API (https://www.endeavourenergy.com.au/designs/connectors/outage-feeds/get-current-outage).
From there, I’d have a card on a dashboard that would populate with fields such as start time, end time, outage type, etc. when there’s an outage on, and otherwise return N/A when there’s no outage.
This API drops a lot of information - all of the outages, both planned and unplanned, across their supply network - into that page/API, and to me it appears to be JSON. The time of start/end is also in UTC.
Admittedly, I did enlist some assistance of ChatGPT, as I can’t do code etc. to save my life.
The street etc, used in the .yaml is an example of an active, unplanned outage.
I’ve saved the config as a YAML file at location: /config/packages/poweroutage.yaml, and configuration.yaml is set to read the packages directory as below.
homeassistant:
packages: !include_dir_named packages
My poweroutage.yaml is:
sensor:
- platform: rest
resource: https://www.endeavourenergy.com.au/designs/connectors/outage-feeds/get-current-outage
name: Power Outage
value_template: "{{ value_json.status }}"
json_attributes:
- creationDateTime
- endDateTime
- incidentId
- numberCustomerAffected
- outageType
- postcode
- reason
- startDateTime
- status
- streetName
- suburb
- longitude
- latitude
scan_interval: 300 # Set the update interval to 5 minutes
- platform: template
sensors:
power_outage_my_address:
friendly_name: "My Address Power Outage"
value_template: >-
{% set all_outages = states.sensor.power_outage.attributes %}
{% set my_postcode = 2529 %}
{% set my_street = 'WATERFRONT PROM' %}
{% set my_suburb = 'SHELL COVE' %}
{% set filtered_outages = [] %}
{% for outage in all_outages %}
{% if outage.postcode == my_postcode and outage.streetName == my_street and outage.suburb == my_suburb %}
{% set filtered_outage = {
'Outage Type': 'Unplanned' if outage.outageType == 'U' else 'Planned',
'Start Time': as_timestamp(outage.startDateTime) | timestamp_custom('%Y-%m-%d %H:%M:%S', true),
'End Time': as_timestamp(outage.endDateTime) | timestamp_custom('%Y-%m-%d %H:%M:%S', true) if outage.endDateTime is not none else "N/A",
'Reason': outage.reason,
'Status': outage.status
} %}
{% set filtered_outages = filtered_outages + [filtered_outage] %}
{% endif %}
{% endfor %}
{{ filtered_outages | tojson }}
entity_id: sensor.power_outage
The only attributes returned by the rest Sensor are below. Nothing else is, which is strange given the amount of data delivered by the API.
Attributes:
creationDateTime: 2023-10-22T04:18:53Z
endDateTime: 2023-10-16T03:00:00Z
incidentId: 46012092
numberCustomerAffected: 2
outageType: P
postcode: 2117
reason: MAINTENANCE WORK
startDateTime: 2023-10-15T21:00:00Z
status: OUTAGE COMPLETED
streetName: ARKANA ST
suburb: TELOPEA
longitude: 151.03577
latitude: -33.78882
friendly_name: Power Outage