- Platform information:
- Hardware: Raspberry Pi 3 Model B
- OS: openHABian
- Java Runtime Environment: openjdk version “1.8.0_152”
- openHAB version: 2.4.0-1
- MQTT Binding 1.13.0
- mosquitto version 1.4.10
Firstly I humbly apologise as this is a redundant topic. I’ve searched the openHAB forum and have found several similar problems but unfortunately for me (being a noob with openHAB, MQTT etc.) I am still not able to figure out how to resolve this issue.
What I am trying to achieve is very simple, make an on/off button in sitemap and control the LED on my development board.
I’ve installed mosquitto, and the MQTT broker works fine. I’m using MQTT.fx 1.7.1 on my MacOS to check the topics.
Here’s the problem:
To turn on/off the LED on the development board:
Topic = iot-2/cmd/leds/fmt/json
String = {\”led\”:\”red\”,\”value\”:1}
(turning ON the red LED)
String = {\”led\”:\”red\”,\”value\”:0}
(turning OFF the red LED)
Using MQTT.fx, I am able to publish the string to the topic, turning the LED on/off works.
Here’s the content (with screenshot of the actual file for better clarification) of my Items file:
String S1_LED_RED "S1 LED Red" {mqtt=">[<broker>:iot-2/cmd/leds/fmt/json:command:*:default]"}
Here’s the content of my Rules file:
rule "Update 6LoWPAN Module Switch Items"
when
Item S1_LED_RED received command TOGGLE
then
if(S1_LED_RED == OFF) {
S1_LED_RED.sendCommand("{\”led\”:\”red\”,\”value\”:0}")
}
else {
S1_LED_RED.sendCommand("{\”led\”:\”red\”,\”value\”:1}")
}
end
Here’s the content of my Sitemap file:
Switch item=S1_LED_RED label="S1 Red LED" mappings=[,{\”led\”:\”red\”,\”value\”:1}=ON]
And this is what my sitemap looks like:
Can someone please help point the mistake/s I’ve done.
Thanks