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.
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.
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:
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.