Switched Sonoffs to esphome. Getting odd results

Greetings,

I flashed three Sonoff basics and four KULED WiFi switches with esphome firmware. For the most part, everything is working as expected, however I’ve noticed when the lights are on, every minute or two you here the relay click and the lights flicker. It’s as if a blip in WiFi causes the light to turn off and it recovers back to the last state. Everything shows up and functions properly in HA although you can see this light flicker in HA and in the device status.

Here is a sample yaml:
esphomeyaml:
name: guest_bathroom
platform: ESP8266
board: esp01_1m
board_flash_mode: dout

wifi:
ssid: XXXX
password: XXXX
manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.0.223
# 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: XXXX

ota:
password: XXXX

binary_sensor:

  • platform: gpio
    pin:
    number: GPIO0
    mode: INPUT_PULLUP
    inverted: True
    name: “Guest Bathroom”
    on_press:
    • switch.toggle: relay
  • platform: status
    name: “Guest Bathroom Status”

switch:

  • platform: gpio
    name: “Guest Bathroom Relay”
    pin: GPIO12
    id: relay
  • platform: restart
    name: “Guest Bathroom Restart”

output:

  • platform: esp8266_pwm
    id: basic_green_led
    pin:
    number: GPIO13
    inverted: True

light:

  • platform: monochromatic
    name: “Guest Bathroom Green LED”
    output: basic_green_led

This is the watchdog logic for MQTT and API.
For MQTT, if the ESP can’t connect to the broker within 5 minutes, it reboots.
For API, if no client (like Home Assistant) connects to the ESP within 5 minutes, it also reboots.

I think the issue here is that:
a) You disabled your MQTT broker after upgrading to native API?
b) You have Home Assistant configured to connect to the ESP via MQTT, not API. So then no client connects to the native API and thus the ESP reboots every 5 minutes.

(You can read all about the reason for this watchdog logic in the docs. Look for reboot_timeout)

Thanks for the quick response. I do have them set up to MQTT because I was getting mixed results when trying to use them via the API. Namely in HA when I would go to configure them, it keeps saying my password is invalid. Also, I can’t get to them via the .local address only by direct IP. Is the preferred method the native API and I should disable MQTT and figure out my issues?

I commented out the MQTT config and uploaded to the devices. I was then able to fully configure them in the Native API and all appears to be working as expected. Thank you for steering me in the right direction and thank you for all of your amazing work on this project!!!

1 Like

I also have odd results. I try to esplain: yesterday I update ESPHome from a previous version with MQTT autodiscovery to the last version with native API.

I already removed the mqtt section from yaml configuration and I used also the “clean-mqtt” command to remove any mqtt message on the broker, then restarted HA a couple of times.

HA correctly find the device by the integration panel, but it’s not reliable, because the device goes “unavailable” very often.

Also with the esphome dashboard I have same behaviour:

INFO Reading configuration...
INFO Starting log output from 192.168.6.137 using esphomelib API
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
INFO Successfully connected to 192.168.6.137
[10:26:42][I][application:097]: You're running esphomelib v1.10.1 compiled on Feb  5 2019, 22:47:00
[10:26:42][C][wifi:341]: WiFi:
[10:26:42][C][wifi:240]:   SSID: 'martinRoutero'
[10:26:42][C][wifi:241]:   IP Address: 192.168.6.137
[10:26:42][C][wifi:243]:   BSSID: 18:D6:C7:FC:F9:41
[10:26:42][C][wifi:245]:   Hostname: 'lampadaluigi'
[10:26:42][C][wifi:250]:   Signal strength: -83 dB ▂▄▆█
[10:26:42][C][wifi:251]:   Channel: 6
[10:26:42][C][wifi:252]:   Subnet: 255.255.255.0
[10:26:42][C][wifi:253]:   Gateway: 192.168.6.1
[10:26:42][C][wifi:254]:   DNS1: 0.0.0.0
[10:26:42][C][wifi:255]:   DNS2: 0.0.0.0
[10:26:42][C][binary_sensor.status:046]: Status Binary Sensor 'Lampada Luigi Status'
[10:26:42][C][binary_sensor.status:046]:   Device Class: 'connectivity'
[10:26:42][C][binary_sensor.gpio:023]: GPIO Binary Sensor 'Lampada Luigi Button'
[10:26:42][C][binary_sensor.gpio:024]:   Pin: GPIO0 (Mode: INPUT_PULLUP, INVERTED)
[10:26:42](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[10:26:42][C][output.esp8266_pwm:028]: ESP8266 PWM:
[10:26:42][C][output.esp8266_pwm:029]:   Pin: GPIO13 (Mode: OUTPUT, INVERTED)
[10:26:42][C][output.esp8266_pwm:030]:   Frequency: 1000.0 Hz
[10:26:42][C][logger:099]: Logger:
[10:26:42][C][logger:100]:   Level: VERBOSE
[10:26:42][C][logger:101]:   Log Baud Rate: 115200
[10:26:42][C][light.state:266]: Light 'Lampada Luigi Green LED'
[10:26:42][C][light.state:268]:   Default Transition Length: 1000 ms
[10:26:42][C][light.state:269]:   Gamma Correct: 2.80
[10:26:42](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[10:26:42][C][switch.restart:034]:   Icon: 'mdi:restart'
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
WARNING Couldn't connect to API (Error connecting to 192.168.6.137: timed out). Trying to reconnect in 1 seconds
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
WARNING Couldn't connect to API (Error connecting to 192.168.6.137: timed out). Trying to reconnect in 2 seconds
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 4 seconds
WARNING Disconnected from API.
WARNING Couldn't connect to API (Already connected!). Trying to reconnect in 8 seconds
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
WARNING Couldn't connect to API (Error connecting to 192.168.6.137: timed out). Trying to reconnect in 1 seconds
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 2 seconds
WARNING Disconnected from API.
WARNING Couldn't connect to API (Already connected!). Trying to reconnect in 4 seconds
WARNING Disconnected from API.
WARNING Couldn't connect to API (Already connected!). Trying to reconnect in 8 seconds
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
INFO Successfully connected to 192.168.6.137
[10:28:02][D][api:241]: 'Home Assistant 0.86.4 (192.168.6.245)' disconnected.
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
INFO Successfully connected to 192.168.6.137
[10:28:09][V][api:500]: Hello from client: 'Home Assistant 0.86.4 (192.168.6.245)'
[10:28:09][D][api:531]: Client 'Home Assistant 0.86.4 (192.168.6.245)' connected successfully!
WARNING Disconnected from API.
INFO Connecting to 192.168.6.137:6053 (192.168.6.137)
INFO Successfully connected to 192.168.6.137

This is my conf:

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

wifi:
  ssid: 'martinRoutero'
  password: 'xxxxxxxxxxxxxxxxxxxxxxx'
  manual_ip:
    static_ip: 192.168.6.137
    gateway: 192.168.6.1
    subnet: 255.255.255.0
  fast_connect: True
  

# mqtt:
#   broker: 192.168.6.245
#   username: ''
#   password: ''
 

# Enable logging
logger:
  level: VERBOSE

ota:

api:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Lampada Luigi Button"
    on_press:
      then:
      - switch.toggle:
          id: relay
  - platform: status
    name: "Lampada Luigi Status"

switch:
  - platform: gpio
    pin: GPIO12
    name: "Lampada Luigi"
    id: relay
  - platform: restart
    name: "Lampada Luigi restart"

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

light:
  - platform: monochromatic
    name: "Lampada Luigi Green LED"
    output: basic_green_led

Any suggestion?

Hello everyone!

I was wondering if it possible to keep the Sonoff Basic’s green led on after a light.turn_on action is called?

Basically I want to keep the LED on if the main relay is on and then turn it off when relay is off. This is my code:

esphome:
  name: ${project_name}
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: ${wifi_ssid}
  password: ${wifi_psw}
  fast_connect: true
  ap:
    ssid: ${friendly_name}
    password: ${ap_psw}

logger:

web_server:

api:
  password: ${api_psw}

ota:

binary_sensor:

## Buton 00

  - platform: gpio
    id: button_00
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    filters:
      - delayed_on: 50ms
      - delayed_off: 50ms
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - switch.toggle: main_switch
      - timing:
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_00_double"
      - timing:
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_00_triple"
      - timing:
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_00_quadruple"
      - timing:
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_00_many"
      - timing:
          - ON for at least 2s
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_00_long"

output:
  - platform: gpio
    id: main_relay
    pin: GPIO12

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

switch:
  - platform: output
    name: ${switch_entity_id}
    id: main_switch
    output: main_relay
    icon: ${switch_icon}
    on_turn_on:
      then:
        - light.turn_on: led
    on_turn_off:
      then:
        - light.turn_off: led

light:
  - platform: monochromatic
    output: basic_green_led
    id: led

sensor:
  - platform: wifi_signal
    name: ${friendly_name} - Sinal Wifi
    update_interval: 60s

text_sensor:
  - platform: template
    name: ${friendly_name} - Interruptores
    id: buttons
    icon: "mdi:light-switch"

status_led:
  pin:
    number: GPIO13
    inverted: true

With this code, when I turn on the switch, relay turns on, led fades in and immediately turns off. When switch is turned off, relay goes off, led turns on and fades out.

Thanks!

1 Like

Ok, so turns out that the problem is the status_led component. After disabling it the led turned on and off with the switch, matching their states.

The problem is that now I’ve missed a very important function that allows me to visually know if there is a problem with the device.

Is there a way to overcome this problem?

Thanks!

upgrade esphome and clean/upload the config to your node