Matomo Blog Statistics in Homeassistant

I use to write a Blog with two other guys and we’ve recently included Matomo (formerly Piwik) for analytics. Matomo has a nice API and it’s quite easy to display the stats in Homeassistant. Here are the steps:

Get Auth Token from Matomo Dashboard:
In Matomo navigate to Settings > API and copy your token.

Create 3 REST-Sensors in Homeassistant for daily, weekly and monthly visitors: Change URL_MATOMO, idSite and auth-token according to your needs

- platform: rest
  resource: "https://URL_MATOMO/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=1&period=day&date=today&format=JSON&token_auth=c7a98***************************"
  name: Blog Visitors Today
  value_template: '{{ value_json.value | int }}'
  unit_of_measurement: "Visitors"
- platform: rest
  resource: "https://URL_MATOMO/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=1&period=week&date=today&format=JSON&token_authc7a98***************************4"
  name: Blog Visitors Week
  value_template: '{{ value_json.value | int }}'
  unit_of_measurement: "Visitors"
- platform: rest
  resource: "https://URL_MATOMO/?module=API&method=VisitsSummary.getUniqueVisitors&idSite=1&period=month&date=today&format=JSON&token_auth=c7a98***************************"
  name: Blog Visitors Month
  value_template: '{{ value_json.value | int }}'
  unit_of_measurement: "Visitors"

Create a nice glance card in Lovelace-UI:

- type: glance
  title: Triumvirat.org | Statistik  
  entities:
    - entity: sensor.blog_visitors_today
      icon: 'mdi:calendar-today'
      name: Today
    - entity: sensor.blog_visitors_week
      name: Week
      icon: 'mdi:calendar-week'
    - entity: sensor.blog_visitors_month
      name: Month
      icon: 'mdi:calendar-week-begin

Voilà! It’s done:

matomostats

I’ve written a blog post (in german) about this and if you’re interested there is also a script to use TTS for a spoken Blog statistics report: https://www.triumvirat.org/2018/12/18/matomo-besucherstatistik-in-homeassistant-einbinden/

3 Likes

Thanks for that nice idea that I implemented here in my system :wink:

1 Like

@jones - nice, I might try this. Thanks

1 Like