I have 4 of these devices: https://templates.blakadder.com/treatlife_SS01S.html. I was originally going to flash them with tasmota but after reading up on ESPHome, I think I want to go that route instead. If they are compatible with tasmota firmware via a template, does that mean its compatible with ESPHome? I cracked open the case to see if I could research anything on the chip but this area of tech is new to me and I’m getting a bit lost. How can I tell what Platform and board type to use in my configs? Appreciate someone pointing me in the right direction!
I did a search for “esphome TYWE3S” and came up with:
platform: ESP8266
board: esp01_1m
In this issue:
Then that is what I will try! thanks for the help. For future purchases, is there a way to self identify easily/easier?
Other than Google? Not that I know of.
There’s a board reference here but it does not list Tuya modules like the one you have:
http://docs.platformio.org/en/latest/platforms/espressif8266.html#d-systems
Hi,
This is working with my tuya switch (2 way) with this config:
esphome:
name: switch_tuya2_1
platform: ESP8266
board: esp01_1m
wifi:
ssid: "xxx"
password: "xxx"
# Enable logging
logger:
level: VERBOSE
# Enable Home Assistant API
api:
ota:
Figure it out? I have the same switch and trying to figure out the proper esphome ‘switch:’ values.
In the past I used this info to work out the GPIO used in the Tasmota template and put that into ESPhome
I temporarily gave up. I was having issues getting the devices to flash (if my memory is correct on the issue). Its still on my list, but I’m tackling other more important HA tasks.
Still perfecting it, but here is my esphome template for the treatlife switch: https://gist.github.com/MACscr/3472d7b3bdad9676f6ef4faf1dd775ee
Works great so far. Don’t really have the LED fully figured out, but i can turn the switch on and off and i even have a home assistant automation to turn the switch (a bathroom fan in my case) off after 60 minutes if its on.
Any tips on how you were able to flash ESPhome onto the switch in the first place?
I followed used the tuya convert method. Definitely need to have all the right parts and some patience, but once you get it all setup, it only takes a few minutes per device.
Below is my esphome Treatlife light switch, copy and paste yaml.
My code turns the white led on when the switch is off and, led off when the switch is on. The code uses the led pins state as a power sense, to determine whether to turn the relay on or off.
I have provided two different versions, one is for a simple on and off smart switch and the other, gives event triggers to use in home assistant automations (like turning all the lights off when double pressed or, turning curtain lights on when long pressed).
Update: updated the code a little, added an ESPhome flashing how to, some code to convert the switch to a light in home assistant and, an automation that works with event triggers.
Flashing guide:
As far as flashing goes, there are two main ways. One is a solderless wifi exploit and the other requires you to pop the cover off the switch and solder wires either directly to the chip or to some sort of rig, to be able to program the chip.
—OPTION ONE—
Wifi exploit -
Providing power 120VAC:
Two options, either replace the wall light switch with the new smart switch to power it or, do like I did and cut the end off of an old computer power cord, wire nuts and, use a power strip to turn it on and off. The second method makes it easier to program several in a short amount of time (just make sure you label the switch once it is flashed).
To get the firmware need for your switch:
Go to your ESPhome instance, copy and paste whichever flavor of code you want to a yaml file and upload it the your ESPhome directory or, copy and paste it into the ESPhome editor. With your code input and saved. Click the 3 dots on the right of the box, then select compile. Once it has finished it will give you an option to download the firmware. Download the bin file and rename it to firmware.bin. If you are using the method above to upload it, then move the firmware file to the appropriate directory on the raspberry pi.
Uploading the code:
Once you have power to the switch, I recommend using this method the tuya wifi exploit for flashing your firmware to it. After the exploit has completed, if your firmware is in the correct directory it will show up as an option to upload to your device.
It sounds like a lot of work but, trust me it is much easier once it is setup to upload code for multiple devices than the solder option is.
—OPTION TWO—
Solder / Pogo Pin Jig option-
This option is for those who don’t mind doing it manually or are unable to use the Wifi exploit method. I have done both, I much rather prefer the Wifi exploit. Then option however does provide the advantage of being able to upload your code direct through the ESPhome interface over tty/usb.
Accessing the controller board:
Use a pry tool (flat tip screwdriver or other flat pry tool) to release the tabs holding the outer case on. (Be careful some treatlife switches use header pins to connect the control board to the power and switch board). Pull up as straight as you can to separate the two pieces. There where 4 screws holding my control board in. With the screws removed you should be able to see the blue ESP chip.
Connecting to the controller board:
Solder wires either directly to the chip or, if you chose to, the pogo pin jig. Just remember this is a 3.3v chip. Once the wires are connected, connect the other side of the wires to an FTDI programer, set to 3.3v.
Chip FTDI
GND - GND
3.3v - VCC
GPIO 0 - GND (not only to get into programming mode but also while programming)
RX - TX
TX - RX
Uploading the code:
Once connect plug the FTDI board into a usb port of the computer hosting the ESPhome instance and change the upload method from OTA to whichever usb device appears, in the top right corner of the screen. Then simply upload your code, verify it connected to your network then, disconnect power, unsolder / remove jig, screw the control board back into the top, snap the two pieces together and that’s it you’re done. (simple)
# ##################################
# Treatlife Light Switch
# ##################################
# D2 GPIO04: white led (inverted) (sensor)
# D1 GPIO05: red led (inverted)
# D6 GPIO12: relay
# D7 GPIO13: button (inverted)
# ##################################
substitutions:
device_name: treatlife_light_switch #change
friendly_name: Treatlife Light Switch #change
icon: "mdi:light-switch"
esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${device_name}
password: !secret esphome_ap_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret esphome_api_password
ota:
password: !secret esphome_ota_password
status_led:
pin:
number: GPIO5 # Red LED
inverted: True
binary_sensor:
- platform: gpio
pin:
number: GPIO4
inverted: True
id: sensor
internal: True
- platform: gpio
pin:
number: GPIO13
inverted: True
id: button
name: ${friendly_name} Button
on_press:
- switch.toggle: ${device_name}
internal: True
light:
- platform: binary
id: white_led
output: led_1
restore_mode: RESTORE_DEFAULT_ON
internal: True
output:
- platform: gpio
id: led_1
pin:
number: GPIO4
inverted: True
switch:
- platform: gpio
pin: GPIO12
id: relay
restore_mode: RESTORE_DEFAULT_OFF
- platform: template
name: ${friendly_name}
id: ${device_name}
icon: ${icon}
lambda: |-
if (id(sensor).state) {
return false;
} else {
return true;
}
turn_on_action:
- if:
condition:
binary_sensor.is_on: sensor
then:
- switch.turn_on: relay
- light.toggle: white_led
turn_off_action:
- if:
condition:
binary_sensor.is_off: sensor
then:
- switch.turn_off: relay
- light.toggle: white_led
# ##################################
# Treatlife Light Switch
# ##################################
# D2 GPIO04: white led (inverted) (sensor)
# D1 GPIO05: red led (inverted)
# D6 GPIO12: relay
# D7 GPIO13: button (inverted)
# ##################################
substitutions:
# https://esphome.io/guides/configuration-types.html#substitutions
device_name: treatlife_light_switch #change
friendly_name: Treatlife Light Switch #change
icon: "mdi:light-switch"
esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${device_name}
password: !secret esphome_ap_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret esphome_api_password
ota:
password: !secret esphome_ota_password
status_led:
# https://esphome.io/components/status_led
pin:
number: GPIO05 # Red LED
inverted: True
binary_sensor:
- platform: gpio
pin:
number: GPIO4
inverted: True
id: sensor
internal: True
- platform: gpio
pin:
number: GPIO13
inverted: True
id: button
name: ${friendly_name} Button
on_multi_click:
# Single Click:
- timing:
- ON for at most 1s
- OFF for at least 0.3s
then:
- switch.toggle: ${device_name}
- logger.log: "Single Short Clicked"
- homeassistant.event:
event: esphome.${device_name}
data:
title: single_click
# Double Click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
- homeassistant.event:
event: esphome.${device_name}
data:
title: double_click
# Long Click:
- timing:
- ON for 1s to 2s
- OFF for at least 0.3s
then:
- logger.log: "Single Long Clicked"
- homeassistant.event:
event: esphome.${device_name}
data:
title: long_click
- timing:
- ON for at least 2.2s
then:
- logger.log: "Click and Hold"
- homeassistant.event:
event: esphome.${device_name}
data:
title: hold
internal: True
light:
- platform: binary
id: white_led
output: led_1
restore_mode: RESTORE_DEFAULT_ON
internal: True
output:
- platform: gpio
id: led_1
pin:
number: GPIO4
inverted: True
switch:
- platform: gpio
pin: GPIO12
id: relay
restore_mode: RESTORE_DEFAULT_OFF
- platform: template
# https://esphome.io/components/switch/template.html
name: ${friendly_name}
id: ${device_name}
icon: ${icon}
lambda: |-
if (id(sensor).state) {
return false;
} else {
return true;
}
turn_on_action:
- if:
condition:
binary_sensor.is_on: sensor
then:
- switch.turn_on: relay
- light.toggle: white_led
turn_off_action:
- if:
condition:
binary_sensor.is_off: sensor
then:
- switch.turn_off: relay
- light.toggle: white_led
The below code turns it from a basic switch into a light. For use with the voice activated home assistant of your choice.
light:
- platform: switch
name: Treatlife Light Switch
entity_id: switch.treatlife_light_switch
And finally the automation that works with the event triggers stated above
automation:
- alias: treatlife_long_press_on
trigger:
- event_data:
title: long_click
event_type: esphome.treatlife_light_switch
platform: event
condition: []
action:
- entity_id: group.all_lights
service: light.turn_on
mode: single
- alias: treatlife_double_click_off
trigger:
- event_data:
title: double_click
event_type: esphome.treatlife_light_switch
platform: event
condition: []
action:
- entity_id: group.all_lights
service: light.turn_off
mode: single
Hi Philip,
Thanks for your config, it’s a great time saver !
you should really upload it to ESPHome Device Configuration Repository
Tom
How did you work out which GPIO was for what?
Started here treatlife_SS02 to see which pins where used. Then cut an old computer power cord to use as a way to connect it to mains voltage while I was testing it.
Quick update!
If you are using the template I had posted above, I have sense changed it for two reasons.
One - the switches started power cycling when trying to trigger the double tap event.
Two - I wanted to move away from the controls being a switch, and move it over to a light entity.
Disclaimer: If you have previously uploaded the switch template. After uploading the below template, you will need to delete the esphome integration for each one, “Also delete the switch to light templating in HA (if it was used), if not it will change the entity_id of the new device once found”.
Then do a server control reboot, it should find all of the devices again.
This template below will show up in HA as a light, and not a switch.
Basic config
substitutions:
device_name: treatlife_light_switch #change
friendly_name: Treatlife Light Switch #change
esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${device_name}
password: !secret esphome_ap_password
captive_portal:
logger:
api:
password: !secret esphome_api_password
ota:
password: !secret esphome_ota_password
status_led:
pin:
number: GPIO5 # Red LED
inverted: True
binary_sensor:
- platform: gpio
id: sensor
pin:
number: GPIO4
inverted: True
internal: true
- platform: gpio
id: button
pin:
number: GPIO13
inverted: True
on_press:
- light.toggle: ${device_name}
internal: True
light:
- platform: binary
id: white_led
output: led_1
internal: True
- platform: binary
id: ${device_name}
name: ${friendly_name}
output: relay
on_turn_on:
if:
condition:
lambda: |-
if (id(sensor).state) {
return true;
} else {
return false;
}
then:
- output.turn_on: relay
- light.turn_off: white_led
on_turn_off:
if:
condition:
lambda: |-
if (id(sensor).state) {
return false;
} else {
return true;
}
then:
- output.turn_off: relay
- light.turn_on: white_led
output:
- platform: gpio
id: led_1
pin:
number: GPIO4
inverted: True
- platform: gpio
id: relay
pin:
number: GPIO12
Multi-press config
substitutions:
device_name: treatlife_light_switch #change
friendly_name: Treatlife Light Switch #change
esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${device_name}
password: !secret esphome_ap_password
captive_portal:
logger:
api:
password: !secret esphome_api_password
ota:
password: !secret esphome_ota_password
status_led:
pin:
number: GPIO5 # Red LED
inverted: True
binary_sensor:
- platform: gpio
id: sensor
pin:
number: GPIO4
inverted: True
internal: True
- platform: gpio
id: button
pin:
number: GPIO13
inverted: True
on_multi_click:
# Single Press:
- timing:
- ON for at most 1s
- OFF for at least 0.3s
then:
- light.toggle: ${device_name}
- logger.log: "Single Short Press"
- homeassistant.event:
event: esphome.${device_name}
data:
title: single_click
# Double Click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
- homeassistant.event:
event: esphome.${device_name}
data:
title: double_click
# Long Press:
- timing:
- ON for 1s to 2s
- OFF for at least 0.3s
then:
- logger.log: "Single Long Press"
- homeassistant.event:
event: esphome.${device_name}
data:
title: long_press
- timing:
- ON for at least 2.2s
then:
- logger.log: "Press and Hold"
- homeassistant.event:
event: esphome.${device_name}
data:
title: hold
internal: True
light:
- platform: binary
id: white_led
output: led_1
internal: True
- platform: binary
id: ${device_name}
name: ${friendly_name}
output: relay
on_turn_on:
if:
condition:
lambda: |-
if (id(sensor).state) {
return true;
} else {
return false;
}
then:
- output.turn_on: relay
- light.turn_off: white_led
on_turn_off:
if:
condition:
lambda: |-
if (id(sensor).state) {
return false;
} else {
return true;
}
then:
- output.turn_off: relay
- light.turn_on: white_led
output:
- platform: gpio
id: led_1
pin:
number: GPIO4
inverted: True
- platform: gpio
id: relay
pin:
number: GPIO12
Thank you for this code. I have a question with regard to the led light
Im using my switch to turn on an AC instead of a light and having the LED indicator being revered is really annoying. Is there anyway I can get this switch to have the LED indicator on when the relay is on?
I do apologize for taking sometime to respond. I made the changes you were looking for, led on when switch is on and off when switch is off. It is using the name scheme with - instead of _
Switch
# ##################################
# SS02 Light Switch
# ##################################
# D2 GPIO04: white led (inverted) (sensor)
# D1 GPIO05: red led (inverted)
# D6 GPIO12: relay
# D7 GPIO13: button (inverted)
# ##################################
substitutions:
device_name: single_pole_test #change
friendly_name: single_pole_test #change
icon: "mdi:light-switch"
esphome:
name: single-pole-test #change
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# use_address: 10.0.0.19 #change
ap:
ssid: ${device_name}
password: !secret esphome_ap_password
captive_portal:
logger:
api:
password: !secret esphome_api_password
ota:
password: !secret esphome_ota_password
status_led:
pin:
number: GPIO5 # Red LED
inverted: True
binary_sensor:
- platform: gpio
id: sensor
pin:
number: GPIO4
inverted: True
internal: true
- platform: gpio
pin:
number: GPIO13
inverted: True
id: button
on_press:
then:
- switch.toggle: ${device_name}
internal: True
output:
- platform: gpio
id: white_led
pin:
number: GPIO4
inverted: True
switch:
- platform: gpio
pin: GPIO12
id: relay
restore_mode: RESTORE_DEFAULT_OFF
internal: True
- platform: template
name: ${friendly_name}
id: ${device_name}
icon: ${icon}
lambda: |-
if (id(sensor).state) {
return true;
} else {
return false;
}
turn_on_action:
- if:
condition:
binary_sensor.is_off: sensor
then:
- switch.toggle: relay
- output.turn_on: white_led
turn_off_action:
- if:
condition:
binary_sensor.is_on: sensor
then:
- switch.toggle: relay
- output.turn_off: white_led
Light
# ##################################
# SS02 Light Switch
# ##################################
# D2 GPIO04: white led (inverted) (sensor)
# D1 GPIO05: red led (inverted)
# D6 GPIO12: relay
# D7 GPIO13: button (inverted)
# ##################################
substitutions:
device_name: single_pole_test #change
friendly_name: single_pole_test #change
icon: "mdi:light-switch"
esphome:
name: single-pole-test #change
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# use_address: 10.0.0.19 #change
ap:
ssid: ${device_name}
password: !secret esphome_ap_password
captive_portal:
logger:
api:
password: !secret esphome_api_password
ota:
password: !secret esphome_ota_password
status_led:
pin:
number: GPIO5 # Red LED
inverted: True
binary_sensor:
- platform: gpio
id: sensor
pin:
number: GPIO4
inverted: True
internal: true
- platform: gpio
id: button
pin:
number: GPIO13
inverted: True
on_press:
- light.toggle: ${device_name}
internal: True
light:
- platform: binary
id: ${device_name}
name: ${friendly_name}
output: relay
on_turn_on:
if:
condition:
lambda: |-
if (id(sensor).state) {
return false;
} else {
return true;
}
then:
- output.turn_on: relay
- output.turn_on: white_led
on_turn_off:
if:
condition:
lambda: |-
if (id(sensor).state) {
return true;
} else {
return false;
}
then:
- output.turn_off: relay
- output.turn_off: white_led
output:
- platform: gpio
id: white_led
pin:
number: GPIO4
inverted: True
- platform: gpio
id: relay
pin:
number: GPIO12