Problem integrating Node-Red to update Item state

So I am trying to use node-red to read my gmail account, parse a status summary message I get every day from my utility company, then ultimately use the openhab2-out filter to send a status update to my item. The ridiculous problem I’m having is that the “payload” field for the openhab2-out filter will literally put whatever text is in the field out into the REST API. I have tried setting msg.payload (in node red) to the desired float value, but I always get a “State could not be parsed” error. The only thing that “works” is if I actually type out the desired value into that field i.e. payload = 3.2 which it will happily accept. What am I missing here? Below is the error output from the console, as well as a screenshot of the “payload” field I’m talking about. Typing an actual number in there will work, but I’d like to be able to specify the variable i.e. ‘foo’ and have the filter know that ‘foo’ is actually 3.2 and send a bloody 3.2!

6 Aug 01:31:10 - [warn] [openhab2-out:updateElectricDaily] response error '{"statusCode":400,"body":"{\"error\":{\"message\":\"State could not be parsed: msg.payload\",\"http-code\":400}}","headers":{"connection":"close","content-type":"application/json","content-encoding":"UTF-8","content-length":"78","server":"Jetty(9.4.20.v20190813)"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":"openhabian:XXXXXXXX","host":"localhost:8080","port":"8080","hostname":"localhost","hash":null,"search":null,"query":null,"pathname":"/rest/items/Utility_Electric_Daily/state","path":"/rest/items/Utility_Electric_Daily/state","href":"http://openhabian:XXXXXXXXX@localhost:8080/rest/items/Utility_Electric_Daily/state"},"method":"PUT","headers":{"authorization":"Basic b3BlbmhhYmlhbjoxNDNjb2xsZWVu","content-length":11}}}' on 'http://openhabian:XXXXXXXX@localhost:8080/rest/items/Utility_Electric_Daily/state'

You have an HTML 400 error
This means you have a bad request

The screenshot of your node red sketch doesn’t give enough information to help you.

Thanks for the reply. Sorry my text was not clear. You are correct it’s a bad request. The reason it’s a bad request is because the REST API is literally sending the string msg.payload instead of the float value that it needs in order to do the update.

D’oh! It’s working now! The fix was to actually leave the “payload” field completely blank. I was trying to be too helpful by filling it in with msg.payload, which was causing the error. I’ll leave the post up here in case it helps someone else. I don’t see many node-red discussions around here.

In short, leave the “payload” field blank!

2 Likes