Matomo Statistics On Home Assistant

Creating entities in Home Assistant to display your Matomo statistics is super easy through the RESTful Sensor integration. First of all, you’ll need to visit your Matomo install as a super user, click on Administration (the gear) > Security > scroll down to Auth Tokens > Create New Token. Please keep this token secure (I use Bitwarden).

Next, navigate to Home Assistant, fire up the File Editor, and navigate to your configuration.yaml file. At the bottom, add the following code. Be sure to replace YOUR-MATOMO-PATH with the URL for your Matomo installation and YOUR-AUTH-TOKEN with the auth token you generated above.

sensor:
  - platform: rest
	resource: https://YOUR-MATOMO-PATH/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=2&period=day&date=today&format=JSON&token_auth=YOUR-AUTH-TOKEN
	name: Visitors Today
	value_template: '{{ value_json.value | int }}'
	unit_of_measurement: "Visitors"
  - platform: rest
	resource: https://YOUR-MATOMO-PATH/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=2&period=week&date=today&format=JSON&token_auth=YOUR-AUTH-TOKEN
	name: Visitors This Week
	value_template: '{{ value_json.value | int }}'
	unit_of_measurement: "Visitors"
  - platform: rest
	resource: https://YOUR-MATOMO-PATH/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=2&period=month&date=today&format=JSON&token_auth=YOUR-AUTH-TOKEN
	name: Visitors This Month
	value_template: '{{ value_json.value | int }}'
	unit_of_measurement: "Visitors"

Once you’ve finished, save the file. Remember YAML can be finicky about indentation/spacing, so use a validator if you’re having trouble. Restart Home Assistant when you’re done.

Now create a card (I use the Lovelace Glance card) to display your Matomo entities. Create a Glance card, click Show Visual Editor, and copy the code below.

type: glance
entities:
  - entity: sensor.blog_visitors_today
    icon: mdi:calendar-today
    name: Today
  - entity: sensor.blog_visitors_week
    icon: mdi:calendar-week
    name: Week
  - entity: sensor.blog_visitors_month
    icon: mdi:calendar-week-begin
    name: Month

Drop me a comment below if you found this post helpful! 🙂

Support My Work

Comments

One response to “Matomo Statistics On Home Assistant”

  1. Pharizna Avatar

    Hi there, how are you doing? Let me introduce myself — my name is Pedro, also known as Pharizna on the Spanish website pcdemano.com, which I co-founded many years ago. I’m currently trying to get MATOMO working on my WordPress blog, and I came across your page… but I haven’t been able to make it work on mine. I know it’s been a long time and you probably don’t even remember the topic, but I’m reaching out just in case there’s a bit of luck. Could you give me a hand?

Leave a Reply

Your email address will not be published. Required fields are marked *