From 1f631a6b8e471c4eb76c648bea8024f3f5526e88 Mon Sep 17 00:00:00 2001 From: Arne Seime Date: Thu, 11 Apr 2024 21:58:36 +0200 Subject: [PATCH] [tibber] Add two channels: consumption and production for current hour (#16623) * Add 2 new live channels; consumption and production this hour (since last hour shift) Signed-off-by: Arne Seime --- bundles/org.openhab.binding.tibber/README.md | 50 ++++++++++--------- .../internal/TibberBindingConstants.java | 2 + .../internal/handler/TibberHandler.java | 12 ++++- .../resources/OH-INF/thing/thing-types.xml | 4 +- .../resources/OH-INF/update/instructions.xml | 8 +++ 5 files changed, 50 insertions(+), 26 deletions(-) diff --git a/bundles/org.openhab.binding.tibber/README.md b/bundles/org.openhab.binding.tibber/README.md index 44fba1ed783..0a9b3973700 100644 --- a/bundles/org.openhab.binding.tibber/README.md +++ b/bundles/org.openhab.binding.tibber/README.md @@ -37,29 +37,31 @@ Tibber Default: Tibber Pulse (optional): -| Channel ID | Description | Read-only | -|-----------------------------|------------------------------------------|-----------| -| live_timestamp | Timestamp for live measurements | True | -| live_power | Live Power Consumption | True | -| live_lastMeterConsumption | Last Recorded Meter Consumption | True | -| live_accumulatedConsumption | Accumulated Consumption since Midnight | True | -| live_accumulatedCost | Accumulated Cost since Midnight | True | -| live_accumulatedReward | Accumulated Reward since Midnight | True | -| live_currency | Currency of Cost | True | -| live_minPower | Min Power Consumption since Midnight | True | -| live_averagePower | Average Power Consumption since Midnight | True | -| live_maxPower | Max Power Consumption since Midnight | True | -| live_voltage1 | Voltage Phase 1 | True | -| live_voltage2 | Voltage Phase 2 | True | -| live_voltage3 | Voltage Phase 3 | True | -| live_current1 | Current Phase 1 | True | -| live_current2 | Current Phase 2 | True | -| live_current3 | Current Phase 3 | True | -| live_powerProduction | Live Power Production | True | -| live_accumulatedProduction | Accumulated Production since Midnight | True | -| live_lastMeterProduction | Last Recorded Meter Production | True | -| live_minPowerproduction | Min Power Production since Midnight | True | -| live_maxPowerproduction | Max Power Production since Midnight | True | +| Channel ID | Description | Read-only | +|-------------------------------------|-----------------------------------------------|-----------| +| live_timestamp | Timestamp for live measurements | True | +| live_power | Live Power Consumption | True | +| live_lastMeterConsumption | Last Recorded Meter Consumption | True | +| live_accumulatedConsumption | Accumulated Consumption since Midnight | True | +| live_accumulatedConsumptionThisHour | Accumulated Consumption since last hour shift | True | +| live_accumulatedCost | Accumulated Cost since Midnight | True | +| live_accumulatedReward | Accumulated Reward since Midnight | True | +| live_currency | Currency of Cost | True | +| live_minPower | Min Power Consumption since Midnight | True | +| live_averagePower | Average Power Consumption since Midnight | True | +| live_maxPower | Max Power Consumption since Midnight | True | +| live_voltage1 | Voltage Phase 1 | True | +| live_voltage2 | Voltage Phase 2 | True | +| live_voltage3 | Voltage Phase 3 | True | +| live_current1 | Current Phase 1 | True | +| live_current2 | Current Phase 2 | True | +| live_current3 | Current Phase 3 | True | +| live_powerProduction | Live Power Production | True | +| live_accumulatedProduction | Accumulated Production since Midnight | True | +| live_accumulatedProductionThisHour | Accumulated Production since last hour shift | True | +| live_lastMeterProduction | Last Recorded Meter Production | True | +| live_minPowerproduction | Min Power Production since Midnight | True | +| live_maxPowerproduction | Max Power Production since Midnight | True | ## Binding Configuration @@ -238,6 +240,7 @@ DateTime TibberAPILiveTimestamp "Timestamp - Li Number:Power TibberAPILivePower "Live Power Consumption [%.0f W]" {channel="tibber:tibberapi:7cfae492:live_power"} Number:Energy TibberAPILiveLastMeterConsumption "Last Meter Consumption [%.2f kWh]" {channel="tibber:tibberapi:7cfae492:live_lastMeterConsumption"} Number:Energy TibberAPILiveAccumulatedConsumption "Accumulated Consumption [%.2f kWh]" {channel="tibber:tibberapi:7cfae492:live_accumulatedConsumption"} +Number:Energy TibberAPILiveAccumulatedConsumptionThisHour "kWh consumed since since last hour shift [%.2f kWh]" {channel="tibber:tibberapi:7cfae492:live_accumulatedConsumptionLastHour"} Number:Dimensionless TibberAPILiveAccumulatedCost "Accumulated Cost [%.2f NOK]" {channel="tibber:tibberapi:7cfae492:live_accumulatedCost"} Number:Dimensionless TibberAPILiveAccumulatedReward "Accumulated Reward [%.2f NOK]" {channel="tibber:tibberapi:7cfae492:live_accumulatedReward"} String TibberAPILiveCurrency "Currency" {channel="tibber:tibberapi:7cfae492:live_currency"} @@ -252,6 +255,7 @@ Number:ElectricCurrent TibberAPILiveCurrent2 "Live Current P Number:ElectricCurrent TibberAPILiveCurrent3 "Live Current Phase 3 [%.1 A]" {channel="tibber:tibberapi:7cfae492:live_current3"} Number:Power TibberAPILivePowerProduction "Live Power Production [%.0f W]" {channel="tibber:tibberapi:7cfae492:live_powerProduction"} Number:Energy TibberAPILiveAccumulatedProduction "Accumulated Production [%.2f kWh]" {channel="tibber:tibberapi:7cfae492:live_accumulatedProduction"} +Number:Energy TibberAPILiveAccumulatedProductionThisHour "Net kWh produced since last hour shift [%.2f kWh]" {channel="tibber:tibberapi:7cfae492:live_accumulatedProductionThisHour"} Number:Energy TibberAPILiveLastMeterProduction "Min Power Production [%.0f W]" {channel="tibber:tibberapi:7cfae492:live_lastMeterProduction"} Number:Power TibberAPILiveMinPowerproduction "Min Power Production [%.0f W]" {channel="tibber:tibberapi:7cfae492:live_minPowerproduction"} Number:Power TibberAPILiveMaxPowerproduction "Max Power Production [%.0f W]" {channel="tibber:tibberapi:7cfae492:live_maxPowerproduction"} diff --git a/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/TibberBindingConstants.java b/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/TibberBindingConstants.java index 384ddb0f7eb..7ab5cbc817d 100644 --- a/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/TibberBindingConstants.java +++ b/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/TibberBindingConstants.java @@ -60,6 +60,7 @@ public class TibberBindingConstants { public static final String LIVE_LASTMETERCONSUMPTION = "live_lastMeterConsumption"; public static final String LIVE_LASTMETERPRODUCTION = "live_lastMeterProduction"; public static final String LIVE_ACCUMULATEDCONSUMPTION = "live_accumulatedConsumption"; + public static final String LIVE_ACCUMULATEDCONSUMPTION_THIS_HOUR = "live_accumulatedConsumptionThisHour"; public static final String LIVE_ACCUMULATEDCOST = "live_accumulatedCost"; public static final String LIVE_ACCUMULATEREWARD = "live_accumulatedReward"; public static final String LIVE_CURRENCY = "live_currency"; @@ -74,6 +75,7 @@ public class TibberBindingConstants { public static final String LIVE_CURRENT3 = "live_current3"; public static final String LIVE_POWERPRODUCTION = "live_powerProduction"; public static final String LIVE_ACCUMULATEDPRODUCTION = "live_accumulatedProduction"; + public static final String LIVE_ACCUMULATEDPRODUCTION_THIS_HOUR = "live_accumulatedProductionThisHour"; public static final String LIVE_MINPOWERPRODUCTION = "live_minPowerproduction"; public static final String LIVE_MAXPOWERPRODUCTION = "live_maxPowerproduction"; diff --git a/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java b/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java index d9217886628..b55de4d028f 100644 --- a/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java +++ b/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java @@ -566,6 +566,10 @@ public class TibberHandler extends BaseThingHandler { if (myObject.has("accumulatedConsumption")) { updateChannel(LIVE_ACCUMULATEDCONSUMPTION, myObject.get("accumulatedConsumption").toString()); } + if (myObject.has("accumulatedConsumptionLastHour")) { + updateChannel(LIVE_ACCUMULATEDCONSUMPTION_THIS_HOUR, + myObject.get("accumulatedConsumptionLastHour").toString()); + } if (myObject.has("accumulatedCost")) { updateChannel(LIVE_ACCUMULATEDCOST, myObject.get("accumulatedCost").toString()); } @@ -608,6 +612,10 @@ public class TibberHandler extends BaseThingHandler { if (myObject.has("accumulatedProduction")) { updateChannel(LIVE_ACCUMULATEDPRODUCTION, myObject.get("accumulatedProduction").toString()); } + if (myObject.has("accumulatedProductionLastHour")) { + updateChannel(LIVE_ACCUMULATEDPRODUCTION_THIS_HOUR, + myObject.get("accumulatedProductionLastHour").toString()); + } if (myObject.has("minPowerProduction")) { updateChannel(LIVE_MINPOWERPRODUCTION, myObject.get("minPowerProduction").toString()); } @@ -630,8 +638,8 @@ public class TibberHandler extends BaseThingHandler { public void startSubscription() { String query = "{\"id\":\"1\",\"type\":\"subscribe\",\"payload\":{\"variables\":{},\"extensions\":{},\"operationName\":null,\"query\":\"subscription {\\n liveMeasurement(homeId:\\\"" + tibberConfig.getHomeid() - + "\\\") {\\n timestamp\\n power\\n lastMeterConsumption\\n lastMeterProduction\\n accumulatedConsumption\\n accumulatedCost\\n accumulatedReward\\n currency\\n minPower\\n averagePower\\n maxPower\\n" - + "voltagePhase1\\n voltagePhase2\\n voltagePhase3\\n currentL1\\n currentL2\\n currentL3\\n powerProduction\\n accumulatedProduction\\n minPowerProduction\\n maxPowerProduction\\n }\\n }\\n\"}}"; + + "\\\") {\\n timestamp\\n power\\n lastMeterConsumption\\n lastMeterProduction\\n accumulatedConsumption\\n accumulatedConsumptionLastHour\\n accumulatedCost\\n accumulatedReward\\n currency\\n minPower\\n averagePower\\n maxPower\\n" + + "voltagePhase1\\n voltagePhase2\\n voltagePhase3\\n currentL1\\n currentL2\\n currentL3\\n powerProduction\\n accumulatedProduction\\n accumulatedProductionLastHour\\n minPowerProduction\\n maxPowerProduction\\n }\\n }\\n\"}}"; try { TibberWebSocketListener socket = TibberHandler.this.socket; if (socket != null) { diff --git a/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/thing/thing-types.xml index ce809c5ea4e..d15e00d7954 100644 --- a/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/thing/thing-types.xml @@ -26,6 +26,7 @@ + @@ -42,10 +43,11 @@ + Tibber - 1 + 2 diff --git a/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/update/instructions.xml index e01fe517789..c13b9661800 100644 --- a/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/update/instructions.xml +++ b/bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/update/instructions.xml @@ -9,6 +9,14 @@ tibber:production + + + tibber:consumption + + + tibber:production + +