I totally agree with @rlkoshak, however I’ m using the files and have it working.
Additionally I use mqtt-spy to check wether the commands are actually send.
Please show your log entries , we might find a clue.
I now configured the thing (bridge and generic number thing) using paper ui. I get the error “java.lang.Exception: No MQTT client”.
The Generic Thing shows OFFLINE - COMMUNICATION ERROR the Broker seems to be online.
With MQTT.fx I can connect to my broker just fine.
EDIT: A restart of OpenHab seems to have fixed the problem…
This is a working example from my things file:
Bridge mqtt:broker:mosquitto "MQTT Broker" [ host="10.200.0.4", port=1883, clientid="openhab", username="home", password="xxxx" ]
{
Thing topic rgbw1 "Ambient Light 1" {
Channels:
Type switch : state "OnOff" [ stateTopic="openhab/RGBWController1/relay/0", commandTopic="openhab/RGBWController1/relay/0/set" ]
Type number : brightness "Brightness" [ stateTopic="openhab/RGBWController1/brightness", commandTopic="openhab/RGBWController1/brightness/set" ]
Type number : white "White" [ stateTopic="openhab/RGBWController1/channel/3", commandTopic="openhab/RGBWController1/channel/3/set" ]
Type colorRGB : rgb "Color" [ stateTopic="openhab/RGBWController1/rgb", commandTopic="openhab/RGBWController1/rgb/set" ]
}
Thing topic rgbw2 "Ambient Light 2" {
Channels:
Type switch : state "OnOff" [ stateTopic="openhab/RGBWController2/relay/0", commandTopic="openhab/RGBWController2/relay/0/set" ]
Type number : brightness "Brightness" [ stateTopic="openhab/RGBWController2/brightness", commandTopic="openhab/RGBWController2/brightness/set" ]
Type number : white "White" [ stateTopic="openhab/RGBWController2/channel/3", commandTopic="openhab/RGBWController2/channel/3/set" ]
Type colorRGB : rgb "Color" [ stateTopic="openhab/RGBWController2/rgb", commandTopic="openhab/RGBWController2/rgb/set" ]
}
}
Resolved in OH 2.5 snapshot, appears if you configure via textual files.
@David_Graeff
Hi,
I’m struggling with the dimmer type channel/dimmer item combo. The Dimmer item can send PercentType commands (0…100) which should be converted on thing level to 0…255 range expected by the device.
The NumberValue class doesn’t apply any min/max transformation to percent type commands only for decimals:
...
else if (command instanceof PercentType) {
numberValue = ((PercentType) command);
} else if (command instanceof DecimalType) {
double v = ((DecimalType) command).doubleValue();
v = (v - min) * 100.0 / (max - min);
numberValue = new PercentType(new BigDecimal(v));
}
...
Any suggestion how to archive this?
I’m using Number channels with Setpoint controls on sitemap as workaround but it renders ugly…
Thanks
Hi,
I have a problem with the migration from oh2.3 stable to oh2.4 stable (MQTTv2):
on the picture you can see that with the new version of the mqtt bindings “on” and “OFF” can be seen in the sitemap, at the bottom of the picture you can see the old mqtt binding. how can I remove this “ON” resp. “OFF”?
MQTTv2:
Bridge mqtt:broker:Mosquitto [ host="localhost", port=1883, clientid="xxx", secure=false, username="xxx", password="xxx"]
{
Thing topic sonoff1Basic "sonoff1 BASIC" {
Channels:
Type switch : StatusSonoff1 "EIN/AUS" [ stateTopic="stat/sonoff1/POWER", commandTopic="cmnd/sonoff1/POWER" ]
Type switch : ReachableSonoff1 "Erreichbarkeit" [ stateTopic="tele/sonoff1/LWT", transformationPattern="MAP:reachable.map" ]
Type number : RSSISonoff1 "RSSI" [ stateTopic="tele/sonoff1/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
Type string : UptimeSonoff1 "Uptime" [ stateTopic="tele/sonoff1/STATE", transformationPattern="JSONPATH:$.Uptime" ]
Type string : FirmwareSonoff1 "Firmware" [ stateTopic="tele/sonoff1/INFO1", transformationPattern="JSONPATH:$.Version" ]
}
}
Switch sonoff1 "EIN/AUS" <switch> (gAnwensenheitsSimulation) { channel="mqtt:topic:Mosquitto:sonoff1Basic:StatusSonoff1" }
Switch sonoff1_Reachable "sonoff1 BASIC" <switch> { channel="mqtt:topic:Mosquitto:sonoff1Basic:ReachableSonoff1" }
Number sonoff1_RSSI "RSSI [%d %%]" <wlan> { channel="mqtt:topic:Mosquitto:sonoff1Basic:RSSISonoff1" }
String sonoff1_uptime "Uptime [%s]" <clock> { channel="mqtt:topic:Mosquitto:sonoff1Basic:UptimeSonoff1" }
String sonoff1_Firmware "Firmware [%s]" <firmware> { channel="mqtt:topic:Mosquitto:sonoff1Basic:FirmwareSonoff1" }
MQTTv1:
Switch sonoff2 "EIN/AUS" <switch> { mqtt=">[broker:cmnd/sonoff2-pow/POWER:command:*:default],
<[broker:stat/sonoff2-pow/POWER:state:default]"
}
Switch sonoff2_Reachable "sonoff2 POW" <switch> { mqtt="<[broker:tele/sonoff2-pow/LWT:state:MAP(reachable.map)]" }
Number sonoff2_RSSI "RSSI [%d %%]" <wlan> { mqtt="<[broker:tele/sonoff2-pow/STATE:state:JSONPATH($.Wifi.RSSI)]" }
String sonoff2_uptime "Uptime [%s]" <clock> { mqtt="<[broker:tele/sonoff2-pow/STATE:state:JSONPATH($.Uptime)]" }
//
Switch sonoff3 "EIN/AUS" <switch> { mqtt=">[broker:cmnd/sonoff3-th/POWER:command:*:default],
<[broker:stat/sonoff3-th/POWER:state:default]"
}
Switch sonoff3_Reachable "sonoff3 TH16" <switch> { mqtt="<[broker:tele/sonoff3-th/LWT:state:MAP(reachable.map)]" }
Number sonoff3_RSSI "RSSI [%d %%]" <wlan> { mqtt="<[broker:tele/sonoff3-th/STATE:state:JSONPATH($.Wifi.RSSI)]" }
Number:Temperature sonoff3_temp "Temperature [%.1f °C]" <temperature> (gTemperatureFireAlarm) { mqtt="<[broker:tele/sonoff3-th/SENSOR:state:JSONPATH($.AM2301.Temperature)]" }
Number sonoff3_humidity "Luftfeuchte [%.1f %%]" <humidity> { mqtt="<[broker:tele/sonoff3-th/SENSOR:state:JSONPATH($.AM2301.Humidity)]" }
String sonoff3_uptime "Uptime [%s]" <clock> { mqtt="<[broker:tele/sonoff3-th/STATE:state:JSONPATH($.Uptime)]" }
Frame {
Text label="sonfoffs" icon="sonoff" {
Frame label="sonoff1" {
Switch item=sonoff1_Reachable mappings=[ON="online ✔"] icon="connected" visibility=[sonoff1_Reachable=="ON"]
Switch item=sonoff1_Reachable mappings=[OFF="offline ✘"] icon="error" visibility=[sonoff1_Reachable!="ON"]
Switch item=sonoff1 visibility=[sonoff1_Reachable=="ON"]
Text item=sonoff1_RSSI visibility=[sonoff1_Reachable=="ON"]
Text item=sonoff1_uptime visibility=[sonoff1_Reachable=="ON"]
Text item=sonoff1_Firmware visibility=[sonoff1_Reachable=="ON"]
}
Frame label="sonoff2" {
Switch item=sonoff2_Reachable mappings=[ON="online ✔"] icon="connected" visibility=[sonoff2_Reachable=="ON"]
Switch item=sonoff2_Reachable mappings=[OFF="offline ✘"] icon="error" visibility=[sonoff2_Reachable!="ON"]
Switch item=sonoff2 visibility=[sonoff2_Reachable=="ON"]
Text item=sonoff2_RSSI visibility=[sonoff2_Reachable=="ON"]
Text item=sonoff2_uptime visibility=[sonoff2_Reachable=="ON"]
}
Frame label="PC-KELLER" {
Switch item=sonoff3_Reachable mappings=[ON="online ✔"] icon="connected" visibility=[sonoff3_Reachable=="ON"]
Switch item=sonoff3_Reachable mappings=[OFF="offline ✘"] icon="error" visibility=[sonoff3_Reachable!="ON"]
Switch item=sonoff3 visibility=[sonoff3_Reachable=="ON"]
Text item=sonoff3_RSSI visibility=[sonoff3_Reachable=="ON"]
Text item=sonoff3_temp visibility=[sonoff3_Reachable=="ON"]
Text item=sonoff3_humidity visibility=[sonoff3_Reachable=="ON"]
Text item=sonoff3_uptime visibility=[sonoff3_Reachable=="ON"]
}
Same problem here, my solution was to use a MAP transformation and hide the unwanted state. This problem is related to the new MQTT binding, perhaps there is a more elegant solution that I dont know.
Are you sure that this problem (a switch item showing its ON /OFF as text additionally) is related to MQTT?
IMHO it is a problem (or even a wanted? new feature) of the sitemap.
Just put an empty into the label of the item to make the item’s value disappear:
Switch sonoff2 "EIN/AUS []"
Maybe the MQTT binding is not the right place to implement this outbound transformation. I have a feeling that implementing it on profile level would be a better solution. WDYT?
I think we are all in agreement with this but that is a longer term project. Adding outbound transforms to the MQTT binding is a stop gap solution until something like that gets implemented.
David did say elsewhere that profiles will probably not be the right approach but he didn’t provide details for why. I suspect profiles are set up to only process incoming data.
Thanks for pointing, it works. However, I do not understand the cause of the problem. with version MQTT v1 I did not have this problem …
The mqtt2 addon does things more … accurate, for example correctly defining the state presentation including a unit if necessary etc.
Please help convert to new binding:
Switch ESP_Dock_State "Dock online" <network> { expire="5m,command=OFF", mqtt="<[zbox:/esp/esp-dock/sensors/uptime:state:ON]" }
I need to trasform any number value (‘10’ for example) from /esp/esp-dock/sensors/uptime
topic to ON
state.
Any message means ON or literally any number means ON and non-numbers mean OFF? Ignored?
Any message means ON
OK, then I think this will work.
Assuming you are running OH 2.5 M1 (which you should because of many bug fixes in MQTT 2 binding immediately after 2.4 released there is a new default value in the Map transform. So if you create a .map file containing
=ON
and apply that transform to the incoming Channel any message should get transformed to ON.
Works!
Thank you @rlkoshak
One more thing, can you explain this rule from here: https://www.openhab.org/addons/bindings/mqtt.generic/
rule "Publish all"
when
Channel "mqtt:broker:myUnsecureBroker:myTriggerChannel" triggered
then
//this is variable where all incoming messages is stored separated by #
val parts = receivedEvent.split("#")
//but i do not understand this line
sendCommand(parts.get(0), parts.get(1)
end
This is to replace part of the replacement for the EventBus capability. The Rule get’s triggered for all messages published to the myTriggerChannel. The receivedEvent implicit variable carries the event as a String. The format of the String is <topic>#<value>
.
So when events are received on the topic we can command the Item of the same name with the value. Thus you can sort of federate OH instances over MQTT by having them publish all events and using a Rule like this to synchronize them.