Migrate from Tasmota to ESPHome

Hi, I’m new to Hass, ESPHome and YAML and need some help to start.

I have a MagicHome UFO RGBW controller, which works fine with the latest tasmota firmware. But now I want to migrate to ESPHome.
Previously I used the tasmota template from Magic UFO RGBW LED Controller (26-011-945) Configuration for Tasmota
How do I “translate” this config to an esphome <device>.yaml?

My current configuration to create the *.bin file is the following:

esphome:
  name: led-controller-ufo-9f7c14
  platform: ESP8266
  board: esp8285

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "MagicUfo-9F7C14-Fallback"
    password: "espfallback"

captive_portal:

web_server:
  port: 80

# MagicHome UFO RGBW LED controller
light:
  - platform: rgbw
    name: "MagicHome 9F7C14"
    red: pwm_r
    green: pwm_g
    blue: pwm_b
    white: pwm_w

# general information
sensor:
  - platform: wifi_signal
    name: "WiFi Signal (RSSI)"
  - platform: uptime
    name: "Uptime"

# color output
output:
  # Red
  - platform: esp8266_pwm
    id: pwm_r
    pin: GPIO14
    frequency: 1000 Hz
  # Green
  - platform: esp8266_pwm
    id: pwm_g
    pin: GPIO5
    frequency: 1000 Hz
  # Blue
  - platform: esp8266_pwm
    id: pwm_b
    pin: GPIO12
    frequency: 1000 Hz
  # White
  - platform: esp8266_pwm
    id: pwm_w
    pin: GPIO13
    frequency: 1000 Hz

# TODO reset button: restart esp device or wifi
# binary_sensor:
#   - platform: gpio
#     pin: GPIO0
#     name: "Reset"

# LED: power - always on, no gpio (820R to 3V3)

# TODO LED: info
# status_led:
#   pin: GPIO15
#   id: state_info

# TODO LED: network
# status_led:
#   pin: GPIO2
#   id: state_link

I copied most of the code from the other MagicHome rgb controller and changed the pins. Is this correct?
How do I get the button and status leds to work?

  • The button shall reset the device or the wifi connection → doesn’t matter
  • network/link led shall be on, if connection ist established (bonus: flash while connecting)
  • info led shall be on, if … (configurable? e.g. mqtt connection or something)

Looks good to me. About the button - you can use the restart switch functionality and use the on_press method for the physical button to call it. Look here and here for inspiration.

For the status LED, I don’t think you can link it to network activity. It has a predefined function defined here and you cannot change that.

Thanks for your reply.
I added fast_connect: true to my config, because the wifi is hidden and removed the web_server section.
Then I tried flashing the binary file via esphomeflasher, but after restart the device does not connect to my network. I saw that esphomeflasher sets the clock to 40 MHz, but the board seems to operate at 26 MHz?

Serial port /dev/ttyUSB0
Connecting........___
Detecting chip type... ESP8266
Chip is ESP8285
Features: WiFi, Embedded Flash
Crystal is 26MHz
[..]

So I flashed this binary again with esptool:
esptool.py -b 460800 write_flash -e -ff 26m -fm dout -fs 1MB 0x00048000 magichome_ufo.bin
But even with that I had no success. The blue and red (GPIO2) LED are permanently on and no connection is established. The fallback WiFi is also not visible.

Am I doing something wrong?

Try and error helped :slight_smile:

Solution: I added

  platformio_options:
    board_build.f_flash: 26000000L

to my configuration and flashed again with esphomeflasher:
esphomeflasher -p /dev/ttyUSB0 --esp8266 magichome_ufo.bin

Looks like esphome is running now:

22:20:30][I][ota:102]: Boot seems successful, resetting boot loop counter.
[22:20:31][D][sensor:125]: 'WiFi Signal (RSSI)': Sending state -53.00000 dBm with 0 decimals of accuracy

Sadly, the device is still not running correctly at all:

The status_led flashes slowly (one time per second), but wifi signal is strong enough and it’s still connected.
The device is auto-discovered in hass, but if i try to connect to, it tells me, that my config shall include an api: line, but it does.
After 15 minutes the device automatically reboots due to a missing api connection:

[18:25:56][D][sensor:125]: 'Uptime': Sending state 876.98297 s with 0 decimals of accuracy
[18:26:17][D][sensor:125]: 'WiFi Signal (RSSI)': Sending state -51.00000 dBm with 0 decimals of accuracy
[18:26:24][E][api:123]: No client connected to API. Rebooting...
[18:26:24][I][app:127]: Forcing a reboot...
[18:26:24][W][wifi_esp8266:483]: Event: Disconnected ssid='removed' bssid=removed reason='Association Leave'
[18:26:24]
[18:26:24] ets Jan  8 2013,rst cause:1, boot mode:(3,0)
[..]

My configuration:

esphome:
  name: led-controller-ufo-9f7c14
  platform: ESP8266
  board: esp8285
  platformio_options:
    board_build.f_flash: 26000000L

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  power_save_mode: none

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "MagicUfo-9F7C14-Fallback"
    password: "espfallback"

captive_portal:

# ESP configuration:
# RGBW platform for MagicHome UFO LED controller
light:
  - platform: rgbw
    name: "MagicHome 9F7C14"
    red: pwm_r
    green: pwm_g
    blue: pwm_b
    white: pwm_w

# General information
sensor:
  - platform: wifi_signal
    name: "WiFi Signal (RSSI)"
  - platform: uptime
    name: "Uptime"

# Color output
output:
  # Red
  - platform: esp8266_pwm
    id: pwm_r
    pin: GPIO14
    frequency: 1000 Hz
  # Green
  - platform: esp8266_pwm
    id: pwm_g
    pin: GPIO5
    frequency: 1000 Hz
  # Blue
  - platform: esp8266_pwm
    id: pwm_b
    pin: GPIO12
    frequency: 1000 Hz
  # White
  - platform: esp8266_pwm
    id: pwm_w
    pin: GPIO13
    frequency: 1000 Hz

# TODO reset button: restart esp device or wifi
#binary_sensor:
#  - platform: gpio
#    pin: GPIO0
#    name: "Reset Button"

# LED: power - always on, no gpio (820R to 3V3)

# LED: info
status_led:
  pin:
    number: GPIO15
    inverted: yes
  id: state_info

# TODO LED: network (maybe from rssi value?)
#status_led:
#  pin:
#    number: GPIO2
#    inverted: yes
#  id: state_link

I already updated ESPHome, the binary, HassOS and restarted everything, but cannot connect anyway.

It’s because a warning in the log - most likely because their is no api connection

Good

bad. I read about this behauvior (bug?) in another thread these days :thinking:

You might wanna try to flash it “fresh” via serial and try again if you can add it to ha…

I saw the other thread about the same issue. I added a password to the api: section and now, hass can connect to the device without a problem. Maybe it’s a bug? The status_led is also not flashing anymore.
Only thing I have to correct is that green and red channel are interchanged (it’s a problem of wrong led stripe markings).

Back to the upper question about a link state led:

I added the onboard led:

binary_sensor:
  # Output: LED: network
  - platform: gpio
    pin:
      number: GPIO2
      inverted: yes
      mode: OUTPUT
    id: state_link
    internal: true

and tried to combine it with the wifi signal:

sensor:
  - platform: wifi_signal
    name: "WiFi Signal (RSSI)"
    id: wifi_rssi
    on_value_range:
      # bad signal, turn off
      - below: -90
        then:
          # how to set the GPIO pin? It's not an output
          - output.turn_off: state_link
      # weak signal, flash
      - above: -90
        below: -75
        then:
          - output.turn_on: state_link
          - delay: 500ms
          - output.turn_off: state_link
          - delay: 500ms
      # good signal, turn on
      - above: -75
        then:
          - output.turn_on: state_link

But output is the wrong keyword. How to set/unset the gpio output?

Edit: I found this and the set_pin() method. Is this the right way and how to use it in this context?

Does anybody know, how to use the binary_sensor as gpio output? All examples I found, only show the use as input. But how do i set a gpio pin to low or high?

by using a output component instead :tada:

Thx. Sometimes we overlook the obvious :slight_smile:

So my code was nearly working.