[SOLVED] MQTTv2 Can't get incoming mqtt message transformed to readable value

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

Hello, I’ve been trying to transform an incomming MQTT message to an openhab readable form but cant seem to get it right.

The payload of the message is : {“state”:“OFF”} or {“state”:“ON”}

I tried with MAP transformation like this:

milight_mqqt.map:

{"state":"OFF"}=0
{"state":"ON"}=100

or

{"state":"OFF"}=off
{"state":"ON"}=on

mqtt.things:

Type string : as_formated_text "as formated text" [ stateTopic="milight/updates/0x611E/rgb_cct/0:state:[MAP(milight_mqtt.map):%s]" ]
      Type switch : as_switch "as switch" [ stateTopic="milight/updates/0x611E/rgb_cct/0:state:[MAP(milight_mqtt.map):%d]" ]
      Type number : as_number "as number" [ stateTopic="milight/updates/0x611E/rgb_cct/0:state:[MAP(milight_mqtt.map):%d]" ]

I read this could be done with JSONPATH transformation but i cant find the right syntax.

Both transformation serveces are installed.

Can someone nudge me in the right direction? Thanks

Type switch : as_switch "as switch" [ stateTopic="milight/updates/0x611E/rgb_cct/0", transformationPattern="JSONPATH:$.state" ]

As per the docs: https://www.openhab.org/addons/bindings/mqtt.generic/#common-channel-configuration-parameters and https://www.openhab.org/addons/bindings/mqtt.generic/#incoming-value-transformation

1 Like

wow that simple, now i feel deeply ashamed for my stupid question :flushed:.
I was trying things like JSONPATH:"{“state”}":"{"$"}", even though i has read the docs you refered to. Now with your example i can better understand the docs (I dont know anything about json)

Thanks a bunch

Have I seen this?

Yes i have, been using it for a while now (fantastic hub and fantastic binding). But i needed a fix for Group 0 not beeing distributed to Group 1-4 when Group 0 on/off whas pressed on a physical remote (hub doesn’t keep state for group 0 so lights went off but in OH individual groups remained on). I use the items above to detect a Group 0 on/off button press on physical remote to send this command to Group 1-4 via a rule. This way my OH allso remains in sync when group0 on/off is used. I have heard the 1,9,0 firmware of the hub might resolve this issue. But for now this workaround works great. Anyways thanks for the hint

In around 20 minutes I added and tested the extra support to the binding which I have just uploaded.
Both ON/OFF and Brightness are updating the globes in Openhab when it receives group 0.

Thanks for suggesting this, no one has pointed this out before.

Wow thanks alot. This really makes it complete :grin:. So do i just uninstall the current binding and then install the updated version from github?

you will need to remove the old binding and drop the new jar in the addons folder. They have different file names so please do not put both in the folder at the same time. Any issues just clean tmp and cache folders and reboot…

In linux…

sudo service openhab2 stop && sudo rm -rf /var/lib/openhab2/cache/* && sudo rm -rf /var/lib/openhab2/tmp/* && sudo reboot

OK :ok_hand:, thanks a bunch. I will be doing this tonight :+1:

I just updated to the latest dev firmware and it is more than just on and off and level, colour and all the rest is working. A state ON does send the control to 100% as it is missing the LEVEL in the state. Saturation also seems to have a bug in the firmware for group 0.

1 Like

Just uploaded v9.0.0 fw and installed new binding. Commented out my rules for group0 and now the binding handles group0 on/off for me. Now OH stays in sync when controlling group0 on physical remote. Dont really mind about level or saturation as on/off was most important to me. Thanks