Skip to content

[tibber] Rework binding (channel groups, UoM, Thing actions and more) - #18726

Merged
lsiepel merged 31 commits into
openhab:mainfrom
weymann:tibber-rework-5
Jul 13, 2025
Merged

[tibber] Rework binding (channel groups, UoM, Thing actions and more)#18726
lsiepel merged 31 commits into
openhab:mainfrom
weymann:tibber-rework-5

Conversation

@weymann

@weymann weymann commented May 29, 2025

Copy link
Copy Markdown
Member

It's WIP but I tested now for 2 weeks and it's published on Marketplace. Please start review!

On first hand PR shall solve issue #18506. Seeing all these null fields in the binding it's hard to determine which thread is settiing which variable to null so I decided for a rework.

Rework Rationale

  • spot-prices obtained once per day respecting retry machanism
  • spot-prices were Number:Dimensionless - now tit's changed to Number:EnergyPrice
  • price level polled every minute.
  • price level is a human readable String . Now it's a Number machine readable with < 0 cheap and > 0 expensive.
  • price level now avaialble as TimeSeries
  • channels according to styleguide without underlines like live_
  • logic groups for live power channels and statistic kWh channels

Rework contains:

  • Configuration
    • updateHour - hour of day when prices shall be updated. Retries are performed accoring to Tibber API requirements.
  • Channels rework
    • price group
      • spot-prices current and forecast prices as Number:EnergyPrice
      • level current and forecast price levels as Number with 0=Normal, negative values cheaper, positve values expensive
      • average current and forecast of 24h average prices as Number:EnergyPrice
    • live group for Tibber Pulse power, voltage and current values
    • statistics group for Tibber Pulse energy values
  • ThingActions added for price calculations
    • priceInfoStart - earliest price info available
    • priceInfoEnd - latest price info available
    • listPrices - retreive list in ascending / descending order of prices
    • bestPricePeriod - calculate best rpice in consecutive period
    • bestPriceSchedule - calculate best rpice as non consecutive schedule

@weymann
weymann requested a review from kjoglum as a code owner May 29, 2025 21:49
@openhab-bot

Copy link
Copy Markdown
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/tibber-oh5/164158/4

@lsiepel lsiepel added the enhancement An enhancement or new feature for an existing add-on label May 30, 2025
@weymann weymann changed the title [WIP][tibber] Rework OH5 [tibber] Rework OH5 Jun 16, 2025
@mstormi

mstormi commented Jul 5, 2025

Copy link
Copy Markdown
Contributor

@lsiepel I believe @kjoglum is no longer with us, I haven't heard anything from him in several months although I tried to contact him.

Can you please reassign this review to someone else, yourself maybe?
It's really about fixing bugs/annoyances anyone to use the current Tibber binding keeps encountering more or less weekly.
Thanks!

@lsiepel
lsiepel requested a review from Copilot July 6, 2025 08:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reworks the Tibber binding for OpenHAB 5, consolidating channels into three groups, updating the spot-price logic, and adding comprehensive test coverage and migration instructions.

  • Introduces three channel groups (price, live, statistics) and updates thing-types and channel-types to match the OH5 style guide.
  • Adds new test resources and unit tests for spot prices, price schedules, laundry-curve parsing, and action APIs.
  • Updates migration instructions (instructions.xml) to remove old channels and add new ones, and replaces the refresh parameter with updateHour.

Reviewed Changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/resources/OH-INF/update/instructions.xml Updated migration instructions for OH5, removing old and adding new channels.
src/main/resources/OH-INF/thing/thing-types.xml Removed legacy channels, defined channel groups, bumped thingTypeVersion to 3, added updateHour config.
src/main/resources/OH-INF/thing/price-group.xml Defined the price channel group with new channel IDs.
src/main/resources/OH-INF/thing/live-group.xml Defined the live channel group and its channels for pulse data.
src/main/resources/OH-INF/thing/statistics-group.xml Defined the statistics channel group for energy/production stats.
src/test/resources/curve.json Test resource for laundry-curve conversion (contains a JSON syntax issue).
Comments suppressed due to low confidence (2)

bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/thing/price-group.xml:10

  • Channel ID spot-price does not match the migration instructions which add spot-prices. Please unify the ID names for consistency.
			<channel id="spot-price" typeId="price">

bundles/org.openhab.binding.tibber/src/test/resources/curve.json:2

  • Invalid JSON: an object literal cannot start with a bare array. Either remove the outer {} or add a property name before the array to form valid JSON.
    [

Comment thread bundles/org.openhab.binding.tibber/src/main/resources/OH-INF/thing/live-group.xml Outdated

@jlaur jlaur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this major refactoring! I have had a look and posted some comments.

Since this is a breaking change removing all channels and providing new ones, I'm wondering if should target 5.0 or 5.1. It would have been good to have it included in some milestone releases. How much has the community already been involved in testing?

logger.debug("WebSocket connected to Server");
// String subScriptionMessage = String.format(handler.getTemplate(WEBSOCKET_SUBSCRIPTION_RESOURCE_PATH),
// config.homeid);
String subScriptionMessage = String.format(SUBSCRIPTION_MESSAGE, config.homeid);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to subscribe to events for unlinked channels? Consider populating a DTO and serializing this into the subscribe message.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Can be done very granular.
To be honest this takes now too much effort

  • check every time which channels are connected
    • are channels added or removed
      • unsubscribe then subribe again

To be honest I cannot provide this in short timeframe

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be refined further later, let's leave it like this for now.

if (!elem.isJsonNull()) {
return elem.getAsString();
} else {
return NULL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to actually return null so that the string "null" doesn't become some reserved value?

@weymann weymann Jul 11, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to NULL_VALUE to avoid confusion with java null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was the returning the literal string "null" as a reserved value prevents the actual string "null" to be normally returned. The method could return null in this case to be handled specially.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can come back to this in a follow-up PR.

weymann added 21 commits July 9, 2025 22:22
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Comment thread bundles/org.openhab.binding.tibber/README.md Outdated
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
@jlaur

jlaur commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

@lsiepel - can you verify my latest commits?

@jlaur jlaur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. There are a few open comments left. I would appreciate any relevant feedback also after the merge.

@jlaur jlaur changed the title [tibber] Rework OH5 [tibber] Rework binding (channel groups, UoM, Thing actions and more) Jul 13, 2025

@lsiepel lsiepel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll merge this at 16:00, with or without the suggested changes.
You allready highlighted the parts i wanted to mention. A breaking change notice should also be added (of not alread) to the distro repo.

Comment on lines +78 to +83
public static final String SCHEDULE_CONTAINER = "{\"size\":%s, \"cost\":%s, \"schedule\":%s}";
public static final String QUERY_CONTAINER = "{\"query\":\"%s\"}";
public static final String WEBSOCKET_URL_QUERY = "{\"query\":\"{viewer {websocketSubscriptionUrl }}\"}";
public static final String CONNECT_MESSAGE = "{\"type\":\"connection_init\", \"payload\":{\"token\":\"%s\"}}";
public static final String DISCONNECT_MESSAGE = "{\"type\":\"connection_terminate\",\"payload\":null}";
public static final String SUBSCRIPTION_MESSAGE = "{\"id\":\"1\",\"type\":\"subscribe\",\"payload\":{\"variables\":{},\"extensions\":{},\"operationName\":null,\"query\":\"subscription { liveMeasurement(homeId:\\\"%s\\\") { timestamp power lastMeterConsumption lastMeterProduction accumulatedConsumption accumulatedConsumptionLastHour accumulatedCost currency minPower averagePower maxPower voltagePhase1 voltagePhase2 voltagePhase3 currentL1 currentL2 currentL3 powerProduction accumulatedProduction accumulatedProductionLastHour minPowerProduction maxPowerProduction }}\"}}";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future refactoring it would be a step forward to create proper DTO's for these

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Override
public String toString() {
return "{\"power\":" + powerWatts + ",\"duration\":" + durationSeconds + "}";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree


@Override
public String toString() {
return "{\"price\":" + price + ",\"duration\":" + durationSeconds + ",\"level\":" + level + ",\"startsAt\":\""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

@jlaur

jlaur commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

A breaking change notice should also be added (of not alread) to the distro repo.

I have created openhab/openhab-distro#1766

@lsiepel

lsiepel commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

Ok looked at the comments that are left, i merge this now. Quick fixes usually tend (let me speak for myself) to create regressions. So if there are any post merge findings a new PR can be created easily. Thanks @weymann for your efforts on this refactoring!

@lsiepel
lsiepel merged commit 7826fa9 into openhab:main Jul 13, 2025
2 checks passed
@lsiepel lsiepel added this to the 5.0 milestone Jul 13, 2025
@jlaur

jlaur commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

@weymann - thank you for the major rework in the binding! 👍

phenix1990 pushed a commit to phenix1990/openhab-addons that referenced this pull request Jul 31, 2025
…openhab#18726)

* use common httpclient

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Aug 6, 2025
…openhab#18726)

* use common httpclient

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Paul Smedley <paul@smedley.id.au>
computergeek1507 pushed a commit to computergeek1507/openhab-addons that referenced this pull request Mar 16, 2026
…openhab#18726)

* use common httpclient

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Signed-off-by: Scott Hanson <scooter_seh@yahoo.com>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request Jun 13, 2026
…openhab#18726)

* use common httpclient

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature for an existing add-on (potentially) not backward compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants