Fail to get NodeRED to work

Hello.
I need some help to get nodered with openhab2 up and running

I have a very basic flow:
Bigtimer -> Openhab OUT

When the event is triggered i get the following error:

"response error '{"statusCode":400,"body":"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 400 Bad Request</title>\n</head>\n<body><h2>HTTP ERROR 400</h2>\n<p>Problem accessing /rest/items/gXmasLights. Reason:\n<pre>    Bad Request</pre></p><hr><a href=\"http://eclipse.org/jetty\">Powered by Jetty:// 9.4.20.v20190813</a><hr/>\n\n</body>\n</html>\n","headers":{"connection":"close","cache-control":"must-revalidate,no-cache,no-store","content-type":"text/html;charset=iso-8859-1","content-length":"343","server":"Jetty(9.4.20.v20190813)"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"localhost:8080","port":"8080","hostname":"localhost","hash":null,"search":null,"query":null,"pathname":"/rest/items/gXmasLights","path":"/rest/items/gXmasLights","href":"http://localhost:8080/rest/items/gXmasLights"},"method":"POST","headers":{"content-length":1}}}' on 'http://localhost:8080/rest/items/gXmasLights'"

sind a GET to this URL (http://localhost:8080/rest/items/gXmasLights) gives me the correct item. A POST the error message you ca see in the codeblock.
Any idea, what i have configured wrong?

Here the openhab2-out item (which imho causes the trouble):

and the openhab2 connection itself:
grafik

and the bigtimer node:

nothing magincal in my opinion :smile:

Thanks
Dakky

HTTP 400 is “Bad Request” which means OH thinks there is a client ( NodeRed) error in the requiest.

Shouldn’t the content be ON resp. OFF instead of on resp. off ?

@Bruce_Osborne
yep, or a bad requests dropps also, when POSTing with an empty body against the rest endpoint.
Problem is: I don’t know where to continue to debug

@Wolfgang_S
after your suggestion i tried changing the ON/OFF Text in the bigTimer node. Same error as before.

If it is a bad request, it is a Node-RED issue. Perhaps their forums would have suggestions.

Can you run a network sniffer so that we can check the exact content of the request that is being sent to the REST API ?
The request that is being described in the error message does not show the content-type of the request which needs to be text/plain.

Perhaps putting the REST APi into DEBUG or TRACE log mode would help to see, at least, when OH thinks it receives.

@Wolfgang_S that’s what i found with sniffing around with tcpdump:

POST /rest/items/gXmasLights HTTP/1.1
host: localhost:8080
content-length: 1
Connection: close

1

I assume since the Item starts with g it is a Group. Is the Group specified as a type of Switch? There are a couple of variants documented in the official documentation for this.

yes it’s an group item.

definition:
Group:Switch gXmasLights "Weihnachtsbeleuchtung" {alexa="Lighting"}

I also found something in the logs:

2020-12-20 17:36:20.979 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/gXmasLights' with an invalid status value '1'.
2020-12-20 17:37:21.057 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/gXmasLights' with an invalid status value '1'.

That does not agree with either example in the documentation

Received HTTP POST request at ‘items/gXmasLights’ with an invalid status value ‘1’.

That error is correct As documented, switches usually receive ON or OFF commands…

Erm what exactly does not agree?

Group[:itemtype[:function]] groupname ["labeltext"] [<iconname>] [(group1, group2, ...)]

seems okay imho? The group itself works fine via ui and alexa.

BUT your very first assumption was correct: it was an issue on the rednode side.
So in case someone stumbles over the same problem:

It was a simple error: ON msg (which text box is described as “mqtt msg” does NOT refer to mqtt only, but to every output. ON text is just a simple ui text message in node red and has nothing to do with the actual nessage send to openhab.

long story short: write ON and OFF in the mqqt payload field and everything is fine.

the “1” send as payload was a debugging error on my side

There are 2 examples in the doc.

Group:Switch:OR(ON,OFF)  			Lights       	"Active Lights [%d]"              // e.g. ON and "2"

and

Group:Switch:AND(ON,OFF) 			Lights       	"Active Lights [%d]"              // e.g. ON and "2"

Your definition is neither.

these are examples :wink:

Group[:itemtype[:function]] groupname ["labeltext"] [<iconname>] [(group1, group2, ...)]

is copied from the official doc: https://www.openhab.org/docs/configuration/items.html#groups
Square brackets means OPTIONAL

my snipplet:

 Group:Switch gXmasLights "Weihnachtsbeleuchtung" {alexa="Lighting"}
   1     2        3                 4                      5
  1. Group keyword. non optional
  2. itemtype. optional, in my case: Switch
  3. groupname. non optional
  4. label optional
  5. binding configuration, can be attached to EVERY thing see https://www.openhab.org/docs/configuration/items.html#binding-configuration

function and iconname are both optional and not used

For switch specifically, they specified 2 options, mainly controlling the status of the Group.