Yes, Chris is correct. You’ll have to use tuya-convert to replace the factory firmware. tuya-convert ‘out of the box’ includes a tasmota binary, but you don’t have to use it - you can add whatever firmware images you want to tuya-convert/files. When tuya convert runs, it asks you which of the images in that directory it should use.
For devices I’m confident of the Pin out - and hence the ESPHome configuration I do the following…
- Create a device specific config in ESPHome - compile and download to my local machine
- Fire up my Tuya-Convert machine (for me a Raspberry Pi 2b! with wifi usb stick) - check both raspbian and tuya convert are fully updated
- Upload the compiled binary from (1) to the tuya conver files directory (via Filezilla and SSH)
- Follow the Tuya-convert instructions to flash the device. For most of the dim/switch modules I use - the easiest way is to avoid powering them on until the Tuya Convert AP is up and I have another device attached. At that point, power the device and normally it is discovered immediately.
- Tuya convert gives me the option of using my uploaded ESPHome device specific binary .Once uploaded,…wait a moment and power cycle (not strictly necessary but I prefer to)
- Watch it turn green in ESPHome and connect to the logs…
Honestly quicker to do, than type !
For a new device that I am unsure of the configurations/pins, I will go to tasmota first as I find that quicker to change/experiment with pin assignments. Once happy, I write my ESPhome config, compile and download. Then upload via tasmota upgrade (noting you need Tasmota 7.2 or earlier to allow a non-Tasmota binary to be uploaded.)
(I see that Tasmota may have added a run time option to allow 8+ to use a non-tasmota binary to upload via web… “If you are using Tasmota 8+ and get an error after uploading the firmware, go to the console and type SetOption78 1
, then restart the device and try the firmware again.” - Not something I’ve tried}
Thanks, this worked perfectly.
One question, I am not sure what the below section does. It adds a button to HA which when pressed turned on the red light on the switch.
- platform: gpio
id: ${switch_id}_out_led_red
name: "${switch_id} Touch Status Led Red"
pin: GPIO13
inverted: True
restore_mode: ALWAYS_OFF
I think I have figured it. Within the Switch
section, I think it needs an internal: true
to internalise the switch and not expose to HA.
- platform: gpio
pin: GPIO13
inverted: yes
internal: true
id: ${switch_id}_out_led_red
name: "${switch_id} Touch Status Led Red"
restore_mode: ALWAYS_OFF
Then, to get the lights to go blue when on and red when off, it needs switch.turn_off: ${switch_id}_out_led_red
and switch.turn_on: ${switch_id}_out_led_red
added.
name: "${switch_id} Template 1"
id: ${switch_id}_template1
internal: true
lambda: |-
if (id(${switch_id}_out_relay1).state) {
return true;
} else {
return false;
}
on_state:
- if:
condition:
- binary_sensor.is_on: ${switch_id}_template1
then:
- switch.turn_on: ${switch_id}_out_led
- switch.turn_off: ${switch_id}_out_led_red
- if:
condition:
- binary_sensor.is_off: ${switch_id}_template1
then:
- switch.turn_off: ${switch_id}_out_led
- switch.turn_on: ${switch_id}_out_led_red```
Would you be able to share your yaml file (with sensitive information left out) please? I want to make sure I’ve got mine correct since I’m having trouble getting esphome to OTA flash the plug.
When you flashed with tuya-convert do you update to a specific firmware version or just the one in the files directory?
I had to use tasmota-minimal v7.2 to enable the upload of an esphome firmware to Tasmota
So I’ve made some progress and cleared up a few issues I had in my head when it came to how all this fits together.
I’ve managed to get the esphome bin file flashed onto the plug:
esphome:
name: plug1
comment: 2Nice UP111 01 - Hall
platform: ESP8266
board: esp01_1m
wifi:
ssid: ""
password: ""
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
password:
time:
- platform: homeassistant
substitutions:
# Unique ID for Sensors.
switch_id: "plug_01"
binary_sensor:
# Push Button
- platform: gpio
id: ${switch_id}_in_switch1
internal: true
pin: GPIO3
name: " Switch 1"
filters:
- invert:
on_click:
min_length: 50ms
max_length: 350ms
then:
- switch.toggle: ${switch_id}_out_relay1
# Template Sensor - Tracks Relay, Switches LED to Match (Internal Only)
- platform: template
name: "${switch_id} Template 1"
id: ${switch_id}_template1
internal: true
lambda: |-
if (id(${switch_id}_out_relay1).state) {
return true;
} else {
return false;
}
on_state:
- if:
condition:
- binary_sensor.is_on: ${switch_id}_template1
then:
- switch.turn_on: ${switch_id}_out_led
- switch.turn_off: ${switch_id}_out_led_red
- if:
condition:
- binary_sensor.is_off: ${switch_id}_template1
then:
- switch.turn_off: ${switch_id}_out_led
- switch.turn_on: ${switch_id}_out_led_red
switch:
# Restart Switch in HA
- platform: restart
name: "${switch_id} Restart"
# Relay Output
- platform: gpio
pin: GPIO14
id: ${switch_id}_out_relay1
name: "${switch_id} Relay 1"
# Blue LED Output
- platform: gpio
pin: GPIO1
internal: true
id: ${switch_id}_out_led
inverted: yes
name: "${switch_id} Touch Status Led"
- platform: gpio
id: ${switch_id}_out_led_red
name: "${switch_id} Touch Status Led Red"
pin: GPIO13
inverted: True
internal: true
restore_mode: ALWAYS_OFF
sensor:
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO04
cf1_pin: GPIO05
# Higher value gives lower watt readout
current_resistor: 0.0025
# Lower value gives lower voltage readout
voltage_divider: 880
current:
name: "${switch_id} energy_temp_Amperage"
unit_of_measurement: A
voltage:
name: "${switch_id} energy_temp_Voltage"
unit_of_measurement: V
power:
name: "${switch_id} energy_temp_Wattage"
unit_of_measurement: W
id: "energy_temp_Wattage"
change_mode_every: 8
update_interval: 10s
- platform: total_daily_energy
name: "${switch_id} energy_temp_Total Daily Energy"
power_id: "energy_temp_Wattage"
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
unit_of_measurement: kWh
# Extra sensor to keep track of plug uptime
- platform: uptime
name: ${switch_id} energy_temp_Uptime Sensor
# Wifi Signal
- platform: wifi_signal
name: "${switch_id} WiFi Signal Sensor"
update_interval: 60s
This includes @SimplyGardner led changes above which work really well.
My last issue and probably the one more important to me is getting it controllable within HA at the moment I have two entities defined by the plug (binary_sensor.plug1
and binary_sensor.plug1_button
) neither of which let me control it from the dashboard. I’d really like to get this working in the UI so any help would be awesome.
My config is
esphome:
name: washing_machine_plug
platform: ESP8266
board: esp8285
wifi:
ssid: ""
password: ""
logger:
api:
ota:
binary_sensor:
- platform: gpio
pin:
number: GPIO3
inverted: True
name: "Power Button"
on_press:
- switch.toggle: relay
switch:
- platform: gpio
id: led
pin: GPIO1
- platform: gpio
name: "Washing Machine Plug"
pin: GPIO14
id: relay
on_turn_on:
- switch.turn_on: led
on_turn_off:
- switch.turn_off: led
sensor:
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO04
cf1_pin: GPIO05
current_resistor: 0.00221
voltage_divider: 871
current:
name: "Washing Machine current"
unit_of_measurement: A
voltage:
name: "Washing Machine Voltage"
unit_of_measurement: V
power:
name: "Washing Machine Wattage"
unit_of_measurement: W
id: "energy_temp_Wattage"
change_mode_every: 8
update_interval: 10s
which gives me 5 entities in HA -
I bought a pack of gosund up111 from amazon and flashed them several months ago fine. I bought 4 more last week, 2 flashed, 1 stuck with the intermediate firmware and 1 goes off when you start the flashing process… all very odd
the newer ones have a raised part on the pins
I know this was requests for plugs and not sockets. Have flashed these sockets with esphome, and they look nicer than plugs. Do cost a bit more though, but the USB charger comes in handy.
I know this was requests for plugs and not sockets. Have flashed these sockets with esphome, and they look nicer than plugs. Do cost a bit more though, but the USB charger comes in handy.
Same here, I got mine from ebay:
I can vouch for these. Flashed via serial, haven’t tried tuya-convert. Without practice they’re hard to open without damaging them. If I was going to fault anything with them it would just be the width - You can’t get them side by side on the average trailer socket. I haven’t tried on a two gang wall socket but reckon that would be tight also. Great for the price.
New to energy monitoring plugs though and just used the calibration settings here but on a 2kW heater they report 2150W where my TP-Link plug gives 2250W. Something I plan on investigating further at some point. Does anyone know, would the calibration settings be different for all Maxcio units, or are they just one size fits all/specific to certain chips?
Gosund UP111 (same as 2Nice) are great also. Got mine on Amazon, 4 for £25 a couple weeks ago. Used tuya-convert as they looked tricky to get into without damaging them, worked great. 13A rated but as I’ve not opened them I haven’t seen the internals.
Much better form factor though than the Maxcios; they’ll go in trailer sockets side by side and don’t obscure switches.
I’ve got four of these UP111 smart plugs and they work very well with home assistant. I’ve taken the code from @mikebell above and added a couple of lambda expressions to show apparent power and power factor. I’m wondering if its possible to make the red led flash quickly if the plug loses wifi signal? So far it seems ok. Anyway, this is my current code:
esphome:
name: plug1
comment: 2Nice UP111 01
platform: ESP8266
board: esp01_1m
wifi:
ssid: ""
password: ""
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
time:
- platform: homeassistant
substitutions:
# Unique ID for Sensors.
switch_id: "plug_04"
binary_sensor:
# Push Button
- platform: gpio
id: ${switch_id}_in_switch1
internal: true
pin: GPIO3
name: " Switch 1"
filters:
- invert:
on_click:
min_length: 50ms
max_length: 350ms
then:
- switch.toggle: ${switch_id}_out_relay1
# Template Sensor - Tracks Relay, Switches LED to Match (Internal Only)
- platform: template
name: "${switch_id} Template 1"
id: ${switch_id}_template1
internal: true
lambda: |-
if (id(${switch_id}_out_relay1).state) {
return true;
} else {
return false;
}
on_state:
- if:
condition:
- binary_sensor.is_on: ${switch_id}_template1
then:
- switch.turn_on: ${switch_id}_out_led
- switch.turn_off: ${switch_id}_out_led_red
- if:
condition:
- binary_sensor.is_off: ${switch_id}_template1
then:
- switch.turn_off: ${switch_id}_out_led
- switch.turn_on: ${switch_id}_out_led_red
switch:
# Restart Switch in HA
- platform: restart
name: "${switch_id} Restart"
# Relay Output
- platform: gpio
pin: GPIO14
id: ${switch_id}_out_relay1
name: "${switch_id} Relay"
# Blue LED Output
- platform: gpio
pin: GPIO1
internal: true
id: ${switch_id}_out_led
inverted: yes
name: "${switch_id} Touch Status Led"
- platform: gpio
id: ${switch_id}_out_led_red
name: "${switch_id} Touch Status Led Red"
pin: GPIO13
inverted: True
internal: true
restore_mode: ALWAYS_OFF
sensor:
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO04
cf1_pin: GPIO05
# Calibration
current_resistor: 0.0025 # Value of shunt resistor in ohms (higher value gives lower watt readout)
voltage_divider: 880 # Resistance ratio of internal voltage divider resistors (lower value gives lower voltage readout)
# Other person has:
#current_resistor: 0.00221
#voltage_divider: 871
current:
name: "${switch_id} Current"
unit_of_measurement: A
id: "energy_temp_Amperage"
voltage:
name: "${switch_id} Voltage"
unit_of_measurement: V
id: "energy_temp_Voltage"
power:
name: "${switch_id} Power"
unit_of_measurement: W
id: "energy_temp_Wattage"
change_mode_every: 8
update_interval: 10s
- platform: total_daily_energy
name: "${switch_id} Total Daily Energy"
power_id: "energy_temp_Wattage"
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
unit_of_measurement: kWh
- platform: template
name: "${switch_id} Apparent Power"
unit_of_measurement: VA
lambda: return id(energy_temp_Voltage).state * id(energy_temp_Amperage).state;
- platform: template
name: "${switch_id} Power Factor"
lambda: return id(energy_temp_Wattage).state / (id(energy_temp_Voltage).state * id(energy_temp_Amperage).state);
Hi,
I have tried the following and would comment as follows:
Sonoff Basic flashed with Tasmota - not strictly a plug but probably the cheapest option for more permanent installations.
Sonoff S20/S26 flashed with Tasmota - although these are on the large size they are good value and work great. The S26 is a little bit harder to flash as it requires some soldering.
Sonoff S26 with with Sonoff LAN HACS Integration - works but I have experienced some problems in local mode when external access is blocked in my firewall (external DNS queries and regular reconnections to my WiFi but it still seems to work fine).
Meross MSS210 - works well with the Merross Cloud IOT HACS Integration (but obviously not local).
Teckin SP27 via the Tuya Integration - initially tried to flash these with Tuya Convert but it failed as they do not use an ESP8266 chip. I think I found them to be a bit tempromental when I originally tried them so they are not currently used (also not local).
Gosund UP111 flashed with Tasmota using Tuya Convert - these are my favourites as they are small, include power monitoring, and I picked up a pack of 4 for only £29.99 including delivery on the Amazon UK website.
To keep this up to date - I’ve just Tuya Converted another batch of 4 of the round 2Nice plugs from Amzon, QS-WIFI-D01-TRIAC dimmers, QS-WIFI-S03 and QS-WIFI-S04-2C switch modules , from Ali Express.
2Nice plugs with power monitoring
QS-WIFI-D01-TRIAC Dimmers
QS-WIFI-S03 Switch modules and QS-WIFI-S04-2C Dual Switch module
Just to keep the story going, as there’s a worry that these devices are moving away from flashable ESP8266-type devices, I’ve just received and flashed two of the UP111-4 plugs from this Amazon listing.
One went straight through the tuya-convert
process with no issues to a basic Tasmota firmware which I then upgraded to ESPHome (with Setoption 78 1
needed on the interim Tasmota firmware to allow the upgrade: see here).
The second device was a bit more troublesome but converted in the end: not sure what the difference was. Just one of those things.
Both are now live in my Home Assistant and ESPHome dashboard and working well.
+1 for the Gosund plugs. A four pack is currently £36 but the price varies a lot. I picked up some just before Xmas for £25.50 (though you can see they have been as low as £24)
No issues Tasmota’ing them, though occasionally a sticky one needs a couple of tries
As a long term Tasmota/mqtt user I have never really looked at ESPHome. What are the advantages?
Everyone will have their own views. I started with Tasmota/MQTT and moved to ESPHome because I like the flexibility you can build in with the EPSHome YAML. E.g. a specific plug for our Iron that has always turns off after an hour to avoid it being left on. I had some devices with sperate MCU dimmers that ESPHome enabled me to talk to (tasmota has since had these added natively). I have some devices with built in automations (Sonoff mini that controls an extractor fan and has some logic detecting a connected water flow meter… I have used ESPHome to create a very custom multiway switch panel with addressable LED indicator lights that read status back from HA. Similarly an esp32 running ESPHome that reads my old alarm PIRs and emulates an Alarm.
The more basic customisations could almost certainly be done with Tasmota scripts but I didnt find them very user friendly.The more complex ones really use quite a lot of ESPHome’s automation with and ability to include snippets of actual C code to complete some functions.
If possible I try and keep specific automations local to the relevant device - rather back everything off to HA. So if there is a server issue as much as possible continues to “just work” until HA is back.
I invariably use Tasmota though when looking at new devices to very quickly cycle through different pin combinations - and to load as a generic firmware that then allows me to connect, add wifi etc and then OTA change to ESPHome in some cases.
On the downside of ESPHome - I do get duplicated devices sometimes and changing IP address can be a nightmare if you dont get the process right.
Sometimes the native HA API connection feels quicker than MQTT but I have never measured or attempted to quantify if that is actually the case. If the “out of the box” functionality is there in Tasmota and works the way you want it, there may be little reason to change.
Also thanks for updates on the Gosund plugs. Always great to know there are current options avaialble.