Mastodon
The Mastodon integration uses Mastodon to post status updates, get account statistics, and mute accounts.
使用场景
- Posting your local weather station details to your Mastodon account.
- Displaying a count of your followers on your Home Assistant dashboard.
- Receiving a notification when an account you follow publishes a new status.
- Muting accounts when you are busy or away to reduce your timeline.
设置
Go to Preferences in the Mastodon web interface, then to Development and create a new application.
Select at a minimum the following scopes: read:accounts, write:statuses, write:media, and write:mutes.
Select Submit to create the application and generate the key, secret, and token required for the integration.
此集成可通过 UI 配置。前往 设置 > 设备与服务 添加。
传感器
The integration will create the following sensors for the Mastodon account:
- Followers: The total number of accounts that follow this account.
- Following: The total number of accounts this account follows.
- Posts: The total number of posts published by the account.
- Last post: When the last post was published
- Username: Displays the account username and avatar, plus attributes like display name, bio, and creation date.
Sensors are updated once an hour.
二进制传感器
- Bot: Indicates whether the account performs automated actions, is not actively monitored, or identifies as a bot.
- Discoverable: Indicates whether the account is discoverable. Public posts and the profile may be featured or recommended across Mastodon.
- Indexable: Indicates whether public posts may appear in search results on Mastodon.
- Limited: Indicates whether the account has been limited by moderators. Limited accounts are hidden from users on the instance, and their content is not publicly visible.
- Moved: Indicates that the account is inactive because the user has moved to a new account.
- Suspended: Indicates whether the account has been suspended.
- Memorial: Indicates whether the account is marked as a memorial.
操作
All Mastodon actions require integration config_entry_id. To find it, go to Developer tools > Actions. Choose the desired action and select your integration from the dropdown. Then switch to YAML mode to see config_entry_id.
操作:获取账户
The mastodon.get_account action is used to get details of an account. Will only return accounts that are federated with your instance.
-
Data attribute:
config_entry_id- Description: The ID of the Mastodon config entry.
- Optional: No
-
Data attribute:
account_name- Description: The account name to get, in the format
@user@instance. - Optional: No
- Description: The account name to get, in the format
操作:静音账户
The mastodon.mute_account action is used to mute an account you follow, which stops their posts appearing in your timeline.
-
Data attribute:
config_entry_id- Description: The ID of the Mastodon config entry.
- Optional: No
-
Data attribute:
account_name- Description: The account name to mute, in the format
@user@instance. - Optional: No
- Description: The account name to mute, in the format
-
Data attribute:
duration- Description: The duration to mute the account, if omitted the account will be muted indefinitely.
- Optional: Yes
-
Data attribute:
hide_notifications- Description: Hide notifications as well as muting the account, defaults to hide.
- Optional: Yes
操作:取消静音账户
The mastodon.unmute_account action is used to unmute a previously muted account.
-
Data attribute:
config_entry_id- Description: The ID of the Mastodon config entry.
- Optional: No
-
Data attribute:
account_name- Description: The account name to unmute, in the format
@user@instance. - Optional: No
- Description: The account name to unmute, in the format
操作:发布状态
The mastodon.post action posts a status to your Mastodon account.
-
Data attribute:
config_entry_id- Description: The ID of the Mastodon config entry.
- Optional: No
-
Data attribute:
status- Description: The status text to post.
- Optional: No
-
Data attribute:
visibility- Description: If not used, will default to account setting.
public: post will be public.unlisted: post will be public but not appear on the public timeline.private: post will only be visible to followers.direct: post will only be visible to mentioned users. - Optional: Yes
- Description: If not used, will default to account setting.
-
Data attribute:
idempotency_key- Description: A unique key to prevent duplicate posts for up to one hour. Common strategies include using a hash of the status text or a static string.
- Optional: Yes
-
Data attribute:
content_warning- Description: Text will be shown as a warning before the text of the status. If not used, no warning will be displayed.
- Optional: Yes
-
Data attribute:
language- Description: The language of the post. If not used, the language that is set in the Mastodon account is used.
- Optional: Yes
-
Data attribute:
media- Description: Attach an image or video to the post.
- Optional: Yes
-
Data attribute:
media_description- Description: If an image or video is attached, will add a description for this media for people with visual impairments.
- Optional: Yes
-
Data attribute:
media_warning- Description: If an image or video is attached,
Truewill mark the media as sensitive.Falseis default. - Optional: Yes
- Description: If an image or video is attached,
Mastodon holds idempotency keys for up to one hour and subsequent posts using the same key will be ignored by your Mastodon instance. If not used, the post will be published without any duplicate check. The timeframe is controlled by your Mastodon instance, not Home Assistant.
示例
发布状态的动作示例
Example post action that will post a status using your account's default visibility:
私密发布动作示例
This will post a status to Mastodon, but visibility is marked as private so only followers will see it.
避免短时间重复发布的状态动作示例
Example post action that will post a status, but ensure that the same status is not posted more than once within one hour. This check is performed by your Mastodon instance.
媒体发布动作示例
This will post a status to Mastodon that includes an image.
包含媒体和内容警告且不显示在公开时间线的发布示例
This will post a status to Mastodon that includes an image, with a description, a content warning, and a visibility of unlisted, so it doesn't show in the public timeline.
休假期间静音已关注账户的示例
This automation will look for an event in your calendar and mute the specified account while the event is active, and unmute at the end of the event.
For more on how to use notifications in your automations, please see the getting started with automation page.
已知限制
The integration does not provide functionality to get the stream, favorite, bookmark, or boost posts of that account.
Mastodon account details only show the date of the last status you posted, not the time. If you use the mastodon.get_account action to monitor new posts, you should instead watch the statuses_count field in the action response for changes.
故障排除
无法使用操作
现象:使用操作时日志中出现错误
When using actions errors relating to permissions are shown in the logs.
说明
Actions require specific permissions within your Mastodon account to read or write data.
解决方法
Ensure that you have set these appropriately within your Mastodon account, please see the setup instructions.
删除集成
This integration follows standard integration removal, once the integration is removed you can remove the application registration (assuming it was only used by this integration) from your Mastodon account by going to Preferences in the Mastodon web interface, then to Development and deleting the application you created for Home Assistant.
从 Home Assistant 中删除集成实例
- Go to Settings > Devices & services and select the integration card.
- From the list of devices, select the integration instance you want to remove.
- Next to the entry, select the three-dot
menu. Then, select Delete.

