MQTT Item for the IFan02

I am using OpenHab2 inside an Ubuntu VM. It has been working for about 6 months with no issues using Sonoff products. I finally broke down and ordered an IFan02 and flashed it with Tasmota 6.4.1.

Now for the issue: For the life of me I can not figure out the MQTT statement for the items file. I can get the light to turn on and off with the following statement

Switch MBFan “Master Bedroom Fan” [ “Switchable” ] { mqtt=">[broker:cmnd/MBFan/POWER1:command:*:default],<[broker:stat/MBFan/POWER1:state:default]" }

But for the fan control, I am lost. Below I pasted the console for the Tasmota IFan02 device

15:59:42 MQT: stat/MBFan/RESULT = {“FanSpeed”:2}
16:02:00 MQT: tele/MBFan/UPTIME = {“Time”:“2018-12-26T16:02:00”,“Uptime”:“0T00:28:56”}
16:02:23 MQT: stat/MBFan/RESULT = {“FanSpeed”:0}
16:02:30 MQT: stat/MBFan/RESULT = {“FanSpeed”:3}
16:02:34 MQT: stat/MBFan/RESULT = {“POWER1”:“OFF”}
16:02:34 MQT: stat/MBFan/POWER1 = OFF
16:02:46 MQT: stat/MBFan/RESULT = {“POWER1”:“ON”}
16:02:46 MQT: stat/MBFan/POWER1 = ON
16:02:52 MQT: stat/MBFan/RESULT = {“POWER1”:“OFF”}
16:02:52 MQT: stat/MBFan/POWER1 = OFF
16:02:57 MQT: stat/MBFan/RESULT = {“FanSpeed”:0}
16:03:05 MQT: stat/MBFan/RESULT = {“FanSpeed”:3}
16:03:24 MQT: tele/MBFan/STATE = {“Time”:“2018-12-26T16:03:24”,“Uptime”:“0T00:30:20”,“Vcc”:3.545,“SleepMode”:“Dynamic”,“Sleep”:250,“LoadAvg”:3,“POWER1”:“OFF”,“FanSpeed”:3,“Wifi”:{“AP”:1,“SSId”:“ACEHouse24”,“BSSId”:“A8:11:FC:C9:9E:10”,“Channel”:11,“RSSI”:80}}
16:03:26 MQT: stat/MBFan/RESULT = {“FanSpeed”:0}
16:03:58 MQT: stat/MBFan/RESULT = {“POWER1”:“ON”}
16:03:58 MQT: stat/MBFan/POWER1 = ON
16:08:25 MQT: tele/MBFan/STATE = {“Time”:“2018-12-26T16:08:25”,“Uptime”:“0T00:35:21”,“Vcc”:3.543,“SleepMode”:“Dynamic”,“Sleep”:250,“LoadAvg”:3,“POWER1”:“ON”,“FanSpeed”:0,“Wifi”:{“AP”:1,“SSId”:“ACEHouse24”,“BSSId”:“A8:11:FC:C9:9E:10”,“Channel”:11,“RSSI”:82}}
16:13:26 MQT: tele/MBFan/STATE = {“Time”:“2018-12-26T16:13:26”,“Uptime”:“0T00:40:22”,“Vcc”:3.547,“SleepMode”:“Dynamic”,“Sleep”:250,“LoadAvg”:3,“POWER1”:“ON”,“FanSpeed”:0,“Wifi”:{“AP”:1,“SSId”:“ACEHouse24”,“BSSId”:“A8:11:FC:C9:9E:10”,“Channel”:11,“RSSI”:86}}
16:18:26 MQT: tele/MBFan/STATE = {“Time”:“2018-12-26T16:18:26”,“Uptime”:“0T00:45:22”,“Vcc”:3.547,“SleepMode”:“Dynamic”,“Sleep”:250,“LoadAvg”:3,“POWER1”:“ON”,“FanSpeed”:0,“Wifi”:{“AP”:1,“SSId”:“ACEHouse24”,“BSSId”:“A8:11:FC:C9:9E:10”,“Channel”:11,“RSSI”:82}}
16:23:29 MQT: tele/MBFan/STATE = {“Time”:“2018-12-26T16:23:29”,“Uptime”:“0T00:50:25”,“Vcc”:3.545,“SleepMode”:“Dynamic”,“Sleep”:250,“LoadAvg”:3,“POWER1”:“ON”,“FanSpeed”:0,“Wifi”:{“AP”:1,“SSId”:“ACEHouse24”,“BSSId”:“A8:11:FC:C9:9E:10”,“Channel”:11,“RSSI”:80}}
16:24:18 MQT: stat/MBFan/RESULT = {“FanSpeed”:0}
16:24:20 MQT: stat/MBFan/RESULT = {“FanSpeed”:1}
16:24:23 MQT: stat/MBFan/RESULT = {“FanSpeed”:2}
16:24:26 MQT: stat/MBFan/RESULT = {“FanSpeed”:3}
16:24:29 MQT: stat/MBFan/RESULT = {“FanSpeed”:0}

Any help creating a MQTT statement for this device would be appreciated.
Thank you!

Have you tried using the Fanspeed command with payload 1…3 as per the doc’s?

List of commands link:

Any luck so far?
I’m using the following item:

//sonoff-WZ-fan - FanSpeed
Number Switch_sonoff_WZ_fan_spd “Lüfter WZ” (gSwitches,gWohnzimmer)
{mqtt=">[broker:cmnd/sonoff-WZ-fan/FanSpeed:command:*:default],
<[broker:stat/sonoff-WZ-fan/RESULT:state:JSONPATH($.FanSpeed):REGEX(.Fan.)]"}

with not so much luck. I wish to have a state change like the switches: triggering ON/OFF from web interface or from button leads to update of openhab Basic UI (where I have a sitemap with a Switch). Viceversa Openhab would be able to generate a state change to the fan (0,1,2,3).

here the mistake: we don’t need to declare a REGEX, since it is interpreted as such! just use as last argument

.*Fan.*

Hi all !
so … the solution is … ?

What in things, what in items and what in sitemap?

Thanks for your help.

Dani

Hello the Solution is:

ITEMS:

Switch ifan2_Ligth “Ligth”
{ mqtt=">[broker:cmnd/ifan02/POWER1:command:*:default],
<[broker:stat/ifan02/POWER1:state:default]" }

Number ifan2_speed “Fan:” {mqtt=">[broker:cmnd/ifan02/FanSpeed:command:*:default],
<[broker:stat/ifan02/RESULT:state:JSONPATH($.FanSpeed):(.Fan.)]"}

SITEMAP:

Switch item= ifan2_Ligth icon=“light”
Switch item= ifan2_speed label=“Mode” icon=“fan_ceiling” mappings=[0=“Off”, 1=“Slow”, 2=“Med”, 3=“Higth”]

Hope this work for you
Hector

all I get is a warning that states missing EOF at mapping ? Will load the warning now.

I have tried the setup as suggested. and once uploaded and restart of openhab. my master bedroom items get ignored. and when I remove the mapping from my items. then it includes the items.

Mqtt.Things

Bridge mqtt:broker:mosquitto "MQTT Broker"              [ host="192.168.1.5", port=1883, clientid="openhab", secure=false]
{
Thing topic mything "MasterBedroom"{
    Channels:
    Type switch : lamp                              "Main_Light"                [ stateTopic="HoofSlaapKamer/relay/0:state", commandTopic="HoofSlaapKamer/relay/0/set" ]
    Type switch : downlight                         "downlight"                 [ stateTopic="HoofSlaapKamer/relay/1:state", commandTopic="HoofSlaapKamer/relay/1/set" ]
    Type number : temp                              "MasterBedroom Temp"        [ stateTopic="HoofSlaapKamer/Temperature"] 
    Type number : humi                              "MasterBedroom Humidity"    [ stateTopic="HoofSlaapKamer/Humidity"]
    Type switch : Fan_Light                         "Fan on/off"                [stateTopic="stat/sonoff_MBR_fan/POWER1", commandTopic="cmnd/sonoff_MBR_fan/power", transformationPattern="MAP:OFF0ON1.map" , on="ON", off="OFF"]
    Type string : Fan_SPD                           "Fan Speed"                 [stateTopic="stat/sonoff_MBR_fan/RESULT", commandTopic="cmnd/sonoff_MBR_fan/FanSpeed", transformationPattern=JSONPATH($.FanSpeed):(.Fan.) ]
    }
}

Masterbedroom.items

Group       MasterBedroom               "Master Bedroom"           <bedroom_red>                    (Home)

Switch      MasterBedroom_Light_Ingan   "Entrance Light"            <light>                          (MasterBedroom)                           ["Lighting"]                     {mqtt=">[flatcntr:HoofSlaapKamer/relay/0/set:command:*:MAP(OFF0ON1.map)],<[flatcntr:HoofSlaapKamer/relay/0:state:MAP(0OFF1ON.map)]"}
Switch      MasterBedroom_Light         "Room Light"                <light>                          (MasterBedroom)                           ["Lighting"]                     {mqtt=">[flatcntr:HoofSlaapKamer/relay/1/set:command:*:MAP(OFF0ON1.map)],<[flatcntr:HoofSlaapKamer/relay/1:state:MAP(0OFF1ON.map)]"} 
Number      MasterBedroom_Humidity      "Humidity"                  <humidity>                       (MasterBedroom, gHumidity)                       
Number      MasterBedroom_Temperature   "Temperature"               <temperature>                    (MasterBedroom, gTemperature)                    
Switch      MasterBedroom_Fan_Light     "Fan Light"                 <fan_ceiling>                    (MasterBedroom)                                                            {channel="mqtt:topic:mosquitto:MasterBedroom:Fan_Light"}
Switch      MasterBedroom_Fan_spd       "Fan Speed"                 <fan_ceiling>   mappings=[0="OFF", 1="Slow", 2="Med", 3="High"]                 (MasterBedroom)                                                            {channel="mqtt:topic:mosquitto:MasterBedroom:Fan_SPD"}

Not Sure if it is right ?

Thanks

The mappings= definistion belongs in a sitemap file not in the items file

Thank you .
I am redoing my sitemap. as i only used groupes and pulled everything out of my item files.

Thank you. I re did my site map.
how ever I am having some issues with controlling my IFan02.

Here are my configs.

Mqtt.things

Bridge mqtt:broker:mosquitto "MQTT Broker"              [ host="192.168.1.5", port=1883, clientid="openhab", secure=false]
{
Thing topic master_bed "MasterBedroom"{
    Channels:
    Type switch : lamp                              "Main_Light"                [ stateTopic="HoofSlaapKamer/relay/0:state", commandTopic="HoofSlaapKamer/relay/0/set" ]
    Type switch : downlight                         "downlight"                 [ stateTopic="HoofSlaapKamer/relay/1:state", commandTopic="HoofSlaapKamer/relay/1/set" ]
    Type number : temp                              "MasterBedroom Temp"        [ stateTopic="HoofSlaapKamer/Temperature"] 
    Type number : humi                              "MasterBedroom Humidity"    [ stateTopic="HoofSlaapKamer/Humidity"]
    Type switch : Fan_Light                         "Fan on/off"                [stateTopic="stat/Masterbedroom-Fan/POWER1", commandTopic="cmnd/Masterbedroom-Fan/power"]
    Type number : Fan_SPD                           "Fan Speed"                 [stateTopic="stat/Masterbedroom-Fan/RESULT", commandTopic="cmnd/Masterbedroom-Fan/FanSpeed", transformationPatter="JSONPATH($.FanSpeed):(.Fan.)" ]
    }
}

Matsterbedroom.items

Switch      MasterBedroom_Light_Ingan   "Entrance Light"            <light>                          (MasterBedroom)                           ["Lighting"]                     {mqtt=">[flatcntr:HoofSlaapKamer/relay/0/set:command:*:MAP(OFF0ON1.map)],<[flatcntr:HoofSlaapKamer/relay/0:state:MAP(0OFF1ON.map)]"}
Switch      MasterBedroom_Light         "Room Light"                <light>                          (MasterBedroom)                           ["Lighting"]                     {mqtt=">[flatcntr:HoofSlaapKamer/relay/1/set:command:*:MAP(OFF0ON1.map)],<[flatcntr:HoofSlaapKamer/relay/1:state:MAP(0OFF1ON.map)]"} 
Number      MasterBedroom_Humidity      "Humidity"                  <humidity>                       (MasterBedroom, gHumidity)                       
Number      MasterBedroom_Temperature   "Temperature"               <temperature>                    (MasterBedroom, gTemperature)                    
Switch      MasterBedroom_Fan_Light     "Fan Light"                 <fan_ceiling>                    (MasterBedroom)                                                            {channel="mqtt:topic:mosquitto:MasterBedroom:Fan_Light"}
String      MasterBedroom_Fan_spd       "Fan Speed"                 <fan_ceiling>                    (MasterBedroom)                                                            {channel="mqtt:topic:mosquitto:MasterBedroom:Fan_SPD"}

Sitemap.

Text label="Master Bedroom" icon="bedroom"{
         Default item=MasterBedroom_Light_Ingan label="Entrance Light" icon="lightbulb"
         Default item=MasterBedroom_Light label="Light" icon="lightbulb"
         Default item=MasterBedroom_Fan_Light label="Fan Light" icon="lightbulb"
         Switch item=MasterBedroom_Fan_spd label="Fan Speed" icon="fan_ceiling"  mappings=[0="OFF", 1="Slow", 2="Med", 3="High"]
         Text item=MasterBedroom_Humidity label="Humidity [%.1f %]"
         Text item=MasterBedroom_Temperature  label="Temperature [%.1f °C]"

I have been going around in circles and can figure it out.

Thank you

Are we to assume WHAT the problems are?

Looking at the .things file, the switch “Fan_Light” looks weird, it is using a stateTopic ending at “POWER1”, the commandTopic however ends at “power”. Is this the Problem?

Sorry .
the main issue is that I seem to not be Abel to control the Fan at all.
not sure what can be worn. I will add the log info now also . sorry for the lack of information. not much I can find. I am not sure what the problem is.
Not sure if it could be my mqtt either.

2019-04-15 08:19:28.607 [vent.ItemStateChangedEvent] - CPU_Load changed from 9.4 to 10.2

2019-04-15 08:19:29.843 [ome.event.ItemCommandEvent] - Item 'MasterBedroom_Fan_spd' received command 3

2019-04-15 08:19:29.845 [nt.ItemStatePredictedEvent] - MasterBedroom_Fan_spd predicted to become NULL

It looks like you are not aware off which messages to send to the fan in order to tunr ON/OFf and to change the speed.
I’d try and test this with an external MQTT Viewer (like MQTTfx) before moving to openHAB. When you are able to control the fan via MQTT Messages from the viewer you will have the needed topics on hand.

Ok Will test that tonight and report back.

Hi all . only hade time to cheke today.
the fan speed command topic is : cmnd/Masterbedroom-Fan/FanSpeed
The state topic is :stat/Masterbedroom-Fan/RESULT
The light command topic is :cmnd/Masterbedroom-Fan/power
the light state topic is :stat/Masterbedroom-Fan/POWER1

my mqtt.things for the ifan02 is as follows.

Type switch : Fan_Light                         "Fan on/off"                [stateTopic="stat/Masterbedroom-Fan/POWER1", commandTopic="cmnd/Masterbedroom-Fan/power"]
    Type number : Fan_SPD                           "Fan Speed"                 [stateTopic="stat/Masterbedroom-Fan/RESULT", commandTopic="cmnd/Masterbedroom-Fan/FanSpeed", transformationPatter="JSONPATH($.FanSpeed):(.Fan.)" ]
    }

sitems for ifan02 is as follows.

Switch      MasterBedroom_Fan_Light     "Fan Light"                 <fan_ceiling>                    (MasterBedroom)                                                            {channel="mqtt:topic:mosquitto:MasterBedroom:Fan_Light"}
String      MasterBedroom_Fan_spd       "Fan Speed"                 <fan_ceiling>                    (MasterBedroom)                                                            {channel="mqtt:topic:mosquitto:MasterBedroom:Fan_SPD"}

then my log gives me the following :

2019-04-18 09:15:31.793 [vent.ItemStateChangedEvent] - Memory_Available_Percent changed from 11.1 to 11.2

2019-04-18 09:15:32.611 [ome.event.ItemCommandEvent] - Item 'MasterBedroom_Fan_Light' received command ON

2019-04-18 09:15:32.615 [nt.ItemStatePredictedEvent] - MasterBedroom_Fan_Light predicted to become NULL

2019-04-18 09:16:15.500 [ome.event.ItemCommandEvent] - Item 'MasterBedroom_Fan_spd' received command 3

2019-04-18 09:16:15.503 [nt.ItemStatePredictedEvent] - MasterBedroom_Fan_spd predicted to become NULL

2019-04-18 09:16:16.184 [vent.ItemStateChangedEvent] - Date changed from 2019-04-18T09:15:46.172+0200 to 2019-04-18T09:16:16.173+0200

2019-04-18 09:16:16.851 [vent.ItemStateChangedEvent] - CPU_Load changed from 9.9 to 10.9

But if I send the commands from mqttfx it works. what am I doing wrong.

What I did se is in paperui I can control the fan and light but in the app I get those warnings. and also if I use basicui

I am little dumb. My channel is wrong
:thinking: :relaxed:

What message are sending to the device (Fan Light) via MQTTfx when it works (to which topic and which message content [ ON/OFF or on/ff or…).
What messages are received by MQTTfx when when your are trying to switch the “Fan Light” via openHAB (which topic and which message content [ ON/OFF or on/ff or…).
The differences will tell what is wrong!

Do the same for the “Fan Speed”.

If you can control both via PaperUI (which would be under the Controls section), you are actually using the created items. In an app you would use the same items, in other words the Setup of the app is not correct.

I have seen my error. And feel like a fool.
My mqtt topic
thing topic master_bed "MasterBedroom”

My channel
{channel=“mqtt:topic:mosquitto:MasterBedroom:Fan_SPD”}

Should be : {channel=“mqtt:topic:mosquitto:master_bed:Fan_SPD”}

Glad you found it and don’t worry. I can’t count my post in which I asked a question which I could solve on my own only seconds after posting!:joy: