Skip to content

Show energy meter devices as a power meter in the Energy tab#75

Open
dohun0310 wants to merge 4 commits into
AdyRock:masterfrom
dohun0310:master
Open

Show energy meter devices as a power meter in the Energy tab#75
dohun0310 wants to merge 4 commits into
AdyRock:masterfrom
dohun0310:master

Conversation

@dohun0310

Copy link
Copy Markdown

Problem

SmartThings devices that only report power/energy (e.g. whole-home energy monitors) were paired in Homey as a plain sensor with just a meter_power capability. They never appeared in Homey's Energy tab as a power meter, and live power readings (W) were missing entirely.

Root causes

  1. Swapped capability mappings. In the pairing table (CapabilityMap2), the SmartThings energyMeter capability (accumulated energy, kWh) was mapped to Homey's measure_power (instantaneous power, W), and powerMeter (W) was mapped to meter_power (kWh) — the exact opposite of the data-fetch mappings in CapabilityMap1.
  2. Fallback sources never ran. getDeviceCapabilityValue() throws on HTTP 422/403 when a SmartThings device does not support the queried capability, and getDeviceValues() reacted by removing the Homey capability immediately — before the configured fallback source (powerConsumptionReport) ever got a chance to run. Combined with the swapped mapping, this is why devices ended up with only meter_power.

Changes

  • Fix the swapped mappings: energyMetermeter_power (kWh) and powerMetermeasure_power (W), matching the data-fetch tables.
  • Try the fallback before removing a capability: when the primary SmartThings capability query is rejected with 422/403 and a fallback source is defined, the fallback is queried first; the capability is only removed if no source can provide data.
  • Mark pure meter devices as cumulative: devices that report power/energy but have no switch are now paired with energy: { "cumulative": true }, so Homey shows them as the home power meter in the Energy tab.
  • Per-device toggle: a new "Show as home power meter in the Energy tab" checkbox (Energy group, EN/KO localized) lets users turn the cumulative-meter treatment on or off per device. Changes take effect immediately via Device.setEnergy().
  • Migration for existing devices: on init, devices with meter_power regain the missing measure_power capability when the SmartThings device actually reports powerMeter, and a one-time migration (guarded by a store flag) defaults the new toggle to ON for pure meter devices (sensor class, no onoff) and OFF for everything else.

Testing

  • Installed on a Homey Pro (self-hosted) with a SmartThings whole-home energy meter: the device now appears in the Energy tab as a cumulative power meter, with live W and accumulated kWh.
  • Verified the toggle in the device's advanced settings switches the Energy-tab treatment on/off without an app restart.
  • homey app validate passes at level debug.

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.

1 participant