Unable to import a tasmotized Sonoff into Home Assistant via ESPHome

I am trying to import a Tasmotized sonoff basic r2 into Homeassistant (HA) via ESPHome. Using the ESPHome function built into HA.

I am using Migrating from Sonoff Tasmota — ESPHome I am not using Hassio and have tried to guess how to do it in my HA running in a Virtual box on a Win 10 PC using this: Home Assistant on Windows using VirtualBox GUIDE - YouTube

The device, livingroom light, appears in the HA ESPHome display:
livingroomlight
Filename: livingroomlight.yaml
EDIT VALIDATE UPLOAD LOGS
I used the sample configuration provided here: Using With Sonoff Basic — ESPHome

livingroomlight.yaml
esphome:
name: livingroomlight
platform: ESP8266
board: esp01_1m

wifi:
ssid: “XXXX”
password: “XXXXXXXXXX”

api:

logger:

ota:

binary_sensor:

  • platform: gpio
    pin:
    number: GPIO0
    mode: INPUT_PULLUP
    inverted: True
    name: “Sonoff Basic Button”
    on_press:
    • switch.toggle: relay

switch:

  • platform: gpio
    name: “Sonoff Basic Relay”
    pin: GPIO12
    id: relay

status_led:
pin:
number: GPIO13

After executing Validation, the following errors were reported:

Logger: homeassistant.setup
Source: util/async_.py:139
First occurred: 10:23:12 AM (1 occurrences)
Last logged: 10:23:12 AM
Error during setup of component sonoff
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/setup.py”, line 242, in _async_setup_component
result = await task
File “/config/custom_components/sonoff/init.py”, line 53, in async_setup
hass.data[DOMAIN] = Sonoff(hass, config)
File “/config/custom_components/sonoff/init.py”, line 100, in init
self.do_login()
File “/config/custom_components/sonoff/init.py”, line 175, in do_login
r = requests.post(‘https://{}-api.coolkit.cc:8080/api/user/login’.format(self._api_region),
File “/usr/local/lib/python3.8/site-packages/requests/api.py”, line 119, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/api.py”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/sessions.py”, line 542, in request
resp = self.send(prep, **send_kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/sessions.py”, line 655, in send
r = adapter.send(request, **kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/adapters.py”, line 439, in send
resp = conn.urlopen(
File “/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py”, line 699, in urlopen
httplib_response = self._make_request(
File “/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py”, line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File “/usr/local/lib/python3.8/site-packages/urllib3/connection.py”, line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File “/usr/local/lib/python3.8/http/client.py”, line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/usr/local/lib/python3.8/http/client.py”, line 1266, in send_request
self.putrequest(method, url, **skips)
File “/usr/local/lib/python3.8/site-packages/urllib3/connection.py”, line 214, in putrequest
return HTTPConnection.putrequest(self, method, url, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 150, in protected_loop_func
check_loop()
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 139, in check_loop
raise RuntimeError(
RuntimeError: I/O must be done in the executor; Use await hass.async_add_executor_job() at custom_components/sonoff/init.py, line 175: r = requests.post(‘https://{}-api.coolkit.cc:8080/api/user/login’.format(self._api_region),

Log Details (WARNING)
Logger: homeassistant.util.async_
Source: util/async_.py:131
First occurred: 10:23:12 AM (1 occurrences)
Last logged: 10:23:12 AM
Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sonoff doing I/O at custom_components/sonoff/init.py, line 175: r = requests.post(‘https://{}-api.coolkit.cc:8080/api/user/login’.format(self._api_region),

At this point I am not sure what needs revision. The following additional is provided. Please advise what I need to correct.

The Tasmota data for the device follows:
Sonoff Basic Module
livingroomlight
Program Version 9.3.1(tasmota)
Build Date & Time 2021-03-09T16:12:28
Core/SDK Version 2_7_4_9/2.2.2-dev(38a443e)
Uptime 0T00:25:00
Flash write Count 58 at 0xFA000
Boot Count 15
Restart Reason Power On
Friendly Name 1 Living Room Light

AP1 SSId (RSSI) ASUS (66%, -67 dBm)
Hostname tasmota_0DF888-6280
MAC Address C4:DD:57:0D:F8:88
IP Address (wifi) 192.168.1.11


Gateway 192.168.1.1
Subnet Mask 255.255.255.0
DNS Server 192.168.1.1

MQTT Host
MQTT Port 1883
MQTT User DVES_USER
MQTT Client DVES_0DF888
MQTT Topic tasmota_%06X
MQTT Group Topic 1 cmnd/tasmotas/
MQTT Full Topic cmnd/tasmota_0DF888/
MQTT Fallback Topic cmnd/DVES_0DF888_fb/
MQTT No Retain Disabled

Emulation Belkin WeMo

ESP Chip Id 915592
Flash Chip Id 0x144051
Flash Size 1024 kB
Program Flash Size 1024 kB
Program Size 593 kB
Free Program Space 408 kB
Free Memory 27.0 kB

Configuration files
Configuration.yaml

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Text to speech

tts:

  • platform: google_translate
    group: !include groups.yaml
    automation: !include automations.yaml
    script: !include scripts.yaml
    scene: !include scenes.yaml
    homeassistant:
    auth_providers:
    • type: homeassistant

SonOFF Devices

sonoff:
username: XXXXXXXXXXXXXXX
password: XXXXXXXXXX
scan_interval: 60
grace_period: 600
api_region: ‘us’
entity_prefix: True #(optional)
debug: False #(optional)

Livingroomlight.yaml
esphome:
name: livingroomlight
platform: ESP8266
board: esp01_1m

wifi:
ssid: “XXXX”
password: “XXXXXXXXXX”

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Livingroomlight Fallback Hotspot”
password: “DRoKmyZlUqw8”

captive_portal:

Enable logging

logger:

Enable Home Assistant API

api:
password: “XXXXXXXXXX”
ota:
password: “XXXXXXXXXX”

HA Install info
Home Assistant 2021.4.6
Path to configuration.yaml: /config
System Health
Version core-2021.4.6
Installation Type Home Assistant OS
Development false
Supervisor true
Docker true
Virtual Environment false
Python Version 3.8.7
Operating System Family Linux
Operating System Version 5.4.109
CPU Architecture x86_64
Timezone America/Chicago
Home Assistant Cloud
MANAGE
Logged In false
Reach Certificate Server ok
Reach Authentication Server ok
Reach Home Assistant Cloud ok
Home Assistant Supervisor

MANAGE
Host Operating System Home Assistant OS 5.13
Update Channel stable
Supervisor Version supervisor-2021.04.0
Docker Version 19.03.15
Disk Total 97.7 GB
Disk Used 3.8 GB
Healthy true
Supported true
Board ova
Supervisor API ok
Version API ok
Installed Add-ons Mosquitto broker (5.1.1), File editor (5.2.0), ESPHome (1.16.2), TasmoAdmin (0.14.1), Duck DNS (1.12.5), Samba share (9.3.1)
Lovelace

MANAGE
Dashboards 1
Resources 0
Mode auto-gen

Hay Bro Please format you message correctly

esphome:
name: livingroomlight
platform: ESP8266
board: esp01_1m

wifi:
ssid: “XXXX”
password: “XXXXXXXXXX”

api:

logger:

ota:

binary_sensor:

platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: “Sonoff Basic Button”
on_press:
switch.toggle: relay
switch:

platform: gpio
name: “Sonoff Basic Relay”
pin: GPIO12
id: relay
status_led:
pin:
number: GPIO13

we can see what you have done wrong.

As @myle says, your config is impossible to read.

However you seem to be trying to use the sonoff integration instead of esphome. Why?

Sorry for the format issue. I used the format button before submitting the issue, but it did not seem to change anything. Is there a better way to do it?

Yes. See How to help us help you - or How to ask a good question

The Sonoff had been migrated to Tasmota previously using Tasmotizer. I was following Migrating from Sonoff Tasmota — ESPHome to migrate the tasmotized Sonoff to ESPHome which is embedded in Homeassistant. Once there it is recognized by HA.

So all is ok now?

Not at all. I included the error messages which I hope can identify the problem.

The error I can see is related to the sonoff custom component which has no place when you are using esphome,

Are you saying that I should not be migrating a Tasmotized Sonoff into HA via ESPHome? If so, how should I do it?
I tried using a Sonoff to HA without Tasmotize. but it requires a HACS component not available via the Windows virtualbox installation.

I did not and would not say that.

I am saying that the errors I am seeing relate to the sonoff custom component, e.g.

Also this puzzles me

I assume you mean validation in esphome. But validation is only the first step. Have you actually flashed the esphome generated firmware to the sonoff?

And it is hard helping you when you still haven’t formatted your code.

This is how switched from tasmota to esphome.

I compiled the new bin files using esphome (do not try to flash, just download)
Open the webpage of the tasmota device, hit update firmware (and use the bin file previously compiled with esphome)

Yes, the plan was to upload the new bin from ESPhome by using the Tasmota upgrade as you have suggested here. The problem was that validation of the new code in ESPHome was never completed due to the errors list in the original post.

Thanks for your input.

I should have said that during validation errors occurred that prevented validation from completing.

I am a little confused regarding the error in “custom _components” ???
ESPhome has nothing to do with custom_components, and for sure not one called sonoff…

What happens when you delete the sonoff folder from custom _components ??

Also weird…i run Ha supervised under a virtual machine (HyperV on W10), and i do no have issues with running HACS…

What are the validation errors? You haven’t posted them.

In my post I attached the following errors/warnings

Logger: homeassistant.setup
Source: util/async_.py:139
First occurred: April 24, 2021, 7:34:54 PM (1 occurrences)
Last logged: April 24, 2021, 7:34:54 PM

Error during setup of component sonoff
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/setup.py”, line 242, in _async_setup_component
result = await task
File “/config/custom_components/sonoff/init.py”, line 53, in async_setup
hass.data[DOMAIN] = Sonoff(hass, config)
File “/config/custom_components/sonoff/init.py”, line 100, in init
self.do_login()
File “/config/custom_components/sonoff/init.py”, line 175, in do_login
r = requests.post(‘https://{}-api.coolkit.cc:8080/api/user/login’.format(self._api_region),
File “/usr/local/lib/python3.8/site-packages/requests/api.py”, line 119, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/api.py”, line 61, in request
return session.request(method=method, url=url, **kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/sessions.py”, line 542, in request
resp = self.send(prep, **send_kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/sessions.py”, line 655, in send
r = adapter.send(request, **kwargs)
File “/usr/local/lib/python3.8/site-packages/requests/adapters.py”, line 439, in send
resp = conn.urlopen(
File “/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py”, line 699, in urlopen
httplib_response = self._make_request(
File “/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py”, line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File “/usr/local/lib/python3.8/site-packages/urllib3/connection.py”, line 234, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File “/usr/local/lib/python3.8/http/client.py”, line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File “/usr/local/lib/python3.8/http/client.py”, line 1266, in send_request
self.putrequest(method, url, **skips)
File “/usr/local/lib/python3.8/site-packages/urllib3/connection.py”, line 214, in putrequest
return HTTPConnection.putrequest(self, method, url, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 150, in protected_loop_func
check_loop()
File "/usr/src/homeassistant/homeassistant/util/async
.py", line 139, in check_loop
raise RuntimeError(
RuntimeError: I/O must be done in the executor; Use await hass.async_add_executor_job() at custom_components/sonoff/init.py, line 175: r = requests.post(‘https://{}-api.coolkit.cc:8080/api/user/login’.format(self._api_region),

Log Details (WARNING)

Logger: homeassistant.util.async_
Source: util/async_.py:131
First occurred: April 24, 2021, 7:34:54 PM (1 occurrences)
Last logged: April 24, 2021, 7:34:54 PM

Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for sonoff doing I/O at custom_components/sonoff/init.py, line 175: r = requests.post(‘https://{}-api.coolkit.cc:8080/api/user/login’.format(self._api_region),

One additional warning was found but not posted before:

Logger: homeassistant.components.recorder
Source: components/recorder/init.py:707
Integration: Recorder (documentation, issues)
First occurred: April 24, 2021, 7:34:52 PM (1 occurrences)
Last logged: April 24, 2021, 7:34:52 PM

Ended unfinished session (id=47 from 2021-04-24 15:23:11.234832)

That is all the notifications on this issue. I have viewed the notes about formatting code, but am unsure how that relates to this. If you could edit a portion of this to illustrate, I would be grateful to comply.

I renamed the custom_components folder which contained sonoff and sonoff-debug folders. Upon restart of HA I got only this error
Log Details (ERROR)
Logger: homeassistant.setup
Source: setup.py:164
First occurred: 4:31:13 PM (1 occurrences)
Last logged: 4:31:13 PM

Setup failed for sonoff: Integration not found.

If I left the custom_components folder intact, but renamed the sonoff and sonoff-debug folders, the following errors were reported:

`Log Details (ERROR)
Logger: homeassistant.components.hassio
Source: components/hassio/init.py:486
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: 4:37:14 PM (1 occurrences)
Last logged: 4:37:14 PM

Component error: sonoff - Integration ‘sonoff’ not found. Log Details (ERROR)
Logger: homeassistant.setup
Source: setup.py:164
First occurred: 4:31:13 PM (1 occurrences)
Last logged: 4:31:13 PM

Setup failed for sonoff: Integration not found.`