openhab / openhab-addons

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

[modbus] Do not process values from channel if configured transformation service is unavailable (during startup) #16847

Open dandjo opened 1 month ago

dandjo commented 1 month ago

Expected Behavior

Consistent value range for items.

Current Behavior

When starting or restarting openHAB, services like ModBus poll data from server ignore transformation services (here: JS) when they are not ready. This results in values out of usual value range destroying average calculations and representations (e.g. in Grafana - see screenshot).

image

image

2024-05-29 14:01:44.121 [INFO ] [org.openhab.core.Activator          ] - Starting openHAB 4.2.0 (Build openhab/openhab-core#4103)
2024-05-29 14:01:49.660 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/Vienna'.
2024-05-29 14:01:49.671 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to 'en_AT'.
2024-05-29 14:01:49.674 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Measurement system set to 'SI'.
2024-05-29 14:02:01.593 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'influxdb.persist'
2024-05-29 14:02:02.905 [WARN ] [penhab.core.library.items.NumberItem] - Unit 'rpm' could not be parsed to a known unit. Keeping old unit 'one' for item 'miele_washing_machine_wwg360_spinning_speed'.
2024-05-29 14:02:08.717 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2024-05-29 14:02:10.980 [INFO ] [internal.handler.OnectaBridgeHandler] - Discovered a onecta unit thing with ID '44da5053-e3a9-4519-ba71-43e8da9f3642' '44da5053-e3a9-4519-ba71-43e8da9f3642'
2024-05-29 14:02:11.021 [INFO ] [internal.handler.OnectaBridgeHandler] - Discovered a onecta gateway thing with ID '44da5053-e3a9-4519-ba71-43e8da9f3642' '44da5053-e3a9-4519-ba71-43e8da9f3642'
2024-05-29 14:02:11.030 [INFO ] [internal.handler.OnectaBridgeHandler] - Discovered a onecta watertank thing with ID '44da5053-e3a9-4519-ba71-43e8da9f3642' '44da5053-e3a9-4519-ba71-43e8da9f3642'
2024-05-29 14:02:11.046 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2024-05-29 14:02:27.372 [WARN ] [ty.util.ssl.SslContextFactory.config] - Trusting all certificates configured for Client@6d7da0b[provider=null,keyStore=null,trustStore=null]
2024-05-29 14:02:27.376 [WARN ] [ty.util.ssl.SslContextFactory.config] - No Client EndPointIdentificationAlgorithm configured for Client@6d7da0b[provider=null,keyStore=null,trustStore=null]
2024-05-29 14:02:28.885 [INFO ] [nding.http.internal.HttpThingHandler] - Using the secure client for thing 'http:url:epex_spot_awattar'.
2024-05-29 14:02:29.276 [INFO ] [rt.modbus.internal.ModbusManagerImpl] - Modbus manager activated
2024-05-29 14:02:30.360 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_current_item'}, service not found
2024-05-29 14:02:30.364 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_extrema_item'}, service not found
2024-05-29 14:02:30.367 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_extrema_item'}, service not found
2024-05-29 14:02:30.372 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_current_item'}, service not found
2024-05-29 14:02:30.374 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_current_item'}, service not found
2024-05-29 14:02:30.378 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_extrema_item'}, service not found
2024-05-29 14:02:30.383 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='JS', function='config:js:awattar_extrema_item'}, service not found
2024-05-29 14:02:32.321 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid ae9753ea-0d0b-4be9-8d2d-b838af1cee34
2024-05-29 14:02:36.449 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.493 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.498 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.507 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.516 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.528 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.537 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.543 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.550 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.559 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.565 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:37.575 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:38.397 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:38.403 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:38.407 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable
2024-05-29 14:02:38.411 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'JS' is unavailable

Possible Solution

Ignore values from Thing channel when transformation is configured but not available or initialize transformation services earlier or before Things.

Steps to Reproduce (for Bugs)

  1. Add a Modbus data Thing and configure "Read Transform" (e.g. "JS:|input/10" like in screenshot above).
  2. Link item to channel.
  3. Restart openHAB.

Your Environment

lolodomo commented 1 month ago

Looks very similar to openhab/openhab-core#3763

dandjo commented 1 month ago

@lolodomo True, especially 3763#1745267997 comment nails the issue.

openhab-bot commented 1 month ago

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

https://community.openhab.org/t/oh4-transformationservice-of-type-js-is-unavailable/148786/21

dandjo commented 1 month ago

@lolodomo @kaikreuzer Are there any ideas on how to solve this? Is it even possible to influence the order? Is there a dependency management for this?

J-N-K commented 1 month ago

This is not a core issue. The SingleValueTransformation is implemented in the modbus-addon. The core ChannelTransformation$TransformationStep is correctly returning an empty Optional for a missing transformation service. I'll move this to openhab-addons.

maisun commented 1 month ago

Has anybody found a solution to this? It's really bothering at least for modbus add-on (which ususally requires read/write transforms)

dandjo commented 1 month ago

I found a workaround, which is not really satisfying, but solves the issue atm. I created a transformation script of the same type which I am using in the thing transformation (JS:|input in my case). This transformation is added as thing > item transformation in the channel. In my case it is a simple passthrough of the value, but rendered through the transformation. The result is an error when the transformation service is unavailable but without passing the raw value to the item.

image

image