Switch Elements triggering MQTT command (need help)

Hi,
i’m on 4.2 M2 and just tried to create an item that is linked to a sitemap button(s) that by selection does trigger an mqtt command. tried several ways but seems to simply not trigger looking at the mqtt explorer setup.

Here is what i’ve got:

thing file:
Type number : dtu5_setlimit "HM.ng5wall SetLimit [%d W]" [ commandTopic="/opendtu/dtu5/116xxxxxx78/cmd/limit_nonpersistent_absolute" ]

items file:
Switch dtu5_setlimit "HM.ng5wall SetLimit []" <settings> { channel="mqtt:topic:mosquitto:opendtu:dtu5_setlimit" }

sitemap:
Switch item=dtu5_setlimit mappings=[ 50="50W", 500="500W", 1500="1500W"] icon="settings"

My believe is that by selecting either 50, 500 or 1500 it would trigger an mqtt publish with the linked values 50, 500 or 1500. But via MQTT exploroer i do not see this.

Anything that i missed out, highly appreciate your feedback!

Do you see Thing, Channel and Item in Main UI?
By the way: The label of the channel does not support format.

Type number : dtu5_setlimit "HM.ng5wall SetLimit" [ commandTopic="/opendtu/dtu5/116xxxxxx78/cmd/limit_nonpersistent_absolute" ]

Are you sure about the leading slash in the topic? While not strictly prohibited, mqtt guidelines do discourage to use it.

And the Item has to be defined as Number, because Switch is only capable to send ON or OFF but never numbers:

Number dtu5_setlimit "HM.ng5wall SetLimit" <settings> { channel="mqtt:topic:mosquitto:opendtu:dtu5_setlimit" }

This won’t have any effect on the Switch widget in the sitemap, it’s completely fine to use a Switch widget with Number Items.

Switch item=dtu5_setlimit icon="settings" mappings=[50="50W", 500="500W", 1500="1500W"]

@Udo_Hartmann thanks for your support!

It simply was the switch-over from Switch to Number for the item.

About your format hint in channels/things. does it make any sense it spend time for the formatting/labelling at “Things” level? As i normally copy/paste the same label to the item that already sticks with the thing entry. What is best recommended. i tend to remove any label from Things file and only do this labelling for BasicUI at items level.

@MQTT Slashing. i use MQTT for years now. and i’ve seen both and hated the non-slashes while looking for “errors”. I still love the Slash version more. but thanks about the official recommendation to be considered for the future…

There is no formatting in channels, so don’t do that. :slight_smile:
At least, it will do no harm, but you also won’t have any benefit, and later on it can cause confusion.