HTTP Binding a Shelly Plus (GetConfig/SetConfig)

Hi

I’m trying to use the HTTP-Binding to modify the Config of a Shelly Plus Plug S

So far I have only managed to get the config, but every attempt to write it seems to disappear into nothingness.

Shelly background:
GET: http://192.168.66.64/rpc/PLUGS_UI.GetConfig
This returns a JSON-String
SET: http://192.168.66.64/rpc/PLUGS_UI.SetConfig?config={%22leds%22:%20{%22colors%22:%20{%22switch:0%22:%20{%22off%22:%20{%22brightness%22:%200.0}}}}}
This sets the Brightness to 0 when the Plug is “off” and both URLs can be called using a browser.

JSON-Path for GET is JSONPATH:$.leds.colors.switch:0.off.brightness and works well.

This is my HTTP-Thing

UID: http:url:412d83813f
label: HTTP 192.168.66.64
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://192.168.66.64/rpc/
  delay: 0
  stateMethod: GET
  refresh: 30
  commandMethod: GET
  contentType: application/json
  timeout: 3000
  bufferSize: 2048
channels:
  - id: PLUGS_UI_GetConfig
    channelTypeUID: http:string
    label: PLUGS_UI.GetConfig
    description: ""
    configuration:
      stateExtension: PLUGS_UI.GetConfig
      commandExtension: PLUGS_UI.SetConfig?config=
  - id: PLUGS_UI_GetConfig_OFF_Brrightness
    channelTypeUID: http:number
    label: PLUGS_UI.GetConfig Off Brightness
    description: ""
    configuration:
      commandTransformation: JSONPATH:$.leds.colors.switch:0.off.brightness
      stateExtension: PLUGS_UI.GetConfig
      stateTransformation: JSONPATH:$.leds.colors.switch:0.off.brightness
      commandExtension: PLUGS_UI.SetConfig?config=

The first channel is linked to a String-Item and gives the full JSON.
The second channel is linked to a Number-Item and gives the value (as set using the WebGUI or the call above).

However when I try to set the value using the rule

events.postUpdate('HTTP_1921686664_PLUGS_UIGetConfig_Off_Brightness', 100);

All I get is a log entry
19:06:36.861 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HTTP_1921686664_PLUGS_UIGetConfig_Off_Brightness' changed from 0.0 to 100
and a few seconds later (refresh time)
19:06:44.877 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HTTP_1921686664_PLUGS_UIGetConfig_Off_Brightness' changed from 100 to 0.0
but as far as I can tell there is never a call to SetConfig made.

For debugging I tried pointing baseURL to my Webserver and view the logs, but only calls to GetConfig are logged. SetConfig is never accessed which leads me to think that there is something wrong in my Binding.

I really hope someone can point me in the right direction to use these Shelly-RPCs as changing the light on/off should have been just the beginning and not a dead end.

Thanks in advance for your patience and help.

Ingo

Hi,
I did a similar thing by setting the configuration to a Shelly Plus 1PM, so I think the same could work for you too.

First of all, you configured the SetConfig to a command extension so in your rule you have to call sendCommand instead of postUpdate.

Then I would try to remove the commandTransformation and change the commandExtension to something like this:

configuration:
  commandTransformation: JSONPATH:$.leds.colors.switch:0.off.brightness
  stateExtension: PLUGS_UI.GetConfig
  commandExtension: PLUGS_UI.SetConfig?config={"leds":{"colors":{"switch:0":{"off":{"brightness":%2$s}}}}
1 Like

That’s it!

Just how did you come to your solution.

For future searches I will post the finished Thing, Item and Script here:

UID: http:url:412d83813f
label: HTTP 192.168.66.64
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://192.168.66.64/rpc/
  delay: 0
  stateMethod: GET
  refresh: 10
  commandMethod: GET
  contentType: application/json
  timeout: 3000
  bufferSize: 2048
channels:
  - id: PLUGS_UI_GetConfig
    channelTypeUID: http:string
    label: PLUGS_UI.GetConfig
    description: ""
    configuration:
      stateExtension: PLUGS_UI.GetConfig
      commandExtension: PLUGS_UI.SetConfig?config=
  - id: PLUGS_UI_GetConfig_OFF_Brrightness
    channelTypeUID: http:number
    label: PLUGS_UI.GetConfig Off Brightness
    description: ""
    configuration:
      stateExtension: PLUGS_UI.GetConfig
      stateTransformation: JSONPATH:$.leds.colors.switch:0.off.brightness
      commandExtension: PLUGS_UI.SetConfig?config={"leds":{"colors":{"switch:0":{"off":{"brightness":%2$s}}}}

events.sendCommand('HTTP_1921686664_PLUGS_UIGetConfig_Off_Brightness', 0);

Now my work to use the Shelly Plus Plug S as indicators can begin.

Thank you very much @djal

I checked the shelly api docs and according to this example, I found out the whole request URL and then just stripped the JSON parts you don’t need for this particular channel.