How to use the API EXPLORER to change a thing configuration

  • Platform information:
    • Hardware: intel laptop
    • OS: windows 10
    • Java Runtime Environment: 11
    • openHAB version: 3.4.2
  • Issue of the topic:

I have been trying to use the API EXPLORER for a few days to change the configuration of a thing without success.

Let’s say I have a thing with this configuration

UID: modbus:serial:d27deb0c81
label: Light temperature humidity sensor
thingTypeUID: modbus:serial
configuration:
  baud: 4800
  connectMaxTries: 1
  timeBetweenTransactionsMillis: 35
  stopBits: "1.0"
  parity: none
  receiveTimeoutMillis: 1500
  dataBits: 8
  echo: false
  encoding: rtu
  flowControlIn: none
  flowControlOut: none
  port: COM4
  connectTimeoutMillis: 10000
  afterConnectionDelayMillis: 0
  id: 1
  enableDiscovery: false

and I want to change the port to COM5

What do I have to enter in the EXPLORER
PUT /things/{thinguid}/config request body section to do that?

I have tried
{port: COM5}
{“port”:COM5}
{“port”:“COM5”}

and I get an HTTP response 500 and the openhab log shows

2023-04-03 14:18:26.538 [ERROR] [rg.apache.cxf.jaxrs.utils.JAXRSUtils] - No message body writer has been found for class java.util.Collections$UnmodifiableMap, ContentType: */*

I know the com port can be changed from the UI

I asked a similar question for a zwave lock user codes a couple of weeks back and Bob Eckhoff has been helping me but I just don’t understand why the API explorer does not work to change the configuration of any Thing.

Thank you

How does the current thing look like when you request it via the API explorer ( GET /things/{thingUID} ) ?
Does it work to use that returned configuration, modify it and send it back ?

This is the response when I paste the reply from the /thing/thingUID/ GET command into the PUT thing/thingUID/config command

{
  "error": {
    "message": "Invalid type '{com.google.gson.internal.LinkedTreeMap}' of configuration value!",
    "http-code": 500
  }
}

Here is the log

07:06:19.234 [ERROR] [est.core.internal.thing.ThingResource] - Exception during HTTP PUT request for update config at 'things/modbus:serial:d27deb0c81/config'

If I PUT the modified configuration into /thing/thingUID/ instead of /thing/thingUID/config then it works with no problem

Thanks

Worked example (changing the DMX channel of a DMX Color Thing from 1/123 to 1/321):

openhabian@openhabian:~ $ curl -X 'GET'   'http://192.168.1.181:8080/rest/things/dmx%3Acolor%3Ae984c6fa47%3A5b4ccdb016'   -H 'accept: application/json' -H @headers_api.txt                                                                  {"channels":[{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_r","id":"brightness_r","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_g","id":"brightness_g","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_b","id":"brightness_b","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:color","id":"color","channelTypeUID":"dmx:color","itemType":"Color","kind":"STATE","label":"Color","description":"Allows to send a color value to the thing. If the thing is associated with more than one DMX channel, color will be re-use in 3-channel groups.","defaultTags":["Control","Light"],"properties":{},"configuration":{}}],"statusInfo":{"status":"UNINITIALIZED","statusDetail":"BRIDGE_UNINITIALIZED"},"editable":true,"label":"DMX Color (RGB) Dimmer","bridgeUID":"dmx:artnet-bridge:e984c6fa47","configuration":{"dmxid":"1/123"},"properties":{},"UID":"dmx:color:e984c6fa47:5b4ccdb016","thingTypeUID":"dmx:color"}openhabian@openhabian:~ $
openhabian@openhabian:~ $ curl -X 'PUT' 'http://192.168.1.181:8080/rest/things/dmx%3Acolor%3Ae984c6fa47%3A5b4ccdb016' -H 'accept: */*' -H 'Content-Type: application/json' -H @headers_api.txt -d '{ "configuration": { "dmxid": "1/321" } }'
{"channels":[{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_r","id":"brightness_r","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_g","id":"brightness_g","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_b","id":"brightness_b","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:color","id":"color","channelTypeUID":"dmx:color","itemType":"Color","kind":"STATE","label":"Color","description":"Allows to send a color value to the thing. If the thing is associated with more than one DMX channel, color will be re-use in 3-channel groups.","defaultTags":["Control","Light"],"properties":{},"configuration":{}}],"statusInfo":{"status":"UNINITIALIZED","statusDetail":"BRIDGE_UNINITIALIZED"},"editable":true,"label":"DMX Color (RGB) Dimmer","bridgeUID":"dmx:artnet-bridge:e984c6fa47","configuration":{"dmxid":"1/321"},"properties":{},"UID":"dmx:color:e984c6fa47:5b4ccdb016","thingTypeUID":"dmx:color"}openhabian@openhabian:~ $
openhabian@openhabian:~ $ curl -X 'GET'   'http://192.168.1.181:8080/rest/things/dmx%3Acolor%3Ae984c6fa47%3A5b4ccdb016'   -H 'accept: application/json' -H @headers_api.txt                                                                  {"channels":[{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_r","id":"brightness_r","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_g","id":"brightness_g","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:brightness_b","id":"brightness_b","channelTypeUID":"dmx:brightness","itemType":"Dimmer","kind":"STATE","label":"Brightness","description":"Allows to send a brightness value to the thing. If the thing is associated with more than one DMX channel, the values is used for ALL DMX channels.","defaultTags":["Control","Light"],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"dmx:color:e984c6fa47:5b4ccdb016:color","id":"color","channelTypeUID":"dmx:color","itemType":"Color","kind":"STATE","label":"Color","description":"Allows to send a color value to the thing. If the thing is associated with more than one DMX channel, color will be re-use in 3-channel groups.","defaultTags":["Control","Light"],"properties":{},"configuration":{}}],"statusInfo":{"status":"UNINITIALIZED","statusDetail":"BRIDGE_UNINITIALIZED"},"editable":true,"label":"DMX Color (RGB) Dimmer","bridgeUID":"dmx:artnet-bridge:e984c6fa47","configuration":{"dmxid":"1/321"},"properties":{},"UID":"dmx:color:e984c6fa47:5b4ccdb016","thingTypeUID":"dmx:color"}openhabian@openhabian:~ $

Sure, this doesn’t tackle your problem with PUT thing/thingUID/config, but you should be able to use the worked example to get your job done.

I’ll try it. I think at some point I did try PUT into the things/thingUID and it replaced the whole configuration with what I had in the PUT statement, but maybe I had the wrong structure.

I see that -H @file inserts all the headers that are in the file. what goes in this file?, everything you have after the @headers_api.txt in your example?

Thank you

openhabian@openhabian:~ $ cat headers_api.txt
Authorization: Bearer oh.DMXTest.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

If you use the API Explorer from the openHAB GUI, you can safely ignore it.

Further reading: openHAB API tokens | openHAB

Not quite working in my case.

In the example I posted in my OP I tried changing the time between transactions as follows using the API explorer

{“configuration”:{" timeBetweenTransactionsMillis": 50} }

It did change the timebetweentransaction parameter but it erased the com port.

When I tried adding the com port as

{“configuration”:{“port”:“COM4”, " timeBetweenTransactionsMillis": 50} }
it deleted all the parameters except the post and the time between transactions.

I also tested changing a parameter in openweathermap account thing and again it changed the parameter I wanted to change but it deleted the api key

Thanks for your suggestion.

Steps to update a thing via API-explorer which are working here:

  • Get the thing via GET on http://openhabhost:port/rest/things/
  • Copy the JSON-object
  • Go to the PUT on http://openhabhost:port/rest/things/
    • paste the json-object in the the window for pushing data
    • adjust the object(take into account the datatype)
  • Perform PUT with the json-object

If you use the /config endpoint for updating configuration, only use the data from “configuration”, so the data in brackets looks like this:

{
  "additionalProp1": {},
  "additionalProp2": {},
  "additionalProp3": {}
}

Please use the complete data for config, there seems to be little error-checking on the correctness of data. Text or strings are quoted and keys of the data (ie additionalProp1) are always in quotes, your error seems to indicate there’s an error in the data you send, you can use a json-linter to check if data adheres to standards.

Hope this helps.

Yes that helped, use /rest/thing/thingUID/config and send the whole configuration and nothing but the configuration in the format shown.

I had read in a thread that only the parameter to be changed could be sent but evidently that is not true or at least is not universally true

Thank you

1 Like