HTTP Binding - stateTransformation for switch item

Hello all,

I have a problem using the http binding in conjunction with a switch item.

things file:

Thing http:url:goveeH6072 "govee H6072 Lyra" [ baseURL="http://127.0.0.1:3666?device=ArbeitszimmerLED", ignoreSSLErrors=true, refresh=10] {
	Channels:
		Type switch : StatusSwitch		"govee H6072 Lyra StatusSwitch"	[stateTransformation="JSONPATH:$.response.data.onOff∩MAP:govee_status_onOff.map", stateExtension="&action=devStatus", onValue="on", offValue="off", commandExtension="&action=%2$s", mode="READWRITE"]
		Type string : StatusString		"govee H6072 Lyra Status"		[stateTransformation="JSONPATH:$.response.data.onOff∩MAP:govee_status_onOff.map", stateExtension="&action=devStatus", mode="READWRITE"]
}

items file:

Switch goveetest {channel="http:url:goveeH6072:StatusSwitch"}
String goveeStest {channel="http:url:goveeH6072:StatusString"}

map file:

1=ON
0=OFF

The funny thing now is that the string item “goveeStest” is always updated, but the actual switch item “goveetest” is not.
I can change the on/off state by switch and it is switched (the real light goes on/off), but the state of the switch item “goveetest” goes to UNDEF afterwards. The string item “goveeStest” changes the status correctly.

This is how it looks in the log:

2023-05-22 16:40:15.230 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'goveetest' received command ON
2023-05-22 16:40:15.231 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'goveetest' predicted to become ON
2023-05-22 16:40:15.232 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'goveetest' changed from UNDEF to ON
2023-05-22 16:40:22.761 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'goveeStest' changed from OFF to ON
2023-05-22 16:40:22.761 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'goveetest' changed from ON to UNDEF

I have already set the http binding, the map and json transformation to DEBUG and there the status is also reflected correctly.

I’m not getting anywhere here and hope for your help :frowning:

raw response of the http call:

{"request": "devStatus ArbeitszimmerLED ", "response": {"cmd": "devStatus", "data": {"brightness": 100, "color": {"b": 255, "g": 255, "r": 255}, "colorTemInKelvin": 2600, "onOff": 1}}}

Because of the MAP transform not only are these unnecessary, they are incorrect. Case matters.

onValue="ON"

Hello Rich,

thanks a lot for your help.
You are absolutely right, with the following thing and map file configuration it works:

Thing http:url:goveeH6072 "govee H6072 Lyra" [ baseURL="http://127.0.0.1:3666?device=ArbeitszimmerLED", ignoreSSLErrors=true, refresh=10] {
	Channels:
		Type switch : StatusSwitch		"govee H6072 Lyra StatusSwitch"	[stateTransformation="JSONPATH:$.response.data.onOff∩MAP:govee_status_onOff.map", stateExtension="&action=devStatus", commandTransformation="MAP:govee_status_onOff.map", onValue="ON", offValue="OFF", commandExtension="&action=%2$s", mode="READWRITE"]
		Type string : StatusString		"govee H6072 Lyra Status"		[stateTransformation="JSONPATH:$.response.data.onOff∩MAP:govee_status_onOff.map", stateExtension="&action=devStatus", mode="READWRITE"]
}
1=ON
0=OFF
ON=on
OFF=off

However, I don’t understand then what the onValue and offValue definition is for? I thought I understood the documentation, but apparently not… :joy:

It’s a built in replacement for the Map transform. If you dropped the Map and put 1 for onValue and 0 for offValue it will automatically map those numbers to ON and OFF as needed.

Note, these are optional parameters. If you want to use the Map transform instead that’s fine, but then don’t include the onValue and offValue parameters on the Channel config.

I think you are wrong here, at least the documentation says otherwise:

There it says that the on/offValue are NOT optional!
And here my confusion comes… :crazy_face:

OK, in that case, instead of either or, you have one choice. Don’t use the Map transform at all. Put 1 for the onValue and 0 for the offValue.