The Tasmota Fan Controller I've been waiting for...





I've done several projects with the Sonoff iFan03 and various Martin Jerry dimmers to make my own fan controllers that work via Home Assistant while also following my rule of "never removing functionality while adding functionality" in a smart home.  The setup is challenging with replacing fan capacitors for 120vac based fans, dimmer rules, iFan rules, etc.  I've always been looking for a drop in fan controller that was not Zwave or Zigbee based.  Treatlife finally came out with a device that answers all of this and more!  

The Treatlife 2 in 1 Fan Controller and Light Dimmer is currently priced comparatively with other Zwave fan controllers that only have fan controls.  Available on Amazon Here.

A live stream is available showing the device -  View Live Stream on digiblurDIY

The switch will work with the Tuya Smartlife cloud app if you want to ride dangerously but as of this article if you attempt to use it via the Home Assistant Tuya integration, the dimmer and fan control entities will not show up.  So how do we control it?  We flash it with Tasmota of course!  Keep it all local control without the cloud! Unfortunately, at this time these devices are shipping with Tuya firmware that is blocking the current TuyaConvert exploit.  The switch will need to be flashed via the old school manual method.  Don't worry, this is fairly simple.  


Disconnect any power going to the device!  Remove the 4 screws and the face plate will come off.  There are no ribbon cables or wires to worry about.


The TYWE3S module containing the flash-able ESP8266 chip is wide out in the open.  There are multiple choices you can use to flash this chip with the 3v3 and GND headers.  Using a TTL USB adapter, you need to connect the following wires:  3v3 (do not use 5 volts!), Ground, RX, and TX.  GPIO 0 will also need to be attached to ground to enable flash mode on an ESP8266.  Instead of soldering, if you have a 3D printer you can also make a pogo pin jig as shown here and below.  Remember that RX goes TX and TX goes to RX on the USB TTL adapter.





Also, note you will need to put a jumper between NRESET and GND locations. This keeps the secondary TuyaMCU in a reset loop during the flashing of Tasmota.  Without this jumper the flashing process will not work.  





Once you've connected the necessary wires to your USB TTL device you can utilize Tasmotizer to flash the chip.  Additional information available on flashing Tuya devices can be found here in the Tasmota Wiki  Once flashed, disconnect GPIO 0 so it will boot up and add the Tasmota device to your network.

This TuyaMCU utilizes a baud rate of 115200 vs. previous dimmers and this requires Tasmota 8.3.1.6 or later!  Tasmotizer should be flashing 8.4.0 or later at this time.

It's all down hill after this...  click the Console button on the Tasmota GUI of the fan switch.  Issue the following commands.  Take note it will restart during many of the commands, wait for the console to somewhat settle down before issuing the next one.  

module 54
so97 1
tuyamcu 11,1
tuyamcu 12,9
tuyamcu 21,10
ledtable 0
dimmerrange 10,1000
so59 1
so68 0

Add the following rule, this should be all on ONE line.

Rule1 on TuyaReceived#Data=55AA03070005030400010016 do publish2 stat/%topic%/speed 3,0 endon
      on TuyaReceived#Data=55AA03070005030400010117 do publish2 stat/%topic%/speed 3,1 endon
      on TuyaReceived#Data=55AA03070005030400010218 do publish2 stat/%topic%/speed 3,2 endon
      on TuyaReceived#Data=55AA03070005030400010319 do publish2 stat/%topic%/speed 3,3 endon

Enable the rule with the following

Rule1 1



You can then add the necessary MQTT configuration, device name, etc and it should be safe to disconnect the wires, reassemble the switch and install it on the wall, on mains AC power to the fan.  You might be asking at this point "how do I control the fan speed from the GUI?"  You will need to utilize the following commands to send the fan speeds on the console

TuyaSend4 3,0  (fan speed 1)
TuyaSend4 3,1  (fan speed 2)
TuyaSend4 3,2  (fan speed 3)
TuyaSend4 3,3  (fan speed 4)

You can also send those over MQTT if you like from various automations using cmnd/topic/tuyasend4 with a payload of 3,0 , etc.  

Currently, at this time, we can not use MQTT Auto Discovery with this switch.  And also, one other drawback, Home Assistant does not support more than 3 fan speeds.  (Feature request anyone?)  In this sample config below, I've dropped fan speed #1 due to this.

If you already have a "fan" and "light" section do not duplicate the sections.  Don't forget to change the "treatfan" topic to the MQTT topic configured in your switch MQTT section.

fan:
  - platformmqtt
    name"Bedroom Fan"
    state_topic"stat/treatfan/POWER1"
    command_topic"cmnd/treatfan/POWER1"
    speed_state_topic"stat/treatfan/speed"
    speed_command_topic"cmnd/treatfan/tuyasend4"
    availability_topic"tele/treatfan/LWT"
    payload_available"Online"
    payload_not_available"Offline"    
    payload_on"ON"
    payload_off"OFF"
    payload_low_speed"3,1"
    payload_medium_speed"3,2"
    payload_high_speed"3,3"
    speeds:
      - low
      - medium
      - high

light:
  - platformmqtt
    name"Bedroom Light"
    state_topic"stat/treatfan/RESULT"
    value_template"{{ value_json.POWER2 }}"
    command_topic"cmnd/treatfan/POWER2"
    availability_topic"tele/treatfan/LWT"
    brightness_state_topic"stat/treatfan/RESULT"
    brightness_command_topic"cmnd/treatfan/Dimmer"
    brightness_scale100
    brightness_value_template"{{ value_json.Dimmer }}"
    payload_on"ON"
    payload_off"OFF"
    payload_available"Online"
    payload_not_available"Offline"



That's it!  Enjoy!  If you need help feel free to pop into Discord and ask for a hand.  



Links to products provided through the Amazon Affiliate program.






Comments

  1. I already have iFan03 in my ceiling fan, but never liked their remote control. Can I use this just as the switch on the wall that turns the fan/light on/off?

    ReplyDelete
  2. Thank you for sharing this! I wish I knew how to decode the different commands you shared to know what they're doing. How could I go about converting this info into a template like https://templates.blakadder.com/treatlife_SS01.html?

    ReplyDelete
    Replies
    1. No template needed for a TuyaMCU based switch. Just go to Configure Module then pick TuyaMCU. That's what the Module 54 command does.

      Delete
  3. Any idea why home assistant Tuya integration doesn't pick it up natively?

    ReplyDelete
    Replies
    1. From what I've heard a few times their API server isn't really supported anymore, like how RGB bulbs don't have color wheels on them. It really wouldn't surprise me if one day it all just stopped working. https://github.com/PaulAnnekov/tuyaha/issues/17

      Delete
  4. Q: where did you get the bin file for 8.3.1.6? When I pull latest as you have above, I get 8.3.1

    ReplyDelete
    Replies
    1. Off the Tasmota github page. "The Tasmota development codebase is checked every 1-2 hours for changes. If new commits have been merged and they compile successfuly, new binary files for every variant will be posted at http://thehackbox.org/tasmota/ (this web address can be used for OTA updates too). "

      Delete
    2. I could not get the FW to update either at first. What I ended up doing was downloading tasmota.bin.gz and tasmota-minimal.bin.gz (make sure to use the .gz packed mapfile) to my computer from http://thehackbox.org/tasmota/ and then uploading them via the web interface. I had to upload the minimal binary first, then when that upgrade was complete I was able to upload the main binary. I did some reading and it seems to be related to binary size. Not sure why the method mentioned in this write-up works for some but not others.

      Delete
    3. Great job on the sleuthing. It is supposed to flash minimal for you via OTA and then flash the full bin all automatically with the OTA upgrade option.

      Of course you can use the manual method. And just to document this anyone else reading, only flash the minimal version if the device is on your network with Tasmota already.

      If you are doing manual upgrades and get the buffer miscompare error which means not enough space. What I do is download the tasmota-lite.gz file. Flash that one. Then download the gz of the next one I need and it's just a little bit safer. Why? tasmota-lite contains the access point mode if something goes really weird in the middle. The minimal bin does not have access point mode.

      Delete
  5. This worked GREAT. About 1 hour after I had the Jigs in hand, I had my TreatLife Fan control / dimmer on Tasmota and had it connected to Home Assistant.

    I had to gently rock the jig the first time to get it to connect, then it remained solid. My first flash was tasmota-lite. I could not upgrade within Tasmota to the full version (memory error) but then flashed from Tasmotizer again to full tasmota version 8.3.1.7.

    ReplyDelete
    Replies
    1. Nice work! Tasmota should automatically handle the OTA 2 step flash to the development version. But yes, if you are using the manual BIN upload it's not a bad idea to send over lite first then the full tasmota.bin of the development version. With 8.3.x you can also use the .gz files too. I had an issue with Tasmotizer crashing if I tried to send the development build over first so I tried to keep it simple and all GUI for folks as much as possible.

      Delete
  6. Follower all the steps in your procedure and after the manual flash the chip is stuck in a bootloop. See the log below.
    I flashed it with tasmota 8.4 .bin file .
    https://github.com/arendst/Tasmota/releases/download/v8.4.0/tasmota.bin

    -------------- CUT HERE FOR EXCEPTION DECODER ---------------

    ets Jan 8 2013,rst cause:2, boot mode:(3,7)

    load 0x4010f000, len 3456, room 16
    tail 0
    chksum 0x84
    csum 0x84
    v0cc1cc0b
    ~ld

    --------------- CUT HERE FOR EXCEPTION DECODER ---------------

    Exception (0):
    epc1=0x4026de40 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

    >>>stack>>>

    ctx: sys
    sp: 3fffe5b0 end: 3fffffb0 offset: 0190
    3fffe740: 40105cec 40105ce9 00000000 00000000
    3fffe750: 400005e1 00000000 00000000 00000000
    3fffe760: 4026de40 00000033 00000020 00000000
    3fffe770: 40105cf2 04000102 00000000 00000001
    3fffe780: fbf8ffff 04000002 3feffe00 00000100
    3fffe790: 0000001e 00000018 04000102 40105cd4
    3fffe7a0: 3fffc100 3ffeed40 00000000 00000000

    ReplyDelete
    Replies
    1. The lite and minimal also give out the same error.

      I have tried the erase flash option using tasmotizer-1.1a but the same error log comes up.

      Delete
    2. How are you powering and receiving this log? I have had this issue on other chips where the power supply wasn't enough to boot Tasmota via the USB flasher. Have you tried letting it boot via the mains unit itself with no wires connected?

      Delete
    3. I am powering up via TTL USB adapter. Its getting 3.3V from the USB adapter. I have connected Teraterm and getting this log when the switch boots up. I don't think I can get the log with the main's connected.

      If i download the .gz file and extract the tasmota.bin file from it will it make any difference compared to downloading the tasmota.bin directly from web?

      Is there a way to force the .gz file on to the chip instead of the .bin file?

      Delete
    4. @digiblurDIY you were correct. After I flashed with Tasmota lite and power up via mains everything seems to be working. Thanks For your help :)

      Delete
    5. Awesome! And I do hope you upgraded off of lite to the regular bin. I don't recall if Lite supports TuyaMCU or not.

      Delete
  7. Followed your instructions and they worked perfectly. Thank you for putting this together!

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Hallo. I am struggling with wemos. I'm sending a signal from wemos 1 to wemos 2. wemos 2 turns on relay 1 and no 2. I guess it's the fault of the wifi. I have another question if it is possible to communicate with tasmota to tasmota without a router. If the routar network disappears, is it possible to connect to tasmota 1 and 2. Is it possible to send to several tasmota without a router, turn off the light. thank you.

    ReplyDelete
  10. How could I use this switch to control 2 lights? a dimmable one and a regular one?
    Any advice greatly appreaciated.

    ReplyDelete
  11. Struggling to get Tasmota on. I have soldered the wires onto the chip as you show, and connected everything to a USB serial adapter. When I use Tasmotizer, it says 'Failed to connect to ESP8266: Timed out waiting for packet header'. I know the module is getting power because it lights up, but I'm not sure what else to check. This is my first time trying to flash something with Tasmota, so I'm sure I'm missing something, just not sure what to check. Thanks so much for your help.

    ReplyDelete
    Replies
    1. After getting this error multiple times I figured out that if the switch was on it would fail the usb port causing a disconnect. Finally got them flashed by ensuring that there were no green lights lighting up when connecting the power.

      Delete
  12. I want to use this switch with my Ifan03. My fan has light and there is only one wire going to the fan from my switchboard.I think the old switch controlled the fan and light via RS433. I will like to use the switch just as a wifi switch that sends the commands to Ifan03 to toggle light and fan on/off with three fan speeds.

    I am not sure about the commands that I need to setup on both switch and the Ifan03. I am also using home assistant to control my other devices.

    Currently both Ifan03 and the switch are added to HA as MQTT devices.
    Kind of want the setup you showed with Martin Jerry dimmer and Ifan03.
    Just one switch instead of two seprate switches.

    Can you help me out with the commands/rules to make it work?

    ReplyDelete
  13. How do you get the feedback from the physical dimmer when it is pressed? It doesn't appear to be in the commands you listed.

    ReplyDelete
    Replies
    1. The TuyaMCU should send it over and Tasmota processes it as dimmer states. That is in the setup above.

      Delete
    2. It's odd. It isn't updating Tasmota dimmer side when the physical + and - buttons are pressed. Weblog 4 shows the TuyaReceived when they are pressed. Not sure why Tasmota doesn't update despite the TuyaMCU 21,10 command. I ran so66 1 and am getting it via the TuyaReceived catch all tele/topic/RESULT in the meantime. Controlling from GUI works fine and shows correct status but just not when physical + and - buttons are pressed. Everything else seems to be working fine. Dimmer range from using the weblog 4 though should be 100 to 1000 which is my only change to the instructions. Thanks for the tutorial!

      Delete
    3. Hi Artekus,

      I ran into the same issue as you with the physical buttons not updating tasmota. Please check rule 1 to ensure you replaced "%topic%" with your actual topic name. Once I did that it resolved the issue.

      Delete
  14. First off thank you for the tutorial and the jig. I got the unit flashed with Tasmota 8.5.1. I'm running into so issues with getting the unit in Home assistant. I manually added the device using the config.yaml file after enabling MQTT on Hass.io and configuring the username and password. However when I go to view the two new objects fan.master_bedroom_fan and light.master_bedroom_light under entity in the UI I get the following error.

    This entity does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

    My question is how do I control the switch objects from HomeAssistant

    ReplyDelete
    Replies
    1. You should be able to just click them and control them, turn them off, set the speed, set the dimming level etc. That error is normal for entries put into YAML manually as you aren't using the GUI to configure the name and such.

      When you see

      This entity does not have a unique ID, therefore its settings cannot be managed from the UI
      Text
      this simply means that you can’t change the entity_id or the friendly name from the UI. You can still use the Customizations menu to customize that entity. Typically you’ll see this when you create entities using YAML.

      Delete
    2. Thank you, so i just testing both objects by using the Homeassistant services and am able to turn on and off the fan and light. Along with setting the speed and brightness. However when I manually push the buttons on the lightswitch it does not update in homeassistant. Yet when I do it from the tasmota webui it does update in homeassistant.

      Anythoughts on why this is?

      Delete
    3. Nevermind, it must be late my brain wasnt functioning correctly. I just blindly copied rule1 instead of modifying it to replace "%topic%" with my actual topic name. I have a feeling this is the same issue as the person above me.

      Delete
    4. Tasmota replaces the topic variable with the topic of the switch automatically.

      Delete
    5. In my case it did not. When pressing the physical button I was not seeing any feedback in the console or in home assistant. After updating rule one as noted before everything is now working correctly.

      Delete
    6. There must have been some other issue with the rule as I use the topic variable all the time. Great feature as it allows copying the same rule to multiple devices.

      Delete
  15. I just tried to OTA Tuya-convert my treat life SS01 3-way switches but found that it wouldn't work due to the new firmware. So I am trying to flash via hard wire. I opened up the switch and found the TYWE3S but am concerned about he soldered pins that don't match up to what I have seen. Is there any way to send you a pic of my board to show you what I am seeing? Thanks for all of the good info and videos.

    ReplyDelete
    Replies
    1. Pretty standard chip there. I even use one in this example video of no soldering method. https://youtu.be/imKZbhJ8lvU You can always email me at the channel name on the gmail domain or hit me up on the discord chat links on the videos.

      Delete
    2. THANK YOU! That is so awesome - just what I was looking for. I guess I was confused as on that switch, it looks as if the tx and rx pins weren't soldered to the board. I am going to order up those things and flash them over.

      Delete

Post a Comment

Popular posts from this blog

Tuya Convert 2.3 Update | Flash Tuya Smartlife Devices | No Soldering! | Remove the cloud | Custom Firmware

How to use the Sonoff Zigbee Bridge with Home Assistant

Tuya Convert 2 - Flash Tuya Smartlife Devices - No Soldering - Remove the cloud with Tasmota ESPHome