Replacing Tasmota firmware with EsphomeLib

So… I’m getting sick of how bad Tasmota 6.4.1.x is with disconnections and am having compilation failures with using 2.3.0 core as well so pretty sick of it all.

Looking at replacing with ESPHomeLib…

So I have some S22 switches (functionally identical to the S20’s) and I am using this YAML file here:

esphome:
  name: s22_sonoff3_0898
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: 'myssid'
  password: 'mypass'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
- platform: gpio
  pin:
    number: GPIO0
    mode: INPUT_PULLUP
    inverted: True
  name: "S22 Sonoff 3 Button"
  on_press:
    - switch.toggle: relay
- platform: status
  name: "S22 Sonoff 3 Status"


switch:
- platform: gpio
  name: "S22 Sonoff 3 Relay"
  pin: GPIO12
  id: relay

output:
- platform: esp8266_pwm
  id: s20_green_led
  pin: GPIO13
  inverted: True

light:
- platform: monochromatic
  name: "S22 Sonoff 3 Green LED"
  output: s20_green_led

This then creates:
image
In the integrations.

With Tasmota, if I press the front button, the switch comes on (as it does with ESP) but the ‘green led’ would also come on with Tasmota but in ESP it stays off. With Tasmota, both LED’s come on when the switch is on. If the switch isn’t connected to the MQTT broker, the blue one (green led) will flash.

Can I set the switch to turn on/off both LED’s with ESPEasy when I toggle the switch?

Second Question… For a Sonoff SV, I want to have a momentary switch that will turn off after 2 seconds. Otto referred me to this code here:

# Example configuration entry
switch:
  - platform: gpio
    pin: 25
    id: relay
  - platform: template
    name: "Gate Remote"
    icon: "mdi:gate"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay

I add that to the above as so:

esphome:
  name: s22_sonoff3_0898
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: 'ssid'
  password: 'pass'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "S22 Sonoff 3 Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "S22 Sonoff 3 Status"

switch:
  - platform: gpio
    name: "S22 Sonoff 3 Relay"
    pin: GPIO12
    id: relay
  - platform: gpio
    pin: 25
    id: relay
  - platform: template
    name: "S22 Sonoff 3 Momentary"
    icon: "mdi:flash"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 2000ms
    - switch.turn_off: relay

output:
- platform: esp8266_pwm
  id: s20_green_led
  pin: GPIO13
  inverted: True

light:
- platform: monochromatic
  name: "S22 Sonoff 3 Green LED"
  output: s20_green_led

When I try and upload, I get an error:
INFO Reading configuration…
Failed config

switch.gpio: [source /config/esphome/s22_sonoff3_0898.yaml:34]
  platform: gpio
  
  ESP8266: Invalid pin number: 25. Got '25'
  pin: 25
  id: relay

How do I fix this?

If I put this in for the switch:

switch:
  - platform: gpio
    name: "S22 Sonoff 3 Relay"
    pin: GPIO12
    id: relay
  - platform: template
    name: "S22 Sonoff 3 Momentary"
    icon: "mdi:flash"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 2000ms
    - switch.turn_off: relay

I then get another switch that does turn on and then off after 2 seconds… but it still has the slider in home assistant as ON (for both the relay and the momentary switch even though the switch is actually off)

image

Switch shows as on but is actually OFF

[15:24:13][D][switch:031]: 'S22 Sonoff 3 Momentary' Turning ON.
[15:24:13][D][switch:031]: 'S22 Sonoff 3 Relay' Turning ON.
[15:24:13][D][switch:055]: 'S22 Sonoff 3 Relay': Sending state ON
[15:24:15][D][switch:035]: 'S22 Sonoff 3 Relay' Turning OFF.
[15:24:15][D][switch:055]: 'S22 Sonoff 3 Relay': Sending state OFF

try changing your ID as per the docs:

  • … must start with a letter and can end with numbers.
  • … must not have a space in the name.
  • … can not have special characters except the underscore (“_“).
  • … must not be a keyword.

One thing I noticed is that Otto’s examples don’t actually follow these rules…:man_facepalming: But it might be worth a try. I have a momentary switch just like your one and it works fine, the nly thing I see differenent is that my ID’s are S1, S2 etc. so they follow the above rules

It’s an S a letter

I meant where you have id: relay It might not be the fix but worth a try

Copied from his github here https://github.com/esphome/esphome-docs/blob/current/devices/sonoff_s20.yaml
I think the very top name has those restrictions but everything else seems ok… It also compiles and is working except for the above…

Do yours switch both the LED’s on like Tasmota?

I know my example is not the S22 or S22, but here is what I use the the Sonoff TH16, formatting may help.

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
    inverted: false
dallas:
  - pin: GPIO14
  
sensor:
  - platform: dallas
    address: 0x75041783A35DFF28
    name: "Fish Tank Temperature"

yeah… I copied of his github and have respaced it properly but no difference. It validates and uploads fine.

Doing some reading now. As I am looking at getting a few S22s myself.

To answer this question, yes.

In my example above:

status_led:
  pin:
    number: GPIO13
    inverted: false

Would appear this is the same GPIO for the Sonoff TH16 and S22/S20
This should keep you status light on, and blink off if there is an issue.

My momentary switch is on a NodeMCU, no LED’s in my situation so can’t help on that one

@sparkydave

You can use:

status_led:
  pin:
    number: GPIO2
    inverted: False

If you wish to use the built in led on the nodemcu.

Yeah, I’m aware of that however I simply have no use for it as the NodeMCU is inside a weatherproof enclosure outside the house. I was really only trying to help with the momentary switch dilemma as that’s the only thing I have experience with relating to the OP’s questions

Righto :slight_smile:

all good :grinning:

@DavidFW1960

This should work.

esphome:
  name: s22_sonoff3_0898
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: 'ssid'
  password: 'pass'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "S22 Sonoff 3 Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "S22 Sonoff 3 Status"

switch:
  - platform: gpio
    name: "S22 Sonoff 3 Relay"
    pin: GPIO12
    id: relay
  - platform: template
    name: "S22 Sonoff 3 Momentary"
    icon: "mdi:flash"
    turn_on_action:
      switch.turn_on: relay
      delay: 2000ms
      switch.turn_off: relay

output:
  - platform: esp8266_pwm
    id: s20_green_led
    pin: GPIO13
    inverted: True

light:
  - platform: monochromatic
    name: "S22 Sonoff 3 Green LED"
    output: s20_green_led

You had the below under the switch call, but it was already called:

  - platform: gpio
    pin: 25
    id: relay

Yeah hence the error with pin 25. But I tried that EXACT yaml and it

  1. Doesn’t turn the LED on/off when switch is on
  2. The switch doesn’t turn the toggle off in Home Assistant as per above screengrab

Sorry, can you try copy pasting the above again, just tinkering with the formatting a bit.

In particular:

    turn_on_action:
      switch.turn_on: relay
      delay: 2000ms
      switch.turn_off: relay

Removed the - before.

it is triggering the switch… it turns on for 2 seconds then off

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "S22 Sonoff 3 Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "S22 Sonoff 3 Status"

switch:
  - platform: gpio
    name: "S22 Sonoff 3 Relay"
    pin: GPIO12
    id: relay
  - platform: template
    name: "S22 Sonoff 3 Momentary"
    icon: "mdi:flash"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 2000ms
    - switch.turn_off: relay

output:
  - platform: esp8266_pwm
    id: s20_green_led
    pin: GPIO13
    inverted: True

light:
  - platform: monochromatic
    name: "S22 Sonoff 3 Green LED"
    output: s20_green_led

@DavidFW1960 I don’t see anything different between your code and mine below in relation to the momentary switch… mine definitely works in that I don’t even have the normal switch in the GUI, only the momentary one. If I turn the momentary one ON, it then turns itself (and the normal one) OFF after 30s. As I mentioned, the only difference is the id format.

  - platform: gpio
    name: "Retic Moisture Sensor Control"
    id: s3
    icon: mdi:water-percent
    pin:
      number: D3
      inverted: false
  - platform: template
    name: "Retic Moisture Test 30s"
    id: s4
    icon: mdi:water-percent
    optimistic: yes
    turn_on_action:
    - switch.turn_on: s3
    - delay: 30s
    - switch.turn_off: s3
    - switch.turn_off: s4 

Ok, I just read your latest post after writing this… so the momentary is all good now?