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! 🙂

Previous article
Next article

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Try EchoTools - my free, iOS ultrasonography reference application!

Latest Articles