Maverick83
(Michael Maier)
November 30, 2021, 4:44pm
1
Dear all,
I have some problems on OH3 to configure my rollershutter item via the http-binding.
I have broken it down to a minimal example
Thing definition
UID: http:url:43ff2e7adb
label: HTTP URL Thing
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: http://192.168.1.52/dsfdf
delay: 0
stateMethod: GET
refresh: 3
commandMethod: POST
contentType: text/plain
timeout: 3000
bufferSize: 2048
channels:
- id: rolladen1
channelTypeUID: http:rollershutter
label: rolladen1
description: ""
configuration:
stateExtension: test
commandExtension: test1
stateTransformation: EXEC:/bin/bash /tmp/test.sh
downValue: '{"action":1}'
upValue: '{"action":0}'
external bash script
#!/bin/bash
echo "call" >> /tmp/new
echo "50"
return 50
I can see that the /tmp/new file is updated every 3 seconds as mentioned in the thing definition.
However, the problem is that the Rollershutter item shows “UNDEF”.
Updating the item manually via api works, but it is set back to UNDEF after 3 seconds.
For string items, this works without problems.
What result does the bash script have to deliver to update the Rollershutter item?
Thanks for your help
rossko57
(Rossko57)
November 30, 2021, 5:08pm
2
Not sure what you"re doing here. Trying to make the Item state 50 regardless of actual input? I think you’d have to get rid of the failing up/down parameters that will never match 50.
Maverick83
(Michael Maier)
November 30, 2021, 10:56pm
3
This is just a sample Code That should Show how I can set the item. The real Code is more complex and will dopend on the real Response of the actor
rossko57
(Rossko57)
November 30, 2021, 11:24pm
4
I’d be surprised if you get state UNDEF without some complaint in your logs.
What does the “working” string version look like? (You may add extra channels to the same Thing for testing)
If I recall, a common surprise is scripts appending a newline to results; “50/n” won’t parse as a number, and looks like “50” in a string at first glance.
Wolfgang_S
(Wolfgang_S)
December 1, 2021, 6:34am
5
that ( of course ) depends on the content of the scripts.
While
echo "50"
or
echo 50
will have a “\n” ( newline ) at the end using the switch -n there will be no newline at the end
echo -n 50
Maverick83
(Michael Maier)
December 1, 2021, 7:30am
6
thanks for the hint.
I tested but unfortunately it did not change anything.
I have raised the loglevel
2021-12-01 07:24:27.589 [TRACE] [p.internal.http.HttpResponseListener] - Received from 'http://192.168.1.52/': Code = {200}, Headers = {Server: nginx/1.11.5, Date: Wed, 01 Dec 2021 07:24:27 GMT, Content-Type: application/json, Transfer-Encoding: chunked, Connection: keep-alive, Strict-Transport-Security: max-age=63072000; includeSubDomains; preload, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, X-XSS-Protection: 1; mode=block}, Content = {<json content>}
2021-12-01 07:24:27.593 [DEBUG] [c.internal.ExecTransformationService] - about to transform '<json content>' by the commandline '/bin/bash /tmp/test.sh'
2021-12-01 07:24:30.678 [TRACE] [c.internal.ExecTransformationService] - command line execution elapsed 19 ms
2021-12-01 07:24:30.680 [TRACE] [.thing.internal.CommunicationManager] - Using profile 'system:default' from cache for link 'NewItem -> http:url:43ff2e7adb:rolladen1'
2021-12-01 07:24:30.682 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/items/NewItem/state, source=http:url:43ff2e7adb:rolladen1, type=ItemStateEvent, payload={"type":"UnDef","value":"UNDEF"}, timestamp=1638343470682}
Maverick83
(Michael Maier)
December 1, 2021, 10:02am
7
I debugged a bit more and compared the log with when I update the value via the api
for the item transformation
2021-12-01 09:52:35.331 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/items/NewItem/statechanged, type=ItemStateChangedEvent, payload={"type":"UnDef","value":"UNDEF","oldType":"Percent","oldValue":"30"}, timestamp=1638352355326}
when I execute via API
2021-12-01 09:52:35.326 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/items/NewItem/statechanged, type=ItemStateChangedEvent, payload={"type":"Percent","value":"30","oldType":"UnDef","oldValue":"UNDEF"}, timestamp=1638352355321}
you see that the type property via UI is set to “Percent”, while with the transform service it is set to type UnDef
But how to configure within the transformation service what item type to update?
rossko57
(Rossko57)
December 1, 2021, 10:27am
8
No, you do not try to edit event types.
You want the transformation in your HTTP channel to not yield UNDEF as an update.
Back to -
Is that true?
Make a string channel with NO transformations, and link to a test Item.
Then try a string channel with your exec transformation,link to another test Item.
Maverick83
(Michael Maier)
December 1, 2021, 10:47am
9
as far as I understand your request yes
Here is the updated Thing defintion
UID: http:url:43ff2e7adb
label: HTTP URL Thing
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: http://192.168.1.52
delay: 0
stateMethod: GET
refresh: 30
commandMethod: POST
contentType: text/plain
timeout: 3000
bufferSize: 2048
channels:
- id: rolladen1
channelTypeUID: http:rollershutter
label: rolladen1
description: ""
configuration:
stateExtension: Status
commandExtension: /shutter/1
stateTransformation: EXEC:/bin/bash /tmp/test.sh
downValue: '{"action":1}'
upValue: '{"action":0}'
- id: stringtestchannel1
channelTypeUID: http:string
label: stringtestchannel1
description: ""
configuration:
stateExtension: Status
commandExtension: /shutter/1
- id: StringChannel2
channelTypeUID: http:string
label: StringChannel2
description: ""
configuration:
stateExtension: device
stateTransformation: EXEC:/bin/bash /tmp/test.sh
commandExtension: /shutter/1
The string item bound to stringtestchannel1 shows the plain json request from the actor, the string item bound to StringChannel2 is set to 50
2021-12-01 10:44:36.399 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/items/NewStringitem2/state, source=http:url:43ff2e7adb:StringChannel2, type=ItemStateEvent, payload={"type":"String","value":"50"}, timestamp=1638355476398}
and
2021-12-01 10:37:39.822 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Newstringitem1' changed from NULL to [<json>]
rossko57
(Rossko57)
December 1, 2021, 10:56am
10
That’s encouraging. I still worry about invisible control characters.
Try
rule "check chars"
when
Item Newstringitem1 received update
then
logInfo("test", "Raw state " + Newstringitem1.state.toString)
logInfo("test", "Char count " + Newstringitem1.state.toString.length)
end
Also, in case these mini-transforms like downValue: '{"action":1}'
are involved in messing up, you might try a plain number channel linked to a Number Item, where your transform output string should get parsed to numeric too.
Maverick83
(Michael Maier)
December 1, 2021, 12:16pm
11
There is a new line obviously at the end of the json but why should it matter
021-12-01 12:15:26.745 [INFO ] [org.openhab.core.model.script.test ] - Raw state {"test":"test"}
2021-12-01 12:15:26.746 [TRACE] [internal.events.ThreadedEventHandler] - wait for event
2021-12-01 12:15:26.748 [DEBUG] [.monitor.internal.metrics.RuleMetric] - Rule test-1 RUNNING - updating metric.
2021-12-01 12:15:26.751 [INFO ] [org.openhab.core.model.script.test ] - Char count 16
2021-12-01 12:15:26.752 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule 'test-1' is executed.
Maverick83
(Michael Maier)
December 1, 2021, 12:20pm
12
Changed the response to a plain json
No changes
2021-12-01 12:18:26.766 [INFO ] [org.openhab.core.model.script.test ] - Raw state {"test":"test"}
2021-12-01 12:18:26.766 [TRACE] [automation.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2021-12-01 12:18:26.768 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.rest.sse.internal.listeners.SseEventSubscriber).
2021-12-01 12:18:26.769 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.monitor.internal.EventLogger).
2021-12-01 12:18:26.769 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.monitor.internal.metrics.RuleMetric).
2021-12-01 12:18:26.770 [DEBUG] [.monitor.internal.metrics.RuleMetric] - Rule test-1 RUNNING - updating metric.
2021-12-01 12:18:26.770 [TRACE] [.openhab.core.io.rest.SseBroadcaster] - broadcast to potential 1 sinks
2021-12-01 12:18:26.771 [TRACE] [internal.events.ThreadedEventHandler] - wait for event
2021-12-01 12:18:26.773 [INFO ] [org.openhab.core.model.script.test ] - Char count 15
rossko57
(Rossko57)
December 1, 2021, 12:55pm
13
What we were interested in was the character count of the “50” returned from your transformation. I don’t know which of your test Items is what.
What you’d want to see is “50” count 2, which can parsed into a numeric value by the channel, not “[nul]50” count 3 or 4, which cannot be parsed but looks like “50”.
Maverick83
(Michael Maier)
December 1, 2021, 1:03pm
14
A that makes sense
2021-12-01 13:01:57.074 [INFO ] [org.openhab.core.model.script.test ] - Raw state 50
2021-12-01 13:01:57.076 [INFO ] [org.openhab.core.model.script.test ] - Char count 2
rossko57
(Rossko57)
December 1, 2021, 1:09pm
15
Maverick83:
Char count 2
Excellent, now we can be confident your exec transformation is returning a simple string.
Looks like rollershutter type channel has a bug - I’m still suspicious those up/downValue mini-transforms are involved, they are supposed to pass numerics through … but.
Once again, try a simple number type channel and Item to see if you can pass 50.
Should that work … maybe it’s the 50 that is the problem. Rollershutter state is not strictly a number, it is a percent type. This binding might be treating that as a ratio or fraction, and you could try having the transformation return “0.5”.
Maverick83
(Michael Maier)
December 1, 2021, 2:13pm
16
I have removed the up/down mini-transformations
I have added a number type channel and number type item. This works.
I have tested
50
0.5
“0.5”
0,5
“0,5”
but no luck for the Rollershutter Item.
rossko57
(Rossko57)
December 1, 2021, 2:17pm
17
Reckon the inbound state is not implemented fully on the rollershutter channel type then.
Log an issue for it on Github.
As an interim, you could try a dimmer type channel, which also deal in percent states and should be able to force a link to a Rollershutter Item.
1 Like
J-N-K
(Jan N. Klug)
December 1, 2021, 4:03pm
19
It’s not a missing but a faulty implementation.
1 Like
Maverick83
(Michael Maier)
December 1, 2021, 8:27pm
20
Thanks for all your support. I hope my GitHub issue is sufficient.