New sensor for alerts from GeoRSS feeds

Following my initial release of a new sensor specifically focusing on showing bush fire alerts published by the NSW rural fire service, and filtered by distance to my home (and my HA instance), I have generalised the sensor to hopefully make it more useful to more users and more use-cases.

This new sensor reads a GeoRSS feed (appears to be more widespread than GeoJSON), filters the entries of the feed by distance to the HA instance, and shows the number of found incidents together with some details.

If you are interested in trying a pre-release of this new sensor (tested with HA 0.49), please follow these instructions:

  • Copy the file geo_rss_incidents.py into <config_dir>/custom_components/sensor/
  • add a new sensor to your configuration, for example:
sensor:
  - platform: geo_rss_incidents
    name: NSW Fire Service
    url: http://www.rfs.nsw.gov.au/feeds/majorIncidents.xml
    icon: mdi:fire
    categories:
      - 'Emergency Warning'
      - 'Watch and Act'
      - 'Advice'
      - 'Not Applicable'
  • The default filter distance between your HA coordinates, and the incidents is 20km. You can change that distance if required by adding the radius parameter, expecting a float value in km.
  • Restart HA
  • New sensors should appear (one per category defined) that you can arrange and group as usual
  • ā€‹The data is updated every 5 minutes
  • ā€‹Details including the incidentā€™s title and distance are displayed in the info dialogue

A couple of other GeoRSS feeds I have tried are:

Bush fire alerts

sensor:
  - platform: geo_rss_incidents
    name: Qld Fire and Emergency Services
    url: https://www.qfes.qld.gov.au/data/alerts/bushfireAlert.xml
    icon: mdi:fire
    categories:
      - 'Notification'
    unit_of_measurement: 'Alerts'
  - platform: geo_rss_incidents
    name: Tas Fire Service
    url: http://www.fire.tas.gov.au/Show?pageId=colBushfireSummariesRss
    icon: mdi:fire
    categories:
      - 'No Alert Level'
    unit_of_measurement: 'Alerts'
  - platform: geo_rss_incidents
    name: WA Department of Fire and Emergency Services
    url: https://www.emergency.wa.gov.au/data/incident_FCAD.rss
    icon: mdi:fire
  - platform: geo_rss_incidents
    name: ACT Emergency Services Agency
    url: http://www.esa.act.gov.au/feeds/currentincidents.xml
    icon: mdi:fire

Earthquake alerts

sensor:
  - platform: geo_rss_incidents
    name: USGS All Earthquakes
    url: https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.atom
    categories:
      - 'Past Hour'
      - 'Past Day'
  - platform: geo_rss_incidents
    name: BGS Worlwide Earthquakes
    url: http://www.bgs.ac.uk/feeds/worldSeismology.xml
    categories:
      - 'EQMH'
  - platform: geo_rss_incidents
    name: Recent significant earthquake reports (Canada)
    url: http://www.earthquakescanada.nrcan.gc.ca/index-en.php?tpl_region=canada&tpl_output=rss
    categories:
      - 'Earthquake Report'

Please let me know if the sensor works for you and how useful you find it. Is there anything missing from your point of view? Any other use-cases you could think of where this type of sensor may be useful?
Any other GeoRSS feeds that you would like to use, and could share your configuration?

6 Likes

This source seems to be useful for the sensor:
http://emergency.copernicus.eu/mapping/copernicus-emergency-management-service

2 Likes

@exxamalte, thank you for very useful sensor!

Would it be possible to configure the ā€œageā€ of incidents?
For instance, if I use EU Copernicus Emergency feed, I see old/closed events together with new/active one.

1 Like

Yes, that would be possible (in a future version). The RSS library can extract the publication date and update date - if present in the RSS feed.
That Copernicus Emergency feed contains the publication date (pubDate) for each entry. However, this date and time do not seem to correspond with either ā€˜Date/Time of Event (LOC)ā€™ or ā€˜Activation Date/Time (UTC)ā€™ which are in the description field of the event.

In the last week I was focusing on sorting events (by title, distance, date).
Filtering events by other attributes (in addition to distance) is on my TODO list.

2 Likes

Great!
Btw, it was the only source that I could find relevant to Sweden regarding storms, floods, fires etc. If there are any other known sources, please share them, I would highly appreciate it.

Great!

Hope also on magnitude for earthquakes. I receive lots of events with magnitude 1 or 2, which is of no use

Yes, I havenā€™t forgotten about this. I have a prototype running locally that extracts the magnitude from the INGV feed. The configuration just requires a source field (in this case title) and a regular expression to extract the relevant data. The result is stored as an attribute with each event. In the prototype I can use the magnitude for sorting already - filtering will have to follow. Since this attribute extraction requires a lot of testing I probably need a bit more time (and code reviews) until this can be released.

Iā€™ll be adding this - things looked very dry until just recently (Central Coast NSW, Aus) - itā€™s going to be a cracker of a summer for bushfires.

Thanks!

1 Like

I have been busy adding a few more features to this sensor:

  • sort events by title, distance, published date or updated date, including ability to reverse the order
  • define custom attributes and filter events by attribute values
  • publish new geo rss events to the HA event bus (an automation can listen for such events)

If you want to test a beta version of these enhancements, please use this file:

And here a few configuration examples:

  1. Extract magnitude value from earthquake feed, filter out any incidents with magnitude <2.0, and then sort by magnitude:
sensor:
  - platform: geo_rss_events
    name: Terremoti
    url: http://info.terremoti.ingv.it/feed/atom/all_week
    radius: 200
    custom_attributes:
      - name: magnitude
        source: title
        regexp: '.*Magnitude\(M.+\) (?P<custom_attribute>\d+.\d+) .*'
    sort_by: 'magnitude'
    sort_reverse: true
    custom_filters:
      - attribute: magnitude
        regexp: '([0-9]{2,}|[2-9]{1})\.\d{1}'

Both, the custom attribute and the custom filter, expect a regular expression. The custom attributeā€™s regular expression must contain a named group custom_attribute. The custom filterā€™s regular expression is just used to match an attributeā€™s value.

  1. Publish to HA event bus:
sensor:
  - platform: geo_rss_events
    ...
    publish_events: true

The event type (that you need in your automation) is generated from the name of the sensor (all lower case, whitespace replaced with underscore).

Iā€™ll have to add some more tests now, and harden the implementation, before the enhancement can go into a pull request.

2 Likes

Will check tomorrow

I donā€™t understand this

how would I make an automation to send notification if a earthquake is above 3? Like this is the number of events not theit magnitude

############
  - alias: 'Attenzione Terremoto'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: sensor.terremoti_any
        above: '3'
    action:
      - service: notify.claudio_pushbullet
        data_template:
          message: 'Attenzione Terremoto'
      - service: notify.claudio_zanzito
        data_template:
          message: 'Attenzione Terremoto'

If set to true the sensor will publish georss incidents retrieved from the external service directly onto the HA event bus. You can then write an automation that does not get triggered by changes of the sensor, but just needs to listen to those events.
This approach comes with the advantage that the fired event contains all the information you may want to send yourself in a notification. Also, you can process each incident separately, and for example use conditions to further filter.

Correct, the sensorā€™s state just represents the number of active incidents.

With the above mentioned HA event bus approach, I see two options:

  1. Create a sensor that retrieves all earthquakes, regardless of magnitude. The action gets triggered by events fired by the sensor; you create a condition that interrogates the event data where you should find the magnitude as an attribute. Then you can forward all relevant information in a notification.
  2. Create a sensor that retrieves all earthquakes but filters by magnitude, so that it will only send events to the HA event bus that are relevant for notifications. The actionā€™s trigger will still be the same but you wonā€™t need a condition since the events are already all the ones you want to send yourself a notification for.

I donā€™t have a configuration example like this at hand at the moment, but I can probably post one tonight.

And here comes an example of an event listener automation:

automation:
  - alias: Notify
    trigger:
      platform: event
      event_type: nsw_fire_service
    action:
      service: persistent_notification.create
      data_template:
        message: '{{ trigger.event }}'
        title: "NSW Fire Service"

There was recently a bug fix that made it into version 0.57 and fixed that event_data is really optional. So make sure you use 0.57 or later.
The value for event_type must match whatever your sensor generated from the sensor name. Please have a look at your logfile to see what type of events are being generated:

INFO:homeassistant.core:Bus:Handling <Event nsw_fire_service[L]: ...>

The above automation simply generates a notification box in the UI. For some reason I canā€™t explain right now, the message from the action is not displayed, and instead if just says ā€œnotifyingā€.

2017-11-12 12:19:24 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.geo_rss_events
2017-11-12 12:19:24 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] latitude=41.9376, longitude=12.4557, url=http://info.terremoti.ingv.it/feed/atom/all_week, radius=200.0
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] 491 entri(es) available in feed http://info.terremoti.ingv.it/feed/atom/all_week
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.2572, 13.5737): 98.85116202219044 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 10:23:24 UTC -  Magnitude(ML) 1.6  -  NW Fagnano Alto (AQ)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=10, tm_min=23, tm_sec=24, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 98.85116202219044, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17623641', 'magnitude': '1.6'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.8062, 13.0782): 109.28564019806099 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 09:52:23 UTC -  Magnitude(ML) 1.2  -  2 km NW Norcia (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=9, tm_min=52, tm_sec=23, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 109.28564019806099, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17623351', 'magnitude': '1.2'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.842, 13.1918): 117.33504609388073 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 09:39:02 UTC -  Magnitude(ML) 1.6  -  7 km SE Castelsantangelo sul Nera (MC)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=9, tm_min=39, tm_sec=2, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 117.33504609388073, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17623251', 'magnitude': '1.6'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.8167, 13.15): 113.17108167555972 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 09:26:12 UTC -  Magnitude(ML) 1.3  -  5 km NE Norcia (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=9, tm_min=26, tm_sec=12, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 113.17108167555972, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17623181', 'magnitude': '1.3'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.7957, 13.1262): 110.17486426602294 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 09:09:24 UTC -  Magnitude(ML) 1.0  -  3 km E Norcia (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=9, tm_min=9, tm_sec=24, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 110.17486426602294, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17623121', 'magnitude': '1.0'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (43.0298, 13.0358): 130.43021111886017 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 08:59:26 UTC -  Magnitude(ML) 1.1  -  2 km SW Pieve Torina (MC)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=8, tm_min=59, tm_sec=26, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 130.43021111886017, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17622951', 'magnitude': '1.1'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.8207, 13.1237): 112.4852197854774 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 08:48:52 UTC -  Magnitude(ML) 1.1  -  4 km NE Norcia (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=8, tm_min=48, tm_sec=52, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 112.4852197854774, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17622911', 'magnitude': '1.1'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (37.759, 14.819): 506.4934995129277 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (38.4352, 15.4398): 464.6068052752786 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (43.0122, 13.0): 127.55560744491149 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 07:29:54 UTC -  Magnitude(ML) 0.9  -  2 km N Monte Cavallo (MC)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=7, tm_min=29, tm_sec=54, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 127.55560744491149, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17622391', 'magnitude': '0.9'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.8052, 13.1325): 111.34638502865567 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Keeping event {'category': None, 'title': '2017-11-12 06:45:06 UTC -  Magnitude(ML) 2.6  -  3 km E Norcia (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=6, tm_min=45, tm_sec=6, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 111.34638502865567, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17622041', 'magnitude': '2.6'}
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (43.6207, 10.9992): 221.7034245046353 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.8132, 13.1318): 112.08772374482871 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 05:45:54 UTC -  Magnitude(Md) 1.1  -  4 km NE Norcia (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=5, tm_min=45, tm_sec=54, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 112.08772374482871, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?eventId=17621851', 'magnitude': '1.1'} does not match filter OrderedDict([('attribute', 'magnitude'), ('regexp', '([0-9]{2,}|[2-9]{1})\\.\\d{1}')])
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Distance from [41.9376, 12.4557] to (42.9158, 13.0432): 118.97948658899703 km
2017-11-12 12:19:31 DEBUG (SyncWorker_7) [custom_components.sensor.geo_rss_events] Event {'category': None, 'title': '2017-11-12 04:55:49 UTC -  Magnitude(ML) 0.8  -  4 km N Preci (PG)', 'date_published': None, 'date_updated': time.struct_time(tm_year=2017, tm_mon=11, tm_mday=12, tm_hour=4, tm_min=55, tm_sec=49, tm_wday=6, tm_yday=316, tm_isdst=0), 'distance': 118.97948658899703, 'id': 'smi:webservices.ingv.it/fdsnws/event/1/query?

,

can you help in automation that tells if a erarthquake is registered (above X magnitude)

I have additional problem, how to have less logs from your component, its making the log too big. Few days and is 2 GByte!

No worries, Iā€™ll see what I can do:

First of all, have you activated publishing data to the event bus?
Please add publish_events: true to your existing sensor:

sensor:
  - platform: geo_rss_events
    ...
    publish_events: true

The log you posted does not contain any of the data weā€™re looking for. Itā€™s not the sensor itself that logs the event, but HA core. If you used the earthquake example from above, the sensorā€™s name is ā€œTerremotiā€ which would be turned into the event type terremoti.

INFO:homeassistant.core:Bus:Handling <Event terremoti[L]: ...>

Now to the automation: Have you set up the sensor to only include earthquakes with a magnitude of 3 or higher? If not, I would recommend doing that because it makes the automation easier as it wonā€™t require a condition.

  - alias: 'Attenzione Terremoto'
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: terremoti
    action:
      - service: notify.claudio_pushbullet
        data_template:
          message: 'Attenzione Terremoto: {{ trigger.event }}'
      - service: notify.claudio_zanzito
        data_template:
          message: 'Attenzione Terremoto'

You are already using the data_template approach in your action which allows you to extract more details from the event that triggered the automation. I donā€™t have a good example for a nicer message yet, but basically you can access all details of the event such as title, date, distance, and custom attributes.

Well, it appears that you log at debug level. Have a look at the logger documentation which explains how you can set log levels for different components. Looking at your log file, I think you want to set custom_components.sensor.geo_rss_events to info.

how you do this?