Switch with Status (Solved)

I am trying to use a switch that displays the value received from the device using MQTT. I can get the command working no problem but I am having trouble with the status unless I have the device send ON and OFF instead of 1 or 0 like I want.

Item:

Switch LED "LED [%s]" {mqtt=">[mosquitto:openhab/LEDcommand:command:ON:1],>[mosquitto:openhab/LEDcommand:command:OFF:0],<[mosquitto:openhab/LEDstatus:state:default]"}

Sitemap:

Switch item=LED icon=<bulb>

I also tried using a map with the item where:
onoff.map:
0=OFF
1=ON

and the item was:

Switch LED "LED [MAP(onoff.map):%s]" {mqtt=">[mosquitto:openhab/LEDcommand:command:ON:1],>[mosquitto:openhab/LEDcommand:command:OFF:0],<[mosquitto:openhab/LEDstatus:state:MAP(onoff.map)"}

What am I doing wrong?

1 Like

Solved it. Two Problems:

  1. Did not have the MAP transformation installed
  2. I was “double mapping” - I only need the mapping on the broker part, not the string as well
1 Like