Mastodon Follower Count and other profile sensors

Hi all,
I’d wanted to add a sensor to pull my current Mastodon follower account into Home Assistant, and wanted to share how I’d gone about doing that using the REST sensor.

Further reading/limitations
There are some other properties that are returned in this API call that could also be easily be added as sensors, and this will not work if the server you’re on has DISALLOW_UNAUTHENTICATED_API_ACCESS set in its configuration.

configuration.yaml Entry
Replace your username and the server address in the entry below, then reload your Home Assistant configuration

rest:
  - resource: 'https://mastodon.example.com/api/v1/accounts/lookup?acct=YOUR_USERNAME'
    scan_interval: 7200 # 2h, in seconds. Can be modified to check more or less frequently.
    sensor:
      - name: Mastodon Followers
        value_template: "{{ value_json.followers_count }}"
        icon: mdi:account
        state_class: measurement
     - name: Mastodon Following
        value_template: "{{ value_json.following_count }}"
        icon: mdi:account
        state_class: measurement
      - name: Mastodon Last Posted
        value_template: "{{ value_json.last_status_at }}"
        icon: mdi:calendar
        state_class: measurement
        device_class: date
3 Likes

Thanks for this. I like it !