I’m requesting state from an external device via an HTTP JSON API and use the HTTP binding.
One channel looks like this: Type number : chargingPower "chargingPower" [ stateExtension="state", stateTransformation="JSONPATH:$.charging_power", unit="W", mode="READONLY" ]
The device’s API has an issue though which is that the value is not always updated when charging stops. So while no charging is performed the charging_power still shows the last positive value which is highly confusing and breaks my metrics dashboard.
There I’m checking the options I have to “correct” the value and trying to understand if it’s already possible on the Thing level somehow.
The most logical would be to combine the channel with the information from another one:
Type string : state "state" [ stateExtension="state", stateTransformation="JSONPATH:$.state", mode="READONLY" ]
If the above is not “CHARGING” the channel should always provide 0 as a value and only use the API value when state matches CHARGING.
Is there any way to achieve this?
Fallback plan would be to create a (virtual) additional Item which is updated via rule according to the above logic but I’m wondering if there is a solution closer to the origin?
Yes, that is the behavior I see. And I actually consider it a bug in the device but the likeliness of it being fixed by the vendor is low so I’m looking for a workaround.
It doesn’t happen always. Could be a timing issue on the device side but it happens quite often.
Then from my knowledge you have the proxy item and rule or don’t use the http binding and use JavaScript to get status process do the logic and then spit out the result based on the workaround you found.
I had a similar challenge with my Solar Inverter (Growatt, connected via “grott” on MQTT). When the sun goes down it stops reporting and always shows around 6 Watt still being delivered whereas it actually consumes power from the grid to keep itself running.
My solution was to add modBus energy meter showing the actual import/export.
In the end i switch of the inverter when it does not deliver any power and switch it on again in the morning based on the astro binding.
I put a separate energy meter in front of my BEV Charger, so I have an independent way to record the consumption.
Works like a charm and you can see the power consumption / delivery without OH as well.
This will return java null (not to be confused with NULL from UnDefType) when wallbox_state is not CHARGING, which will make the state not passed on to the item, as if there was no update.
Tried this latest proposal and it makes sense to me. But the previous version also made sense to me and the only difference according to your explanation would be 0 vs null. But the 0 didn’t work and the null also does not work apparently. After changing it I still get the following events on Thing updates:
2023-09-16 09:02:19.300 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:02:29.278 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:29.282 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:29.285 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:02:39.283 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:39.289 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:39.293 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:02:49.289 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:49.295 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:49.299 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:02:59.286 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:59.294 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:02:59.296 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:03:09.286 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:09.292 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:09.297 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:03:19.294 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:19.302 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:19.305 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:03:29.287 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:29.296 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:29.299 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
2023-09-16 09:03:39.290 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:39.295 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_current_actual' updated to 1751 W
2023-09-16 09:03:39.298 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'wallbox_state' updated to CHARGING_FINISHED
Aha, removing/adding the item didn’t change anything but restarting openhab did: No ProfileFactory found which supports profile 'transform:RB' for link 'wallbox_current_actual -> http:url:dezonyIQ:chargingPower'
As I didn’t use scripting like that so far I didn’t know I have to install some plugin but I assume it’s the JRuby Scripting?
Yes, that was the problem from the beginning then. Sorry for the confusion.
I went back to your first proposal because the other would likely lead to the same issue because once the state switches away from CHARGING it would not update the wrong value to 0 compared to fetching the wrong value from the API. In the end the data would still be wrong.
I will watch out if there still is a problem but I’m pretty confident that it works now.