Skip to content

Add Shelly Cloud receiver for OpenTelemetry Collector#154

Merged
zmoog merged 6 commits intomainfrom
claude/shelly-metrics-receiver-rzvay
Mar 14, 2026
Merged

Add Shelly Cloud receiver for OpenTelemetry Collector#154
zmoog merged 6 commits intomainfrom
claude/shelly-metrics-receiver-rzvay

Conversation

@zmoog
Copy link
Copy Markdown
Owner

@zmoog zmoog commented Mar 14, 2026

Summary

This PR adds a new OpenTelemetry Collector receiver for Shelly Cloud smart home devices. The receiver integrates with the Shelly Cloud API to collect metrics from Shelly smart switches and relays, supporting both Gen1 and Gen2 device formats.

Key Changes

  • New Shelly Cloud Receiver Module (receiver/shellycloudreceiver/)

    • client.go: Implements the Shelly Cloud API client with methods to list devices, fetch device status, and parse both Gen1 and Gen2 device formats
    • config.go: Configuration schema with validation for server_url, auth_key, and collection_interval settings
    • factory.go: Receiver factory implementation following OpenTelemetry Collector patterns
    • scraper.go: Scraper implementation that orchestrates device discovery and metric collection
    • marshaler.go: Converts device status data into OpenTelemetry metrics with proper resource attributes and metric types
  • Metrics Exported

    • Switch state (on/off)
    • Active power (W)
    • RMS voltage (V)
    • RMS current (A)
    • AC frequency (Hz)
    • Total energy consumed (Wh)
    • Device internal temperature (°C)
    • WiFi signal strength (RSSI, dBm)
  • Device Support

    • Gen2 devices: Parsed from switch:N components with comprehensive metrics
    • Gen1 devices: Parsed from meters and relays arrays with legacy format support
    • Automatic room name resolution for device context
    • Offline devices are skipped during collection with debug logging
  • Resource Attributes

    • Device ID, name, model, room, and channel
    • WiFi network metadata (SSID, IP address)
  • Reliability & Rate Limiting

    • Per-device online status check before fetching full device status
    • Configurable request delay between API calls to avoid rate limiting
    • Improved API error messages include response body details for easier debugging
  • Integration

    • Updated collector/go.mod to include the new receiver module
    • Updated collector/components.go to register the Shelly Cloud receiver factory
    • Updated go.work to include the receiver module in the workspace

Implementation Details

  • The client handles region-specific Shelly Cloud endpoints and API authentication via auth keys
  • Device status parsing automatically detects Gen1 vs Gen2 formats based on JSON key patterns
  • Energy metrics are marked as monotonic cumulative sums per OpenTelemetry conventions
  • Configurable collection interval with a 60-second minimum

https://claude.ai/code/session_01GUUhdyzy1c1GYyN4LuDeZ5

claude and others added 6 commits March 8, 2026 14:07
Implements an OTel metrics receiver that polls the Shelly Cloud API
at a configurable interval (default 60s) to collect power, energy,
voltage, current, frequency, switch state, and temperature metrics
from all registered Shelly devices.

Key design decisions:
- Supports both Gen1 (meters/relays) and Gen2 (switch:N) device formats
  detected automatically from the API response structure
- Enriches each ResourceMetrics with device name, model, and room from
  Shelly Cloud metadata — no static IP or device list required
- Offline devices are skipped gracefully each scrape cycle

https://claude.ai/code/session_01GUUhdyzy1c1GYyN4LuDeZ5
Correct the device list endpoint and response structure based on
the real API response observed with curl:
- Use GET /interface/device/list instead of POST /interface/device/collection
- Parse data.devices (not data.devices_status)
- Add Gen, Channel, ChannelsCount, BaseID, CloudOnline to DeviceInfo

Also redesign the scraper and marshaler to handle multi-channel
devices properly: the device list already exposes one entry per
channel (e.g. 98a3167ba5d8_1, _2, _3 for a 4-channel strip), each
with its own name and room. The scraper now fetches status once per
physical device (by BaseID) and the marshaler selects the right
channel data using info.Gen and info.Channel.

https://claude.ai/code/session_01GUUhdyzy1c1GYyN4LuDeZ5
Surface the 'errors' field from the Shelly Cloud response so failures
are actionable without needing to curl manually.

https://claude.ai/code/session_01GUUhdyzy1c1GYyN4LuDeZ5
- Add request_delay config (default 500ms) between device status calls
  to avoid hitting Shelly Cloud rate limits when polling many devices
- Check data.online in the device status response and skip gracefully
  when a device is reported offline at fetch time

https://claude.ai/code/session_01GUUhdyzy1c1GYyN4LuDeZ5
Parses wifi_sta (Gen1) and wifi (Gen2+) from device status:
- shelly.wifi.rssi → Gauge metric (dBm), emitted per channel
- shelly.wifi.ssid → resource attribute
- shelly.wifi.ip   → resource attribute

https://claude.ai/code/session_01GUUhdyzy1c1GYyN4LuDeZ5
@zmoog zmoog marked this pull request as ready for review March 14, 2026 08:07
@zmoog zmoog merged commit 812a47f into main Mar 14, 2026
6 checks passed
@zmoog zmoog deleted the claude/shelly-metrics-receiver-rzvay branch March 14, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants