*SOLVED* MQTT and MAP problem 2.2.0-1

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
      Raspberry P3
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
      2.1 and 2.2
  • Issue of the topic: please be detailed explaining your issue

I have 2 instances one on openhab 2.1 and one 2.2 both installed using openhabian. Am trying to get an MQTT event to change a switch. This works on 2.1 but not on 2.2. There are no errors that I can see and the items and map files are the same.

item

Switch Lever1 { mqtt=">[broker:wartonroad/1:command:OFF:0],>[broker:wartonroad/1:command:ON:1],<[broker:wartonroad/1:state:MAP(onoff.map)]"}

onoff.map

0=OFF
1=ON

rule

rule “lever-1”
when
Item Lever1 changed
then
if(Lever1.state == ON)
publish(“broker”, “signal_1”, “045”)
else
publish(“broker”, “signal_1”,“010”)
end

Sending an MQTT message of 1 will switch the switch on in 2.1 but not 2.2. MQTT is working on 2.2 as if I use basicui and the switch it will send out the relevent MQTT message.

any ideas?

You are trying to send an mqtt message to OH so that another is send out
The inbound MQTT binding with state will only update the item and even then, only if the value changes
Change your rule trigger to received update

rule “lever-1”
when
    Item Lever1 received update
then
    if (Lever1.state == ON)
    publish(“broker”, “signal_1”, “045”)
else
    publish(“broker”, “signal_1”,“010”)
end

Do you really need the outbound mqtt?
To make really sure you get a value EVERY time it is sent, you need to cahge the inbound binding to command but doing so on the same item would create a infinite mqtt loop. Bad for the broker…!!!
So create another switch:

Switch Lever1 { mqtt=">[broker:wartonroad/1:command:OFF:0],>[broker:wartonroad/1:command:ON:1]"}
Switch Lever2 { mqtt="<[broker:wartonroad/1:command:MAP(onoff.map)]"}

And your rule:

rule “lever-2”
when
    Item Lever2 received command
then
    if (receivedCommand == ON)
    publish(“broker”, “signal_1”, “045”)
else
    publish(“broker”, “signal_1”,“010”)
end

I tried the suggested changes with no effect. Copied the config folder and reinstalled openhabian then copied the config folder back and it worked first time.

So I guess I had a corrupt install somehow.

Your solution is much neater thank you

Gavin

Coolio!!
Please mark the thread as solved, please.