hafniumzinc:
State Description
Via the UI, the following options are available:
To populate these fields via configuration files (example values):
Number nTest "Test Number Item" {
stateDescription=""[
pattern="%d%%",
min="0",
max="100",
step="1",
options="1=Red, 2=Green, 3=Blue"
]
}
Thanks!
UPDATED: However… it does not work on openHAB 3.0.2. The language parser chokes on this format of stateDescription
metadata. Maybe it’s the empty double quote portion that is the culprit, as also mentioned in:
Setup, Configuration and Use
Migration
Dear all, during migrating from OH2.5 to OH3 I had some issues to maintain the patterns via “Add items via textual definition”. After longer searching and playing and shouting and playing again, I found a solution, I’d like to share. Maybe it is...
Reading time: 1 mins 🕑
Likes: 3 ❤
More precisely:
The trick is, to add the pattern as metadata in the textual definition. E.g. , stateDescription=" "[ pattern="%1$tR" ]
(Make sure you have a space or some other text in stateDescription=" " / Empty does not work)
(The example successfully assigns and properly configures the custom temperature_list
widget for list items, but skips the offending stateDescription
metadata definition block.)
It however works when adding a single space between the pair of double quotes.
Bug report:
opened 10:50AM - 22 Jun 21 UTC
bug
main ui
## The problem
Although it is possible to define Items from their textual def… inition (openHAB2 .items files), there is an issue when adding the `stateDescription` metadata entry. This has been reported to be working, see e.g.:
https://community.openhab.org/t/oh3-add-metadata-to-items-via-configuration-files/112843
An example `Item` definition that partially succeeds:
```text
Number:Length OneCallAPIweatherandforecast_ForecastToday_Rain "Today's rain" <rain> (gWeatherForecast_Today)
["Rain", "Today", "Forecast", "Point_Measurement", "Property_Rain"] {
channel="openweathermap:onecall:4afe5c0d:local:forecastToday#rain",
stateDescription=""[
readOnly="true",
pattern="%.2f mm"
],
listWidget="rain_amount_list"[
show_badge="true",
show_group_members="false"
]
}
```
In this example, I'm using a custom list widget. The same error occurs when only assigning the `stateDescription` metadata.
The UI shows the following error:
> An error occurred while creating the links and metadata: Server Error
The Item is created (albeit without the offending metadata, i.e., without the `stateDescription` metadata).
The openHAB logs show:
```text
==> /var/log/openhab/events.log <==
2021-06-22 12:17:38.145 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'OneCallAPIweatherandforecast_ForecastToday_Rain' changed from NULL to 4.46 mm
==> /var/log/openhab/openhab.log <==
2021-06-22 12:17:38.144 [ERROR] [internal.JSONResponseExceptionMapper] - Unexpected exception occurred while processing REST request.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 11 path $.value
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224) ~[?:?]
at com.google.gson.Gson.fromJson(Gson.java:888) ~[?:?]
at com.google.gson.Gson.fromJson(Gson.java:826) ~[?:?]
at org.openhab.core.io.rest.core.internal.GsonMessageBodyReader.readFrom(GsonMessageBodyReader.java:58) ~[?:?]
at org.openhab.core.io.rest.core.internal.MediaTypeExtension.readFrom(MediaTypeExtension.java:103) ~[?:?]
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1409) ~[bundleFile:1.0.9]
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1361) ~[bundleFile:1.0.9]
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processRequestBodyParameter(JAXRSUtils.java:877) ~[bundleFile:1.0.9]
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:822) [bundleFile:1.0.9]
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:214) [bundleFile:1.0.9]
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78) [bundleFile:1.0.9]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [bundleFile:1.0.9]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [bundleFile:1.0.9]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301) [bundleFile:1.0.9]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:237) [bundleFile:1.0.9]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) [bundleFile:3.1.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276) [bundleFile:1.0.9]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) [bundleFile:9.4.20.v20190813]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [bundleFile:?]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) [bundleFile:9.4.20.v20190813]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [bundleFile:?]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [bundleFile:9.4.20.v20190813]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [bundleFile:?]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.Server.handle(Server.java:494) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813]
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813]
at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 11 path $.value
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:825) ~[?:?]
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:401) ~[?:?]
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:389) ~[?:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) ~[?:?]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) ~[?:?]
... 54 more
```
## Expected behavior
The Item should have been created without problems, with all metadata definitions provided.
## Steps to reproduce
See example provided.
I suspect that the language parser has a problem when it encounters an empty string after the metadata name, as in `stateDescription=""[...`
## Your environment
Platform information: Raspbian Buster on Raspberry Pi 3B+
```yaml
runtimeInfo:
version: 3.0.2
buildString: Release Build
locale: en-BE
systemInfo:
configFolder: /etc/openhab
userdataFolder: /var/lib/openhab
logFolder: /var/log/openhab
javaVersion: 11.0.11
javaVendor: Azul Systems, Inc.
javaVendorVersion: Zulu11.48+21-CA
osName: Linux
osVersion: 5.10.17-v7+
osArchitecture: arm
availableProcessors: 4
freeMemory: 46704992
totalMemory: 247332864
bindings:
- astro
- buienradar
- exec
- gpstracker
- openweathermap
- sonos
- telegram
- tradfri
- zwave
clientInfo:
device:
ios: false
android: false
androidChrome: false
desktop: true
iphone: false
ipod: false
ipad: false
edge: false
ie: false
firefox: false
macos: true
windows: false
cordova: false
phonegap: false
electron: false
nwjs: false
webView: false
webview: false
standalone: false
os: macos
pixelRatio: 2
prefersColorScheme: dark
isSecureContext: false
locationbarVisible: true
menubarVisible: true
navigator:
cookieEnabled: true
deviceMemory: N/A
hardwareConcurrency: N/A
language: en-gb
languages:
- en-gb
onLine: true
platform: MacIntel
screen:
width: 3360
height: 1890
colorDepth: 24
support:
touch: false
pointerEvents: true
observer: true
passiveListener: true
gestures: false
intersectionObserver: true
themeOptions:
dark: dark
filled: true
pageTransitionAnimation: default
bars: light
homeNavbar: default
homeBackground: default
expandableCardAnimation: default
userAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
timestamp: 2021-06-22T10:28:28.042Z
```
## Browser console
JavaScript Console in Safari:
```txt
[Debug] PUT /rest/links/OneCallAPIweatherandforecast_ForecastToday_Rain/openweathermap%3Aonecall%3A4afe5c0d%3Alocal%3AforecastToday%23rain: {"itemName":"OneCallAPIweatherandforecast_ForecastToday_Rain","channelUID":"openweathermap:onecall:4afe5c0d:local:forecastToday#rain","configuration":{}} (app.js, line 32)
[Debug] PUT /rest/items/OneCallAPIweatherandforecast_ForecastToday_Rain/metadata/stateDescription{"value":{"value":"","config":[{"key":"readOnly","value":"true"},{"key":"pattern","value":"%.2f mm"}]},"config":{"readOnly":"true","pattern":"%.2f mm"}} (app.js, line 32)
[Debug] PUT /rest/items/OneCallAPIweatherandforecast_ForecastToday_Rain/metadata/listWidget{"value":"rain_amount_list","config":{"show_badge":"true","show_group_members":"false"}} (app.js, line 32)
[Error] Failed to load resource: the server responded with a status of 500 (Server Error) (stateDescription, line 0)
[Error] Server Error
(anonymous function) (app.js:32:233850)
promiseReactionJob
```
## Browser network traffic
## Additional information
See also:
https://community.openhab.org/t/oh3-add-metadata-to-items-via-configuration-files/112843/29?u=shutterfreak
2 Likes