New sensor for alerts from GeoRSS feeds

As explained in a previous post, you will have to create a regular expression that matches the desired criterion. Unfortunately it’s not as easy as comparing two numbers with a “greater than” condition. Maybe in a future version this could be enhanced to allow for generating typed custom attributes and corresponding typed custom filters.

Anyway, in the meantime you would need to add the following bit to your sensor configuration. The custom attribute definition extracts a new attribute magnitude from the title of the georss feed. The custom filter then matches the magnitude against the provided regular expression which looks for anything larger than 3.0.

    custom_attributes:
      - name: magnitude
        source: title
        regexp: '.*Magnitude\(M.+\) (?P<custom_attribute>\d+.\d+) .*'
    custom_filters:
      - attribute: magnitude
        regexp: '([0-9]{2,}|[3-9]{1})\.\d{1}'

To test if your regular expression works you could use a service like pythex:

Hi @exxamalte,
Are you planning to update your existing sensor with this new version?
It has more features and could handle some sources, e.g. Copernicus, it nicer way as far as I understood.

Yes, absolutely. Unfortunately I still haven’t found the time to write more thorough unit tests for the new functionality. I’ll try my best to get this done within the next week or so.

Have you tried the development version? Do you have any feedback for me - does it work as expected, is it relatively easy to configure the regular expressions, is there still anything missing for the GeoRSS sources you are interested in?

I’ve tried to replace the original code with a new one, however, faced with permission issue.
Can I install it as a customer component?
I definitely would be happy to provide you with my feedback.

1 Like

That should be possible. However, because the default HA installation already contains a component with the same name, it would probably be best to rename the new file in <config_dir>/custom_components/sensor/, e.g. to geo_rss_events_new.py. Then accordingly you would use platform: geo_rss_incidents_new in your configuration.

FYI - pull request raised which contains the following enhancements:

  • Define custom attributes from data retrieved from the GeoRSS feed. This allows for extracting additional information from the available data and for example use it for filtering, sorting or publishing to the event bus.
  • Define custom filters on attribute values. This allows for more fine granular filtering of retrieved events.
  • Sort events in info dialogue view by attribute value (ascending/descending).
  • Publish events retrieved from GeoRSS feed onto Home Assistant event bus.
2 Likes

Great!

I am still testing your new component and stuck with regexp for custom_filters to be able to sort events with activation date after certain date e.g. 2017-01-01:

  - platform: geo_rss_events_new
    name: European Emergency
    url: http://emergency.copernicus.eu/mapping/activations-rapid/feed
    radius: 250
    unit_of_measurement: 'Incidents'
    custom_attributes:
      - name: date
        source: description
        regexp: '.Activation\ .*\d{4}\-\d{2}\-\d{2}\s+\d{2}:\d{2}:\d{2}'
    sort_by: 'date'
    sort_reverse: true
    custom_filters:
      - attribute: date
        regexp: '?????'

The custom attribute regexp definition must contain a named group called custom_attribute. The date filter is simple if you are after a specific date. The regexp does not support dynamic values like a template.
Please see below for a working example:

  - platform: geo_rss_events_new
    name: European Emergency
    url: http://emergency.copernicus.eu/mapping/activations-rapid/feed
    radius: 250
    unit_of_measurement: 'Incidents'
    custom_attributes:
      - name: date
        source: description
        regexp: '.Activation\ .*(?P<custom_attribute>\d{4}\-\d{2}\-\d{2})\s+\d{2}:\d{2}:\d{2}'
    sort_by: 'date'
    sort_reverse: true
    custom_filters:
      - attribute: date
        regexp: '2017-.*'
1 Like

Thank you very much for help and clarification.
It would be good to have this explanation in the doc for the sensor when it will be updated since it is not so obvious for lamers like me.

Is there any idea why I get this error:

2017-12-12 20:47:57 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform geo_rss_events_new
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 171, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/geo_rss_events_new.py", line 120, in setup_platform
    data.update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
    result = method(*args, **kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/geo_rss_events_new.py", line 290, in update
    events = self.filter_entries(feed_data)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/geo_rss_events_new.py", line 309, in filter_entries
    event = self.create_event(entry, distance)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/geo_rss_events_new.py", line 350, in create_event
    CONF_CUSTOM_FILTERS_ATTRIBUTE]])
  File "/srv/homeassistant/lib/python3.5/re.py", line 163, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object

Yes, you are absolutely right. I should have posted a link to the corresponding documentation change.

The error happens in the code that tries to apply the custom filter.
In the quoted configuration snippet in your previous post, an asterisk (*) seems to have gone missing. The regexp should be '2017-.*'.
Also, I can see that you are not using the latest version of the change. The latest version which is part of the PR contains a few minor changes and bugfixes.
Looking at the error message you sent there, I should probably add a few more test cases and some error handling code to better cater for errors in the regular expression.

Just a quick heads-up: The code in the PR is otherwise fully functional, but I may need to do some more refactorings to fit the new functionality into the HA framework. Stay tuned…

Thanks, update to the latest version from the PR and adding of missing closing parenthesis in the end of regexp solved my issue.

1 Like

It would be good if the regexp could support dynamic values, i.e. template. Maybe it would be something to consider for some next update :wink:

1 Like

do I still need custom_components, or I use the included in 0.59?

Yes, you will still need the custom component - the enhancements have not been added to a new release yet. As mentioned in a previous post, I am still looking at some refactorings to better fit the HA architecture.

Hi,

Is there any progress with including a new version in some next realises?

Unfortunately not a lot of progress at the moment, but definitely still on the task list for myself. Sorry for the delay.

1 Like

Hi @exxamalte, it looks like there is a progress with your new component which will replace GeoRSS as far I understood. It was introduced in 0.78.0, however, it seems like documentation is lacking. Does it work only as demo?

Yes, as a first step I added a new component for geo location based platforms in general. This currently only contains a demo platform to show how entities automatically show up on the map.
As a first platform I decided to go with GeoJSON feeds because they are relatively simple.
GeoRSS feeds will definitely follow, but the underlying library I would use to parse the feeds is currently missing a fix to work properly with Python 3.7. A fix has been proposed and is waiting to be integrated.

In general, I am planning to add more platforms for specific feeds instead of generic platforms. This would make it much easier for the less tech-savvy users to integrate feeds.
Also, there are still a few improvements outside of the geo location component required to make all of this more useful, for example making zone triggers work without knowing the exact entity id.

Stay tuned…

1 Like

I really hope that you’ll manage to integrate GeoRSS feeds too. It seems that there is no good alternative for Europe except Copernicus Emergency Management Service which provides GeoRSS only.