No description
  • Go 87.6%
  • Go Template 8.5%
  • Dockerfile 3.9%
Find a file
Jonas Leder 65a76b3afc
All checks were successful
CI / build (push) Successful in 2m3s
CI / helm (push) Successful in 0s
CI / docker (push) Successful in 0s
CI / build-1 (push) Successful in 36s
Port CI to Forgejo Actions
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-18 10:46:21 +01:00
.forgejo/workflows Port CI to Forgejo Actions 2026-11-18 10:46:21 +01:00
charts/shelly-prometheus-exporter add helm chart 2026-10-11 11:37:50 +02:00
config.go add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
Dockerfile Update golang Docker tag to v1.27.4 2026-11-12 00:01:57 +00:00
go.mod add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
go.sum add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
main.go add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
metrics.go add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
mqtt.go add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
mqtt_test.go add shelly MQTT exporter 2026-10-11 11:26:39 +02:00
Readme.md add helm chart 2026-10-11 11:37:50 +02:00
renovate.json define renovate config 2026-10-11 11:39:29 +02:00

Shelly Prometheus Exporter

Subscribes to the MQTT topics of Shelly Gen2+ devices and exposes their status as Prometheus metrics on /metrics.

Configuration

All configuration is done via environment variables.

Variable Default Description
MQTT_BROKER (required) Broker URL, e.g. tcp://192.168.1.10:1883 or ssl://broker:8883
MQTT_USERNAME Username; leave empty for brokers without authentication
MQTT_PASSWORD Password
MQTT_CLIENT_ID shelly-prometheus-exporter MQTT client ID
MQTT_QOS 0 Subscription QoS (0, 1 or 2)
MQTT_TOPICS Comma-separated device topic prefixes, e.g. shellyplussmoke-halle-2,shellyplussmoke-funkzentrale
MQTT_WILDCARD_TOPIC Topic prefix with MQTT wildcard, e.g. + (all root-level devices) or shellies/+
LISTEN_ADDRESS :9784 HTTP listen address for the metrics endpoint
LOG_LEVEL INFO ERROR, WARN, INFO or DEBUG
LOG_FOLDER If set, logs are additionally written to <LOG_FOLDER>/application.log

At least one of MQTT_TOPICS or MQTT_WILDCARD_TOPIC must be set. For each prefix the exporter subscribes to <prefix>/online, <prefix>/status/+ and <prefix>/events/rpc. The device label is the last segment of the prefix.

Metrics

Metric Labels Source
shelly_online device <device>/online
shelly_cloud_connected device status/cloud → connected
shelly_mqtt_connected device status/mqtt → connected
shelly_smoke_alarm device, id status/smoke:<id> → alarm
shelly_smoke_mute device, id status/smoke:<id> → mute
shelly_battery_voltage_volts device, id status/devicepower:<id> → battery.V
shelly_battery_percent device, id status/devicepower:<id> → battery.percent
shelly_last_message_timestamp_seconds device Time of the last message from the device

NotifyStatus events on <device>/events/rpc are applied too, so e.g. a smoke alarm shows up immediately.

To export more values, add an entry to the mappings table in metrics.go.

Example

MQTT_BROKER=tcp://192.168.1.10:1883 MQTT_WILDCARD_TOPIC=+ go run .

Helm

A chart is located in charts/shelly-prometheus-exporter. It deploys the exporter, a Service and a ServiceMonitor (requires the Prometheus Operator CRDs, disable with serviceMonitor.enabled=false).

Inline connection settings:

helm install shelly-exporter charts/shelly-prometheus-exporter \
  --set mqtt.broker=tcp://192.168.1.10:1883 \
  --set mqtt.username=exporter --set mqtt.password=secret \
  --set mqtt.wildcardTopic=+

Existing secret (keys MQTT_BROKER, optional MQTT_USERNAME / MQTT_PASSWORD, configurable via mqtt.existingSecretKeys):

kubectl create secret generic shelly-mqtt \
  --from-literal=MQTT_BROKER=tcp://192.168.1.10:1883 \
  --from-literal=MQTT_USERNAME=exporter --from-literal=MQTT_PASSWORD=secret

helm install shelly-exporter charts/shelly-prometheus-exporter \
  --set mqtt.existingSecret=shelly-mqtt \
  --set 'mqtt.topics={shellyplussmoke-halle-2,shellyplussmoke-funkzentrale}'