MQTT switch messages arrived as ‘0’ or ‘1’ at clients
I did an update of the system and MQTT switch messages arrived as ‘ON’ or ‘OFF’ at clients
changed mqtt switch item to mqtt number item for 1 item => no messages are send with no error for that one item. Type number : CompRoomLightSwitch "Lampschakelaar Opkamer" [ stateTopic="openhab/command/86BB81_Switch", commandTopic="openhab/command/86BB81_Switch" ]
changed mqtt number item back to switch number => ALL mqtt clients receive switch messages as ‘0’ and ‘1’ again. Type switch : CompRoomLightSwitch "Lampschakelaar Opkamer" [ stateTopic="openhab/command/86BB81_Switch", commandTopic="openhab/command/86BB81_Switch" ]
However, in the logs it still shows as ‘ON’/‘OFF’ 2020-07-05 17:18:09.638 [vent.ItemStateChangedEvent] - LampschakelaarOpkamer changed from OFF to ON
Within openHAB, a switch is either ON or OFF. That’s it, nothing else. However, you can map this ON and OFF to something else when sending and receiving to something externally. I’m not quite certain of the behaviour you want, but if you want to send 0 and 1 instead of ON and OFF then try:
(You may not need the “” around the numbers - try both!)
Note that in the openHAB log it will still say that the switch is OFF or ON, but if you watch your MQTT topic you would hopefully see that you’re sending 1 and 0
Thanks for both answers, they both give me what I needed. @H102 Needed to fiddle a bit to get it working through PaperUI but it works now. @hafniumzinc That is the easiest solution looking how I currently set it up.