[evcc] Add channels for grid currents, grid energy and charging currents.#19228
[evcc] Add channels for grid currents, grid energy and charging currents.#19228lsiepel merged 29 commits intoopenhab:mainfrom
Conversation
61bbdc9 to
a3cf11b
Compare
|
@lsiepel Can you check the unit tests I've added? If they are fine I will add tests for the handlers |
lsiepel
left a comment
There was a problem hiding this comment.
Thanks. Especially for attempting to write tests. They look good. When you write more and more you probably refactor and perform some code de-duplication. As that is what i'm experiencing over and over again. :-)
...nding.evcc/src/main/java/org/openhab/binding/evcc/internal/handler/EvccLoadpointHandler.java
Outdated
Show resolved
Hide resolved
.../org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/handler/Utils.java
Outdated
Show resolved
Hide resolved
...g.evcc/src/test/java/org/openhab/binding/evcc/internal/handler/EvccBaseThingHandlerTest.java
Outdated
Show resolved
Hide resolved
|
I will add more tests as soon as possible |
|
Marked this as draft, please change ready to review when you are done. |
|
Hi Marcel, thank you for your work on this! I'm quite new to evcc (but using OH for quite some time ;)) and thought: hey, use this new version of the plugin ;) During my migration I stumbled over an issue with the value in So I started digging into it, and compiled it myself for debugging. After installing my self-compiled own addon, I got this exception: Okay, you try to modify the list returned in EvccBaseThingHandler.java#L282 - which is immutable by nature ;) Now the addon was able to start and things worked again ;) Next I added some debugging output to see what happens with the value. This is what was shown: The value is here - but the unit's are not matching. And yes, looking on the item value - the 2.5 Wh are here, but we need kWh ;) I have seen there is already some handling for unit mismatches in EvccBaseThingHandler.java#L223 and so I added @@ -221,9 +222,13 @@ public abstract class EvccBaseThingHandler extends BaseThingHandler implements E
case NUMBER_LENGTH:
case NUMBER_POWER:
Double finalValue = "%".equals(itemTypeUnit.unitHint) ? value.getAsDouble() / 100 : value.getAsDouble();
- if (channelUID.getId().contains("capacity") || "km".equals(itemTypeUnit.unitHint)) {
+ if (channelUID.getId().contains("capacity") || "km".equals(itemTypeUnit.unitHint)
+ || ("kWh".equals(itemTypeUnit.unitHint) && Units.WATT_HOUR.equals(itemTypeUnit.unit))) {
updateState(channelUID, new QuantityType<>(finalValue, itemTypeUnit.unit.multiply(1000)));
} else if ("Wh".equals(itemTypeUnit.unitHint)) {And now it works for me (tm) ;-) I havent tracked down why unit and unitHint differs. But maybe it would be worth to align it or to maintain unit's matching the UnitHint? Thanks & Bye, |
|
Hi Marcel, now I stumbled over a Channel/Item where it is the other way: It seems this value is really ment as bye, |
bundles/org.openhab.binding.evcc/src/main/resources/OH-INF/thing/site.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.evcc/src/main/resources/OH-INF/thing/loadpoint.xml
Outdated
Show resolved
Hide resolved
|
@marvkis Thanks for the input. |
In the latest version everything is running fine. The session energy was at 270Wh and in openHAB it was displayed as 0.27kWh. |
|
Hi Marcel, Sorry for the late reply – I had Covid.
Here is my state.json file with the relevant values: state-loadlimit.json Here a fragment with the values from Let's start with This is why I mode the change in EvccBaseThingHandler.java#L223, as mentioned in my previous post. After making this change I noted that I think the Having briefly viewed the JSON and the loadpoint.xml it also seems that the unit for I believe that the adjusting the kWh calculation could reveal several more such (kilo-) mismatches. I hope you can understand where my original problem lay and why I am suggesting this change. thanks & bye, |
|
Oh I hope you feel we'll again. I see what you mean. I will take a deeper look into it. Probably you are right that there will be less calculation to do when I'm matching the values unit and the unit hints. I think I wanted the values to be congruent. I will see what I can do. Unfortunately there is no documentation from evcc which unit each data point has. |
|
Just for the record. The unitHint is only there for the presentation in the openHAB domain. It does not have any effect in the read value from the evcc api. UoM is in between. When reading the value from the API and updating the channel one should know the value /precision |
|
Hi @lsiepel , thanks for pointing this out - I wasn't aware of that. Using it as a hint for API precision doesn't seem like a good idea anymore. Is there any way to specify a 'custom' channel attribute that can be used as the 'unit used by the API'? |
|
Since the channels are getting created dynamically, what would be a smart way to get the correct UoM for the values? Right now I'm using the unit hints as a hint to the UoM. |
|
Well it depends about every API provides this. Usually three ways they do this:
You can also use a mapping file and provide it yourself, but I don’t think you want that here. Does that provide enough information to continue? |
|
Hmm, unfortunately there is no documentation about the units and they are also not enclosed. I guess I have to define a file myself. |
lsiepel
left a comment
There was a problem hiding this comment.
Left two comments to look at.
I would prefer to have some test confirmations due to the extend of this PR. Maybe provide a jar to the community or otherwise. Ping me when both tests and comments are addressed.
.../org.openhab.binding.evcc/src/main/java/org/openhab/binding/evcc/internal/handler/Utils.java
Show resolved
Hide resolved
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
|
Done |
Only after Spotless ;-) |
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
Nooooooooo, sorry for that. Now I'm done 😄 |
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
lsiepel
left a comment
There was a problem hiding this comment.
Thanks for providing this PR. LGTM
I'll merge when you let me know this has been tested enough.
|
On my site it is running well just waiting for some responses of the community. |
|
Hi @marcelGoerentz , Thanks for all your work! I've tested the latest version, and But it seems the precision for /Chris |
|
Hi @marcelGoerentz, I've found where it's shown in evcc: It's hidden in the config view for the charger. And here it is also visualized as kWh - so it seems /chris |
|
Hi @marvkis , |
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
|
Hi @marcelGoerentz , thanks for the update. When I try to install the addon I get this excpetion: I think it is related to this change: 701b164#diff-33f058b22b270592f6020bb2ab248034e02ae4816d0cc9240c8180a4dc58492b shouldn't it be I've fixed it locally. Now it loads again, but the Last but not least a new one from the openhab log i've noticed: When i'm right removing the Thanks for all! /chris |
|
You are completely right in everything you mentioned. I added your suggestions. Thanks again. The one with the Loadpoint is an old one, I don't know why it didn't come up to me earlier... |
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
|
@marcelGoerentz It looks good now from my side! Thanks @marcelGoerentz for all your work! /chris |
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
|
For those who want to test the latest version: |
|
Hi @marcelGoerentz , i've updated to your .jar and it seems the /chris |
|
I added a comment where i think |
|
Ah yeah, that happens when I do something different than before, I missed that special case. |
Signed-off-by: Marcel Goerentz <57457529+marcelGoerentz@users.noreply.github.com>
|
I've updated the jar files in the link. Energy limit is now fixed. |
|
Hi, I just tested the latest jar - LGTM now ;) /chris |
Enhancement for evcc binding: