Metabase BI Data in Lovelace

Hello guys,

i integrated a Metabase dashboard into Home Assistant.

You need a small Python script for this, an command_line sensor,
card-mod and config-custom-template-card mods for lovelace.

Python Script:

import jwt
import time

METABASE_SITE_URL = "https://metabase.xxx.de"
METABASE_SECRET_KEY = "da4de207f002b22478d920973b058d62d69cd72ce81bd229df1ec09xx"

payload = {
  "resource": {"dashboard": 1},
  "params": {
  },
  "exp": round(time.time()) + (60 * 10) # 10 minute expiration
}


token = jwt.encode(payload, METABASE_SECRET_KEY, algorithm="HS256")
iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token.decode("utf8") + "#bordered=false&titled=true"

print (iframeUrl)

command_line_sensor:

  - platform: command_line
    command: '/usr/local/bin/python3 /home/homeassistant/metabaseSign/createURI.py'
    name: "metabaseURI"
    scan_interval: 300

ui-lovelace:

  - title: Einkäufe
    id: einkaufe
    icon: mdi:currency-eur
    panel: true
    cards:
     - type: 'custom:config-template-card'
       entities:
         - sensor.metabaseuri
       card:
         type: iframe
         style: |
          #root {
            height: calc(100vh - 48.5px);
            padding-top: 0 !important;
          }
         url: ${states['sensor.metabaseuri'].state}
         aspect_ratio: 60%

You have to fill in the METABASE_SITE_URL and METABASE_SECRET_KEY to make it work.

Here are some screenshots: