[SOLVED] MQTT items / things problem with commands, text files

Hi have have some problem regarding the commands sent from openhab to device.
i have tried for a couple of days to fix the problem without luck

Im running openhabian 2.5.1 fresh install on a RPI3B

The problem is that i have a switch item that sents “1” and “0” instead of “ON” and “OFF”

Things:

        Type switch : Hus_1sal_bad_udsug                        "Tænd udsugning i badeværelse"      [ stateTopic="hjem/1/badeværelse/fancontrol/fan_sta", commandTopic="hjem/1/badeværelse/fancontrol/fan_cmd" ]
        Type switch : Hus_1sal_bad_udsug_speed                  "Speed udsugning i badeværelsee"    [ stateTopic="hjem/1/badeværelse/fancontrol/fanspeed_sta", commandTopic="hjem/1/badeværelse/fancontrol/fanspeed_cmd" ]

Items:

Switch			Fan1Power				"Ventilator power"				<fan>				(Fan_F_Badevarelse, F)															{channel="mqtt:topic:mosquitto:homemadeMQTT:Hus_1sal_bad_udsug"}
Switch			Fan1Speed				"Ventilator high/low"			<flow>				(Fan_F_Badevarelse, F)															{channel="mqtt:topic:mosquitto:homemadeMQTT:Hus_1sal_bad_udsug_speed"}

From mqtt explorer, here you can see that the
fanspeed_cmd=1 it should be =ON
fan_cmd=1 it should be=ON


‘’
Thanks Mads

Try using MAP transformation on the Thing.

Example:

Thing topic Esp1 "Garage Light Level" @ "Garage" {
    Channels:
        Type number : level  "Light Level"          [ stateTopic="/Esp1/Garage/LightLevel" ]
        Type switch : contact  "Open Closed"        [ stateTopic="/Esp1/Door/Switch", transformationPattern="MAP:ONOFF.map" ]
        Type switch : motion  "Motion"              [ stateTopic="/Esp1/Motion/Switch", transformationPattern="MAP:ONOFF.map" ]
    }

Don’t forget to install the transformation service via PaperUI and put the transformation on the command topic to send a command.

Here is the map file for the things above:

ONOFF.map

GPIO,13,1=ON
GPIO,13,0=OFF
1=ON
0=OFF

You shouldn’t need the GPIO part just the last two lines.

There is an easier way from using the map transform. There is an onState and offState (or something like that) which you can define on the Channel which does essentially the same thing that the map transform does. I don’t use .things files so I’m not sure how that translates to the .things files but you should be able to search around the forum and find examples.

I should probably use PaperUI to create a Thing or two just to help others on the forum as I’m still 100% files…and per my wife hardheaded. :rofl:

2 Likes

I tried making a ONOFF.map file with
1=ON
0=OFF

there was a little change i the behavior, now im able, after many tries to change fan_cmd=0 and back to fan_cmd=1

New version things file:

 Type switch : Hus_1sal_bad_udsug        "Tænd udsugning i badeværelse"      [ stateTopic="hjem/1/badeværelse/fancontrol/fan_sta", commandTopic="hjem/1/badeværelse/fancontrol/fan_cmd", transformationPattern="MAP:ONOFF.map" ]
 Type switch : Hus_1sal_bad_udsug_speed  "Speed udsugning i badeværelsee"    [ stateTopic="hjem/1/badeværelse/fancontrol/fanspeed_sta", commandTopic="hjem/1/badeværelse/fancontrol/fanspeed_cmd", transformationPattern="MAP:ONOFF.map" ]

Mqtt explorer


Thanks Mads

1 Like

I have tried

transformationPattern=“MAP:ONOFF.map”
transformationPatternOut=“MAP:ONOFF.map”

i will tried
formatBeforePublish

For the first switch did you try:

Type switch : Hus_1sal_bad_udsug        "Tænd udsugning i badeværelse"      [ stateTopic="hjem/1/badeværelse/fancontrol/fan_sta", commandTopic="hjem/1/badeværelse/fancontrol/fan_cmd", on="ON", off="OFF" ]

And add to the map file for the other channels:

1=ON
0=OFF
OFF=0
ON=1

I also just noticed on the screen shot this is zigbee2mqtt. Have you added:
experimental:
output: 'json'

to the bottom of your ymal file?

Hi

I have not tried , on=“ON”, off=“OFF” but i have tried 1=“ON”, 0=“OFF”

The fan_cmd and fanspeed_cmd is a WIFI connect device

I the zigbee2mqtt ymal file is completely standard, i just installed it yesterday, i only have one device pair with it

Looking at the screen shot the only thing that uses ON/OFF is the fans status e.g. fan_sta and fanspeed_sta

You need to control the fan by turning it on with 0=OFF and 1=ON.

To control the speed you also need a number, or something different e.g. HIGH, LOW ?? In the pic it looks like you need a number.

HI

Its working :slight_smile: :star_struck:
i tried this , on=“ON”, off=“OFF”
at first it only worked on fan_cmd but after a reboot its also working on fanspeed_cmd

Type switch : Hus_1sal_bad_udsug        "Tænd udsugning i badeværelse"      [ stateTopic="hjem/1/badeværelse/fancontrol/fan_sta", commandTopic="hjem/1/badeværelse/fancontrol/fan_cmd", on="ON", off="OFF" ]

i did not now that it would sent a “1” instead of “ON” because of the differens between on and ON ??

but

THANKS :slight_smile:

Yea. :+1:

I posted that earlier but honestly thought you had tried that already.

Please click the square box on the solution post to mark topic as solved.

I have made the “fan controller” my self, it just need ON and OFF :slight_smile: