Skip to content

Repository files navigation

Tuya exporter for prometheus

Prometheus exporter for Tuya-based smart plug devices. Tested with Immax Neo Lite smart plug.

Following Tuya LAN protocol versions are supported 1/tested.

Version Supported Tested
3.1
3.2 🚫
3.3 🚫
3.4
3.5 🚫 🚫

1 - supported by protocol library, not by exporter itself

smartplug

smartplug2

Setup

devices:
  plug-kitchen-1:
    id: 87e98a987b87b12354a54c
    key: 0987654321abcdef
    address: 192.168.1.5:6668
    connectTimeout: 10s
    readTimeout: 7s

Note: there is JSON schema for configuration here

Run locally

./exporter
ts=2024-02-25T08:18:50.577Z caller=main.go:83 level=info msg="Starting tuya_smartplug_exporter" version="(version=v1.0.0, branch=main, revision=9d0b7b3)" config=config.yaml
ts=2024-02-25T08:18:50.582Z caller=main.go:98 level=info msg="Configured 1 devices"
ts=2024-02-25T08:18:50.583Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:9999
ts=2024-02-25T08:18:50.583Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:9999

Run using docker

docker run -ti -v $(pwd)/config.yaml:/config.yaml:ro ghcr.io/rkosegi/tuya-smartplug-exporter:v1.1.0

Example output

curl --silent localhost:9999/metrics | grep ^tuya
tuya_smartplug_exporter_build_info{branch="main",goarch="amd64",goos="linux",goversion="go1.26.2",revision="96c611a",tags="unknown",version="v1.1.0"} 1
tuya_smartplug_last_scrape_error 0
tuya_smartplug_current{device="livingroom-1"} 0.093
tuya_smartplug_power{device="livingroom-1"} 8.6
tuya_smartplug_scrape_duration_sum{device="livingroom-1"} 73
tuya_smartplug_scrape_duration_count{device="livingroom-1"} 1
tuya_smartplug_total_scrapes_sum 0.62671565
tuya_smartplug_total_scrapes_count 3
tuya_smartplug_voltage{device="livingroom-1"} 242.9
tuya_smartplug_read_packets_total{device="livingroom-1"} 6
tuya_smartplug_sent_packets_total{device="livingroom-1"} 9

Description of metrics

Name Type Description Scope
tuya_smartplug_last_scrape_error Counter Indication of overall error during scrape Global
tuya_smartplug_scrapes_total Summary Overall duration and count of scrapes Global
tuya_smartplug_exporter_build_info Gauge Build info Global
tuya_smartplug_current Gauge Electrical current drawn, in Amperes Device
tuya_smartplug_power Gauge Total power used, in Watts Device
tuya_smartplug_scrape_duration Summary Summary of scrape operation Device
tuya_smartplug_switch_on Gauge Whether the plug is switched on (1 for on, 0 for off) Device
tuya_smartplug_voltage Gauge Electrical voltage, in Volts Device
tuya_smartplug_read_errors_total Counter Total number of read errors Device
tuya_smartplug_read_packets_total Counter Total number of read packets Device
tuya_smartplug_sent_errors_total Counter Total number of sent errors Device
tuya_smartplug_sent_packets_total Counter Total number of sent packets Device

Install using Helm chart to k8s cluster

First, make sure your values are present in file my-values.yaml, then run

helm repo add rkosegi https://rkosegi.github.io/helm-charts/ --force-update
helm upgrade --install rkosegi/generic-exporter --values my-values.yaml

Sample Grafana dashboard

dashboard

Acknowledgment

Portion of client code is inspired by @jasonacox implementation in powermonitor

About

Prometheus exporter for Tuya-based smartplug devices

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages