Skip to content

Read the feed URL from an entity (dynamic feed URLs) - #176

Merged
iantrich merged 1 commit into
masterfrom
feed-url-entity
Nov 15, 2026
Merged

iantrich merged 1 commit into
masterfrom
feed-url-entity

Conversation

@iantrich

Copy link
Copy Markdown
Member

Closes #60.

Why

Some feeds publish a new URL every day (the issue's example is a TV listing named programme-tv-rss_DD-MM-YYYY.xml). The integration used feed_url exactly as typed, so {{ now()... }} was requested literally and failed with InvalidURL.

This change doesn't render Jinja inside the integration. Instead, a feed can take its URL from an entity's state. Users build the URL with a template sensor helper, or set it from an automation with input_text.set_value, so Home Assistant does the templating.

What changed

  • New feed_url_entity source. It can be an input_text, text or sensor entity, and works both in the UI and in YAML. A feed uses either feed_url or feed_url_entity, never both.
  • Coordinator
    • Reads the entity's state on every poll and passes that URL to FeedReader.read(url).
    • Refreshes right away when the entity's value changes. A switch to unknown/unavailable, such as a helper reloading, doesn't trigger a refresh, so the entries stay until the next poll.
    • Stops tracking the entity when the entry unloads.
    • If the entity is missing, empty or not an http/https/file URL, the poll fails with UpdateFailed. At startup that means a setup retry, the same as an unreachable feed.
  • Config flow
    • The setup and reconfigure forms offer Feed URL or Feed URL entity (an entity selector).
    • The test fetch uses the URL the entity holds when the form is submitted.
    • Only one source is stored, so reconfigure can switch an entry between a typed URL and an entity.
    • Three new errors: url_or_entity, entity_no_url and entity_invalid_url.
  • YAML
    • The schema needs exactly one of feed_url and feed_url_entity, and the entity's domain is checked.
    • Changing a YAML sensor between the two updates the same entry, keeping its entity ID.
  • New source.py holds the entity lookup and URL check. is_supported_url moved there from the config flow.
  • Text
    • Strings added in en, de and el.
    • README: new "Feed URLs that change" section with a template-helper example, the YAML key, and the reference table.

For reviewers

  • 255-character limit. Home Assistant caps entity states at 255 characters, so longer URLs can't be passed this way. input_text defaults to a maximum of 100. The README says both.
  • Translations need checking. I wrote the de and el strings myself, without a native speaker; a check from one would help.
  • Validated only at setup. If the entity later holds a URL that isn't a feed, the sensor becomes unavailable until the value changes.
  • Tests and checks. tests/test_url_entity.py covers both setup paths, refresh on change, unknown/unavailable handling, setup retry, unload, duplicates, switching on reconfigure and in YAML, and schema rejections. The full suite passes (239 tests), and ruff and mypy are clean.
  • Not yet tried in a running Home Assistant instance.

🤖 Generated with Claude Code

Some feeds publish a new URL every day (issue #60). Instead of rendering
templates in the integration, a feed can now take its URL from an
input_text, text or template sensor entity, in the UI and in YAML
(feed_url_entity). The URL is read on every poll, and the feed is
refreshed as soon as the entity's value changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@iantrich
iantrich merged commit db13041 into master Nov 15, 2026
6 checks passed
@iantrich
iantrich deleted the feed-url-entity branch November 15, 2026 18:41
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

Successfully merging this pull request may close these issues.

cannot use dynamic date in feed_url

1 participant