I recently created @arborwiki_changes@a2mi.social, a Mastodon bot that posts changes to ArborWiki (a wiki for Ann Arbor, MI and nearby communities).
I had a few ideas for how to build it. If there was a Glitch bot template I would have probably just grabbed that and set up a cron job to try to trigger it hourly. IFTTT would have been perfect, but they don’t support Mastodon. Val Town seems like it would be good, and has some RSS and cron capabilities already, but I’d need to build the Mastodon part.
Then I realized Home Assistant has all the parts I need. Specifically it has an RSS integration called Feedreader and a notification integration for Mastodon. All that I needed to do was configure them, per their docs, and create an automation to post new RSS items. Here’s the automation I initially came up with:
alias: ArborWiki Notifications
description: ""
trigger:
- platform: event
event_type: feedreader
action:
- service: notify.arborwiki_mastodon
data:
message: |-
{{ trigger.event.data.summary }}
{{ trigger.event.data.link }}
mode: single
This worked pretty well, until I realized that the RSS feed was showing changes from other wikis on Localwiki, like Davis, CA. I added a condition to only trigger the notification when the page URL is for Ann Arbor:
alias: ArborWiki Notifications
description: ""
trigger:
- platform: event
event_type: feedreader
condition:
- condition: template
value_template: {{ trigger.event.data.link.startswith('https://localwiki.org/ann-arbor') }}
action:
- service: notify.arborwiki_mastodon
data:
message: |-
{{ trigger.event.data.summary }}
{{ trigger.event.data.link }}
mode: single
Limitations
This mostly works, but there are some things that could be better:
- Ideally LocalWiki would support ActivityPub so I could subscribe to @ann-arbor@localwiki.org for changes and they would arrive as soon as they happen. As I’ve said before, ActivityPub supports a lot of the same use cases as RSS.
- Home Assistant only fires the notification for the latest new change. If someone make a bunch of changes at once, there will only be one post to Mastodon. Maybe that is a good thing, until Mastodon clients figure out how to group many posts from the same author (something that the WordPress.com Reader used to support)
- It’s running on my home internet. This isn’t a high-availability scenario and if it goes down, it goes down. I only guarantee five nines of updog.
3 responses to “Setting up a Mastodon RSS Bot with Home Assistant”
@georgehotelling +1 for five nines of updog
I love what you know and what you are achieving even though I don’t understand a word of it.
Love,
Mom
@georgehotelling @arborwiki_changes This is an unexpectedly timely intersection of my interests 😀