Skip to content

About

Prometheus exporter for Nest thermostat and outdoor weather metrics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

nest-exporter

A small Prometheus exporter that polls a Google Nest thermostat (via the Smart Device Management API) and an outdoor weather reading (via OpenWeatherMap) and exposes both as Prometheus metrics.

Metrics

Metric Description
nest_ambient_temperature_celsius Indoor ambient temperature reported by the thermostat
nest_setpoint_temperature_celsius Target temperature set on the thermostat
nest_humidity_percent Indoor ambient humidity reported by the thermostat
nest_hvac_state{state="off|heating|cooling"} 1 for the thermostat's current HVAC state, 0 for the others
nest_up 1 if the last poll of the Nest SDM API succeeded, 0 otherwise
nest_weather_temperature_celsius Outdoor temperature from OpenWeatherMap
nest_weather_humidity_percent Outdoor humidity from OpenWeatherMap
nest_weather_pressure_hectopascal Outdoor atmospheric pressure from OpenWeatherMap
nest_weather_up 1 if the last poll of the OpenWeatherMap API succeeded, 0 otherwise

Metrics are served on /metrics.

Configuration

All configuration is via environment variables.

Variable Required Description
NEST_CLIENT_ID yes OAuth client ID for your Device Access project
NEST_CLIENT_SECRET yes OAuth client secret
NEST_PROJECT_ID yes Google Device Access project ID
NEST_REFRESH_TOKEN yes OAuth refresh token for the account that owns the thermostat
OWM_API_KEY yes OpenWeatherMap API key
OWM_LOCATION_ID yes OpenWeatherMap city/location ID to poll for outdoor conditions
LISTEN_ADDR no Address to serve /metrics on (default :9777)
POLL_INTERVAL_SECONDS no Seconds between polls of both APIs (default 60)

Getting Nest credentials

  1. Enroll in the Device Access program and create a project to get a NEST_PROJECT_ID.
  2. Create an OAuth client in the Google Cloud console for that project to get NEST_CLIENT_ID / NEST_CLIENT_SECRET.
  3. Run through the OAuth authorization flow once to obtain a NEST_REFRESH_TOKEN; the exporter uses it to mint short-lived access tokens on every poll.

Getting weather credentials

  1. Create a free OpenWeatherMap account and API key for OWM_API_KEY.
  2. Look up your city/location ID via their city list for OWM_LOCATION_ID.

Running

Docker

docker build -t nest-exporter .
docker run -p 9777:9777 \
  -e NEST_CLIENT_ID=... \
  -e NEST_CLIENT_SECRET=... \
  -e NEST_PROJECT_ID=... \
  -e NEST_REFRESH_TOKEN=... \
  -e OWM_API_KEY=... \
  -e OWM_LOCATION_ID=... \
  nest-exporter

From source

cd app
go build -o nest-exporter .
NEST_CLIENT_ID=... NEST_CLIENT_SECRET=... NEST_PROJECT_ID=... \
NEST_REFRESH_TOKEN=... OWM_API_KEY=... OWM_LOCATION_ID=... \
  ./nest-exporter

Helm

A chart is included under helm/. It expects a Secret named nest-exporter-secrets in the release namespace (see helm/templates/secret.yaml) — supply the six credentials above as a values override, e.g.:

secrets:
  nestClientId: "..."
  nestClientSecret: "..."
  nestProjectId: "..."
  nestRefreshToken: "..."
  owmApiKey: "..."
  owmLocationId: "..."
helm install nest-exporter ./helm -f my-secrets.yaml

Development

cd app
go test ./...

Releases

Releases are cut automatically by release-please whenever conventional-commit changes land on main; each release build attaches cross-compiled binaries (linux/darwin, amd64/arm64) to the GitHub Release.

License

MIT

About

Prometheus exporter for Nest thermostat and outdoor weather metrics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages