Switch sanding On/OFF but i need 1/0

Hello all,

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 ?

Greetings

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

Thanks

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!

Greetings

That worked, I was having problems, but it seamed to take a few minutes for my changes to take. I was being too impatient.

Hi,

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.

Please help.

And.

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.

1 Like

Hi,

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.

Andr

For your Thing, can you go to the Code tab, and then copy/paste the YAML in-between code fences?

2 Likes

@hafniumzinc

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:

  - id: pgm8
channelTypeUID: mqtt:switch
label: PGM 8
description: ""
configuration:
  stateTopic: dsc/Get/PGM8

So after playing around with the code, found out that this needs to be:

  - id: zone1
    channelTypeUID: mqtt:contact
    label: Zone 1
    description: ""
    configuration:
      stateTopic: dsc/Get/Zone1
      off: "0"
      on: "1"

For this, funny enough, one needs to delete the default 0 and 1 in the state values in the UI and enter them again by hand specifically.

Thank you @hafniumzinc @rossko57

There is work in this area

how it leaves all this is not clear to me.

Thats exactly what i had to do to send 1/0 to the mqtt topic to turn the relay on or off.

greetings

Hi,
having troubles with these settings

Type switch : livingroom    "Livingroom"     [ commandTopic="somfy/0x279621/level/cmd", on=0, off=100]

and still seeing in mqtt ON OFF instead of 0 or 100
on OH 3.1
do i have something wrong in there or it simply does not work

Note in previous examples the use of strings, not numbers I.e. “100”

tried that as well seems nothing really works, even restarted OH to pickup changes just in case… dunno weird

edit: for some reason it needed 2 restarts of the OH … works with on=“0”