It looks like a basic item, but cannot make it work.
What I want to do is show a switch with an icon to its left. When the switch is activated a command is sent via mqtt and state is received (to make a light on for instance). See this screen capture (Ceiling and Mirror):
Share what you have attempted to make work, and hopefully someone here can offer advice. A good way to make your .items, .sitemap and .rules files legible to others is to wrap them in backticks like this:
If you plan many MQTT items in your Installation, I would recommend not to bother with individual bindings and instead configure MQTT event bus layer in openhab.cfg file. In this case you get automatically all topics for commands, states and feedback updates for each item.
See my post Node-RED as a rule/script engine for OpenHAB and MQTT wiki
The problem I’m facing now is that if I send the ON command (1) to garage/switch1/command, the relay will open but the UI won’t show the new state (light on, switch to the right). Is there something I am missing?
If you refresh your browser, does the switch show correctly? If so, either the event path from server to browser is broken or there is a UI bug.
You might want to also add , autoupdate="false" inside the { } for the item, so that the switch will only change when someone publishes a new state to the broker. Without it, the switch will change state when it receives the command, which is often good for UI responsiveness, but is not a true reflection of the state as monitored from MQTT.
Besides getting the state on the UI (which at this point would be irrelevant), I can’t even send commands to the item when the “<” direction part is present in the binding options.
There is a comma missing in both Switch definitions before <space>autoupdate="false".
This will only work if the message published on that topic is the string ON or OFF. You would have to replace default with a transformation like MAP(onoff.map):
1=ON
0=OFF
ON=1
OFF=0
That’s very odd and I would like to see configuration and logs.
As soon as I save that change, I get this in the log file:
2016-12-19 11:38:20.254 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'soldanet.items'
2016-12-19 11:38:20.301 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'pileta_luces' could not be parsed correctly
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mosquitto:pileta/luces/state:*:MAP(onoff.map)' is not a valid inbound configuration: nvalid type.
at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[190:org.openhab.core.comat1x:2.0.0.b4]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:312)[117:org.eclipse.smarthome.model.itm:0.9.0.b1]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:284)[117:org.eclipse.smarthome.model.itm:0.9.0.b1]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:167)[117:org.eclipse.smarthome.moel.item:0.9.0.b1]
at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:347)[117:org.eclipse.smarthome.model.item:0.9.0.b1]
at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:210)[116:org.eclipse.smarthome.model.core:0.9.0.1]
at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:124)[116:org.eclipse.smarthome.model.core:0.9..b1]
at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:267)[116:org.eclipse.smarthome.model.core:0.9.0.b1]
at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.access$1(FolderObserver.java:261)[116:org.eclipse.smarthome.model.core:0.9.0.b1]
at org.eclipse.smarthome.model.core.internal.folder.FolderObserver$WatchQueueReader.processWatchEvent(FolderObserver.java:142)[116:org.eclipse.smarthome.mdel.core:0.9.0.b1]
at org.eclipse.smarthome.core.service.AbstractWatchQueueReader.run(AbstractWatchQueueReader.java:95)[96:org.eclipse.smarthome.core:0.9.0.b1]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_65]
In English, the above means “for the mosquitto broker, when some client publishes on the pileta/luces/state topic, update the state of the item, but first transform the incoming message using the MAP(onoff.map) transformation.” So you must have the MAP transformation service installed (if on openHAB 2), and the file onoff.map must be in your transform directory.