Magichome devices work PERFECT with homeassistant (reflash this code with ESPHOME)

i read how everybody is pissed off at the cheap magichome devices not working correctly in homeassistant. eg: slow to respond, status is incorrectly polled etc

i’ve aquired a magichome to create some night-pee-light to fit under the bed that comes on at night when triggered by a xiaomi/aqara motion sensor and i had exactly the same problems.
those magichome devices run on ESP’s that are flashable with esphome.
the one i had had these connections.

all you have to do is solder some dupont wires to those solder pads, then connect them to your usb TTY serial programmer adapter.

the pin labeled 3.3v goes to the pin that carries 3.3v on the programmer
the pin labeled Ground goes to the Ground pin on the programmer
the pin labeled IO0 also goes to the Ground on the programmer
the pin labeled TX goes to the RX pin on the programmer
the pin labeled RX goes to the TX pin on the programmer

how the pins are wired depends on the programmer used.
you can either use a FTDI one which has pins protruding (that is why i recommended dupont wires)
or you can use another model which has a header.
before you connect anything make sure your USB serial adapter is set to 3.3v or you’ll blow things up.

the one with the pins looks like this:


(thank you frenck for the image, i also made your doorbell, i slightly modified it tho)
you can also use this example when you have a programmer with a header like this, pinout is the same:

then you’ll need to create a yaml file to flash to the magichome device.
Make sure you have ESPHOME installed on the device your using to flash the magichome controller, i used a raspberry for flashing.
i wrote this yaml code to create a simple binary monochromatic light (as my led is just a warm white strip), all you have to so is create a blank yaml file (name it something conventient) and then paste one of these codes in:

RGBW models

esphome:
  name: node_name
  platform: ESP8266
  board: esp8285

wifi:
  ssid: "Your SSID Here"
  password: "Your Wifi Password"

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "Your API Password"

ota:
  password: "Your OTA Password"
  

# this is code for the RGBW version of magichome 
light:
  - platform: rgbw
    name: Nice Friendly Name
    red: pwm_r
    green: pwm_g
    blue: pwm_b
    white: pwm_w

output:
  - platform: esp8266_pwm
    pin: GPIO12
    frequency: 1000 Hz
    id: pwm_r

  - platform: esp8266_pwm
    pin: GPIO5
    frequency: 1000 Hz
    id: pwm_g

  - platform: esp8266_pwm
    pin: GPIO13
    frequency: 1000 Hz
    id: pwm_b

  - platform: esp8266_pwm
    pin: GPIO15
    frequency: 1000 Hz
    id: pwm_w'

or use this code for the single color monochromatic version:

esphome:
  name: node_name
  platform: ESP8266
  board: esp8285

wifi:
  ssid: "Your SSID Here"
  password: "Your Wifi Password"

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "Your API Password"

ota:
  password: "Your OTA Password"
  

# this is code for the monochromatic version of magichome 
light:
  - platform: monochromatic
    name: Nice Friendly Name
    output: pwm1

output:
  - platform: esp8266_pwm
    id: pwm1
    pin: GPIO12
    frequency: 1000 Hz

all you have to do next is make sure that the usb to serial adapter is wired to your magichome device, and then plug it into your raspberry.
then just run: esphome your-yaml-file.yaml run
it’ll compile the firmware then ask if you want to flash it, select the option for serial and it will write the code.

it might hang at logging, but once it’s flashed you can break the process off.
disconnect the device from usb, then from the programmer, connect your strip and power the thing up.
if you have the discovery component active in HA it will show right up in the notifications and you can set it up right away.

once you’ve confirmed everything is working you can just desolder the wires and put the thing back in it’s casing. all done! you now have a perfect functioning wifi LED strip without all the laggy shit and problems.
:slight_smile:

code above came from https://everythingsmarthome.co.uk
i just modified it to fit my needs.

17 Likes

Try the H801. It’s bigger but can handle more current and larger voltage range.

Thanks for sharing this.

@poldim, does the h801 also use esp8266? I would assume so, but figured I should ask anyways.

Flashed two of the Magic Home devices today, works flawless.

Only thing that didnt worked is that after ESPhome OTA update the devices appeared offline in the ESPhome dashboard. Any suggestions?!

I havent configured OTA since these devices are single function, so flashing once with the tty serial programmer should be enough. If you figure it out please let me know

Compiled a new binary and flashed it OTA from the web interface, now back online, will try to OTA update from the dashboard later and see if its also working

Update: turns out that it is a mdns thing, now working with static ip

Btw how to get the IR remote working?

most MH devices are OTA flashable, so no soldering and ftdi required, give this a shot https://github.com/ct-Open-Source/tuya-convert

1 Like

Magic home are Arlux devices and they don’t appear kn the compatible devices list :man_shrugging:

aw snap I mixed those up with smarthome I think

I wrote a topic to share some written code done in esphome, then someone comes on telling to go use tuya. There’s a reason I didn’t went the tuya way.

Anyways, if you go to the esphome site and then the supporter devices and then check the sonoff list, you’ll find the MH devices and the gpio Pinouts including the IR, you’ll have to add those to the code. This code is written for the wifi only model.

Besides the fact I mixed up the 2 devices I was just contributing an additional way to flash ‘your’ (or any other) image since not everyone has ftdis and/or can solder. Since most tuya-based devices are vulnerable to this ota method of reflashing I felt it would just add to the topic.

2 Likes

I have a magichome with an IR remote. I’m tempted to flash it with esphome but I haven’t found anyone’s code who uses the IR remote. Any suggestions?

havent came across that either, however you can utilize the IR pin to make the controller a adressable controller which is way cooler :slight_smile:

btw you need to flip RX and TX if you want to write data -

No you do not need to flip the pins.
The only case when you need to do that is when they are mislabeled on the board which happens sometimes

That’s not true. You can even see it on the wiring schema you attached in your post.

Sorry i misread the post, theres indeed a typo in my original post.
i was initially confused because on some other esp devices the pins are flipped on the board itself
but that is not the case here, corrected it.

Thanks for the walkthrough! I just recently moved my Tuya devices to ESPHome, which fixed a bunch of my connectivity issues. Quite a while ago I bought a few MagicHome controllers but Home Assistant only really liked controlling one, and the other two were flaky even with the remote. This method seems to fixing all that though, and I don’t have to trash my 12v strips!

I figured out the IR remote details here in a new thread. Works great!

2 Likes

thrown away the remote, just working with Siri :slight_smile:
Anyways thx for the hint!

Thanks, the important principle here is that if HA goes down, my lighting should still be functional. Thanks for figuring it out for us!

1 Like