openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.59k forks source link

[tibber] monthly and annual information. #16797

Open DrScr3w opened 6 months ago

DrScr3w commented 6 months ago

Please add the following channels to the binding for getting monthly and annual information.

openhab-bot commented 6 months ago

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

https://community.openhab.org/t/tibber-binding/67019/288

DrScr3w commented 1 month ago

Hello, is it possible to include this in the next release please?

lsiepel commented 1 month ago

Hello, is it possible to include this in the next release please?

If these are available by the API it should not be that hard to implement. Do you have the JSON or schema details? If these are not available, it might be better to calculate this using rules and persistence.

DrScr3w commented 2 weeks ago

@lsiepel I hope that I have determined it correctly ;) https://developer.tibber.com/explorer

Under “Consumptions” you can see the “cost” and "consumption" and there you can switch from “hourly” to “monthly” or "annual". image image image

DrScr3w commented 2 weeks ago

Wouldn't it “only” be necessary to add more IFs with monthly and annual?

https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.tibber/src/main/java/org/openhab/binding/tibber/internal/handler/TibberHandler.java

Line 234

if (jsonResponse.contains("daily") && !jsonResponse.contains("\"daily\":{\"nodes\":[]")
        && !jsonResponse.contains("\"daily\":null")) {
    try {
        JsonObject myObject = (JsonObject) rootJsonObject.getAsJsonObject("data").getAsJsonObject("viewer")
                .getAsJsonObject("home").getAsJsonObject("daily").getAsJsonArray("nodes").get(0);

        String timestampDailyFrom = myObject.get("from").toString().substring(1, 20);
        updateState(DAILY_FROM, new DateTimeType(timestampDailyFrom));

        String timestampDailyTo = myObject.get("to").toString().substring(1, 20);
        updateState(DAILY_TO, new DateTimeType(timestampDailyTo));

        updateChannel(DAILY_COST, myObject.get("cost").toString());
        updateChannel(DAILY_CONSUMPTION, myObject.get("consumption").toString());
    } catch (JsonSyntaxException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
                "Error communicating with Tibber API: " + e.getMessage());
    }
}
lsiepel commented 2 weeks ago

You are right, it is not a complicated change. But there is more to it: the README.md and the thing-structure.xml need to be adapted and don't forget the thing upgrade instructions.

DrScr3w commented 2 weeks ago

Do you think you can include these things in the next release?