Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering #61

Open
nTx-Cheerok opened this issue Apr 5, 2022 · 7 comments
Open

Filtering #61

nTx-Cheerok opened this issue Apr 5, 2022 · 7 comments

Comments

@nTx-Cheerok
Copy link

Hi im using this component for some time now and it generellay works great with the custom lovelace card. However i was wondering if i could filter the entries of a feed efficiently without the need to fiddle around with template sensors.
Like only show titles that include a certain string or something like that. The reason i ask is that i kind of get it working with templates but not optimally.

@macross5
Copy link

macross5 commented Apr 4, 2023

i would love it aswell

@macross5
Copy link

macross5 commented Apr 4, 2023

@nTx-Cheerok can you show me an example for the templating?

@Vitani
Copy link

Vitani commented Apr 4, 2023

Me too, I use an RSS feed for weather alerts; the feed covers an entire region, but lists the cities affected in the "locations" field of each alert; it'd be nice to stick a regex on that field to only show alerts which affect my city.

@macross5
Copy link

macross5 commented Apr 4, 2023

I scripted the last hours and got this to work:

`
template:

  • sensor:
    • name: "(TEST) RSS"
      state: "{{ states('sensor.rss_feed') | int }}"
      attributes:
      entries: >-
      {% set rss_list = namespace(entries=[]) %}
      {% for entries in state_attr('sensor.rss_feed','entries') -%}
      {% if "filter1" in entries['title']|lower
      or "filter2" in entries['title']|lower
      or "filter3" in entries['title']|lower
      -%}
      {% set rss_list.entries = rss_list.entries + [entries] %}
      {% endif -%}
      {% endfor %}
      {{ rss_list.entries }}
      `

@nTx-Cheerok
Copy link
Author

Hi peops, i was very busy and this also kind of an old post :D
I switched setups and erased some stuff, including the stuff i needed the feed parser for.
Ill see if i can find my old backups as the config must still be in there and post my example.

@ogajduse
Copy link
Collaborator

@Vitani Could you post the URLof the RSS feed that you use for weather alerts here?

@Vitani
Copy link

Vitani commented Jul 27, 2023

@ogajduse this is the specific one I use - http://www.metoffice.gov.uk/public/data/PWSCache/WarningsRSS/Region/em, but there are more of them - https://www.metoffice.gov.uk/weather/guides/rss

Not sure how useful they will be right now, as there are currently no weather warnings in place for the UK

Edit: There are rain & thunderstorm warnings today, here's the feed -

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Met Office warnings for East Midlands</title>
        <link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings</link>
        <description>Weather warnings of severe and extreme weather from the Met Office</description>
        <language>en-gb</language>
        <copyright>(c) Crown copyright</copyright>
        <pubDate>Wed, 02 Aug 2023 08:32:41 GMT</pubDate>
        <dc:creator>webteam@metoffice.gov.uk</dc:creator>
        <item>
            <title>Yellow warning of thunderstorm affecting East Midlands</title>
            <link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=da1b66c8-0df8-49f0-a6a5-7f255d0cb8a9&amp;referrer=rss</link>
            <description>Yellow warning of thunderstorm affecting East Midlands: Derby, Derbyshire, Leicester, Leicestershire, Lincolnshire, Northamptonshire, Nottingham, Nottinghamshire, Rutland valid from 0800 Wed 02 Aug to 1900 Wed 02 Aug</description>
            <guid isPermaLink="false">https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=da1b66c8-0df8-49f0-a6a5-7f255d0cb8a9&amp;referrer=rss&amp;region=East Midlands</guid>
            <enclosure length="109337" type="image/png" url="https://cdn.prod.weathercloud.metoffice.gov.uk/warnings/rss/image/yellow-thunderstorm.png"/>
        </item>
        <item>
            <title>Yellow warning of rain affecting East Midlands</title>
            <link>https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=2be5c1e8-2717-45ac-a32e-581b313e9943&amp;referrer=rss</link>
            <description>Yellow warning of rain affecting East Midlands: Lincolnshire, Nottinghamshire valid from 1000 Wed 02 Aug to 1900 Wed 02 Aug</description>
            <guid isPermaLink="false">https://www.metoffice.gov.uk/weather/warnings-and-advice/uk-warnings#?date=2023-08-02&amp;id=2be5c1e8-2717-45ac-a32e-581b313e9943&amp;referrer=rss&amp;region=East Midlands</guid>
            <enclosure length="98657" type="image/png" url="https://cdn.prod.weathercloud.metoffice.gov.uk/warnings/rss/image/yellow-rain.png"/>
        </item>
    </channel>
</rss>

I would like to filter these items so that if the description contains "Leicester" then it is shown (so in the example above I would only see the "Yellow warning of thunderstorm" item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants