Additional Sonoff functionality with ESPHOME

Greetings all,

Last weekend I moved 4 wifi in wall light switches and three sonoff basics to ESPHOME using the native HA API. For the most part I’m loving it and the switches respond much faster than when they had Tasmota on them. When I had them with Tasmota, I could program in additional functionality such as a double tap and a long tap which would send a different MQTT message through. This allowed me to set up additional automations based on the type of press. Does anyone know if this type of functionality exists in ESPHOME?

See https://esphomelib.com/esphomeyaml/components/binary_sensor/index.html#on-click and the other triggers there

2 Likes

Thank you for the quick reply Otto and all of your hard work on this. I was able to get the double click and long click functionality working on my switches. I saw it mentioned somewhere that it’s in the works to have ability to use MQTT and the API simultaneously. Any idea when this will be available?

Hey could you share your ESPHomeYAML config file. Having a hard time flashing ESPHome.
Thanks.

@forums2012 I’m sure the formatting will be jacked, but you get the idea. This config has one click turn on whatever is plugged in to the Sonoff enabled extension cord. Two clicks turns a bedside lamp on and off (Zigbee bulb) and holding the button for more than a few seconds turns off every inside light in the house.

esphomeyaml:
  name: Ext_1
  platform: ESP8266
  board: esp01_1m
  board_flash_mode: dout

wifi:
  ssid: 'XXXXXX'
  password: 'XXXXXXXXXX'
  power_save_mode: none
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.0.228
    # Set this to the IP address of the router. Often ends with .1
    gateway: 192.168.0.1
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0
  
#mqtt:
#  broker: 192.168.0.69

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: 'XXXXXX'

ota:
  password: 'XXXXX'

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Ext1 Basic Button"
#    on_press:
#      - switch.toggle: relay
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 1s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: light.toggle
              data:
                entity_id: light.lamp
          - logger.log: "Double Clicked"
      - timing:
          - ON for 3s to 5s
          - OFF for at least 0.5s
        then:
          - homeassistant.service:
              service: light.turn_off
              data:
                entity_id: group.all_lights
          - logger.log: "Single Long Clicked"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - switch.toggle: relay
          - logger.log: "Single Short Clicked"
  - platform: status
    name: "Ext1 Status"

switch:
  - platform: gpio
    name: "Ext1 Basic Relay"
    pin: GPIO12
    id: relay
#  - platform: restart
#    name: "Ext1 Restart"

output:
  - platform: esp8266_pwm
    id: basic_green_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    name: "Ext1 Green LED"
    output: basic_green_led
1 Like

Hello
how do I enable PowerOnState (3) in ESPhome