I my Openhab2 i used a SSR relay that is turned ON/OFF with the command 1/0
To get that working a had to make a rule that sanded the commend 1 or 0 to a mqtt topic to turn the relay on or off.
No i installed Openhab3 created a mosquitto broker added as thing, than added my sensors and have it working. Now i want to add the relay, with a channel, and that works. But it sand the commend ON or OFF to the mqtt topic. Now in Openhab3 do i still have to make a rule that sand the command 1 or 0 to the mqtt topic ? and if so how would i do that ?
How are you defining the item? If it’s defined as a Switch/Dimmer it’s going to send ON/OFF. You might need to define it as a number or string is it’s expecting a literal 1 or 0.
Example
Switch SSRRELAY “mqtt relay”
might need to be
Number SSRRELAY “mqtt relay”
or
String SSRRELAY “mqtt relay”
No, you don’t need a rule. If this is defined using the UI, check the custom on/off parameters for this Channel. If you’re using Things files, just add on=1, off=0 to your Channel configuration.
Out of curiosity can you do with with an item that does not have an associated binding/channel?
I have an item for my tablets that is a contact OPEN/CLOSED for when they are docked. Can we remap those to OPEN=Undocked, CLOSED=Docked? I couldn’t get this to work without an associated thing/channel
You could maybe use a MAP transform, either at the Item (or Sitemap level, if relevant). Presumably you’re taking about a wish to display a different value, whilst OP wants to send a different value?
Thanks for the reply’s
I now use UI.
Its working, the custom on/off parameters was already filled in with 1 and 0. But had to type in 1 and 0 and now its working. Thanks!
sorry to tag onto this topic, but I have a problem in reverse. I’m using MQTT to receive the status of a DCS alarm system. I do have switches (some state and some with command topics). Now with switches that MQTT gets custom values (in my case ‘1T’ and ‘1D’) everything works and the switch displays ‘ON’ and ‘OFF’ appropriately. But for the switches or contacts that I receive 1 and 0 through MQTT and use default setting for a switch channel (0 and 1 for off and on), the item displays ‘NULL’ regardless what is received through MQTT. If I set the channel to a number instead of a switch, I do get the exact values that MQTT receives (1 and 0), but then it is not a switch.
Is this a bug, or did I configure the channel incorrectly?
This is what MQTT receives:
dsc/Get/Zone3 1
dsc/Get/Zone3 0
And setup for switch or contact channel are defaut, meaning on/off values are 1 and 0, but I get NULL. MQTT topic is also correct.
Reading between the lines of what you and others have reported, this doesn’t appear to work with default. Maybe that’s actually a UI issue. Trying setting 0 and 1 positively.
I also do not think that this is a UI issue.
I did specifically set 1 and 0 with no effect, although UI does fill these values into the setup fields if you try to leave them empty.
I’m a bit desperate for a workaround since I have eliminated the UI config out and think this is either a bug or config beyond the UI.
Than you for pointing me to the code tab. Issue solved. Let me explain.
If I leave on/off values empty in the UI, those get populated with 0 and 1 by default. However, if I look at the code, it results in this: