esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

ESPHome Update broke Aukey Switches #2865

Closed whizzzkid closed 2 years ago

whizzzkid commented 2 years ago

The problem

I was using https://www.esphome-devices.com/devices/Aukey-SH-PA1-Smart-Plug/ configuration to run the switches, after the most recent update something seems to have messed up all of my switches. The relay doesn't turn on, neither does the blue led.

Which version of ESPHome has the issue?

=2021.11.0

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP8266

Board

No response

Component causing the issue

No response

Example YAML snippet

# Basic Config
esphome:
  name: switch-esp-hall-light-001
  platform: ESP8266
  board: esp01_1m
  platformio_options:
    upload_speed: 115200

wifi:
  ssid: "[redacted]"
  password: "[redacted]"

  # Optional manual IP
  manual_ip:
    static_ip: [redacted]
    gateway: [redacted]
    subnet: [redacted]

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Switch Esp Hall Light 001"
    password: "[redacted]"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
ota:

output:
  - platform: gpio
    pin:
      number: GPIO15
    id: plug_outlet

  - platform: gpio
    pin:
      number: GPIO2
      inverted: yes
    id: blue_led

light:
  - platform: binary
    name: "Hall Light 001"
    id: switch_esp_hall_light_001
    output: plug_outlet

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
    id: switch_esp_hall_light_001_button
    on_press:
      light.toggle: switch_esp_hall_light_001

  - platform: gpio
    pin:
      number: GPIO15
    id: blue_led_follows_the_relay
    on_state:
      then:
        - if:
            condition:
              light.is_on: switch_esp_hall_light_001
            then:
              - output.turn_on: blue_led
            else:
              - output.turn_off: blue_led

status_led:
  # Red LED
  pin:
    number: GPIO0
    inverted: yes

Anything in the logs that might be useful for us?

INFO Reading configuration /config/switch_esp_hall_light_001.yaml...
INFO Starting log output from [redacted] using esphome API
INFO Successfully connected to [redacted]
[18:17:31][I][app:102]: ESPHome version 2021.12.1 compiled on Dec 22 2021, 18:10:40
[18:17:31][C][status_led:019]: Status LED:
[18:17:31][C][status_led:020]:   Pin: GPIO0
[18:17:31][C][wifi:488]: WiFi:
[18:17:31][C][wifi:350]:   Local MAC: [redacted]
[18:17:31][C][wifi:351]:   SSID: [redacted]
[18:17:31][C][wifi:352]:   IP Address: [redacted]
[18:17:31][C][wifi:354]:   BSSID: [redacted]
[18:17:31][C][wifi:355]:   Hostname: 'switch-esp-hall-light-001'
[18:17:31][C][wifi:357]:   Signal strength: -60 dB ▂▄▆█
[18:17:31][C][wifi:361]:   Channel: 1
[18:17:31][C][wifi:362]:   Subnet: 255.255.255.0
[18:17:31][C][wifi:363]:   Gateway: [redacted]
[18:17:31][C][wifi:364]:   DNS1: 0.0.0.0
[18:17:31][C][wifi:365]:   DNS2: 0.0.0.0
[18:17:31][C][logger:233]: Logger:
[18:17:31][C][logger:234]:   Level: DEBUG
[18:17:31][C][logger:235]:   Log Baud Rate: 115200
[18:17:31][C][logger:236]:   Hardware UART: UART0
[18:17:31][C][gpio.output:010]: GPIO Binary Output:
[18:17:31][C][gpio.output:011]:   Pin: GPIO15
[18:17:31][C][gpio.output:010]: GPIO Binary Output:
[18:17:31][C][gpio.output:011]:   Pin: GPIO2
[18:17:31][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'switch_esp_hall_light_001_button'
[18:17:31][C][gpio.binary_sensor:016]:   Pin: GPIO13
[18:17:31][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'blue_led_follows_the_relay'
[18:17:31][C][gpio.binary_sensor:016]:   Pin: GPIO15
[18:17:31][C][light:098]: Light 'Hall Light 001'
[18:17:31][C][captive_portal:144]: Captive Portal:
[18:17:32][C][ota:082]: Over-The-Air Updates:
[18:17:32][C][ota:083]:   Address: [redacted]:8266
[18:17:32][C][api:134]: API Server:
[18:17:32][C][api:135]:   Address: [redacted]:6053
[18:17:32][C][api:139]:   Using noise encryption: NO
[18:17:32][C][mdns:084]: mDNS:
[18:17:32][C][mdns:085]:   Hostname: switch-esp-hall-light-001
[18:17:37][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state OFF
[18:17:37][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state ON
[18:17:37][D][light:035]: 'Hall Light 001' Setting:
[18:17:37][D][light:046]:   State: ON
[18:17:39][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state OFF
[18:17:39][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state ON
[18:17:39][D][light:035]: 'Hall Light 001' Setting:
[18:17:39][D][light:046]:   State: OFF
[18:17:42][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state OFF
[18:17:42][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state ON
[18:17:42][D][light:035]: 'Hall Light 001' Setting:
[18:17:42][D][light:046]:   State: ON
[18:17:43][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state OFF
[18:17:44][D][binary_sensor:036]: 'switch_esp_hall_light_001_button': Sending state ON
[18:17:44][D][light:035]: 'Hall Light 001' Setting:
[18:17:44][D][light:046]:   State: OFF
[18:17:47][D][light:035]: 'Hall Light 001' Setting:
[18:17:47][D][light:046]:   State: ON
[18:17:49][D][light:035]: 'Hall Light 001' Setting:
[18:17:49][D][light:046]:   State: OFF
[18:17:50][D][light:035]: 'Hall Light 001' Setting:
[18:17:50][D][light:046]:   State: ON
[18:17:52][D][light:035]: 'Hall Light 001' Setting:
[18:17:52][D][light:046]:   State: OFF

Additional information

The logs insist everything is working, the actual relay doesn't switch on, Nor does the blue LED.

jesserockz commented 2 years ago

You need to provide more information (config/logs/etc), otherwise nobody can help you. That's why we have those fields in the issue form.

whizzzkid commented 2 years ago

@jesserockz agreed however I don't have anything other than that. The same config (in the link) was working for more than a year and now it's not. Looks like there was a regression which is not reported in the logs and cannot be diagnosed as the logs display the normal behavior. However, it doesn't toggle the relay physically. The logs insists that the switch is on, but not really.

whizzzkid commented 2 years ago

@jesserockz any updates on this?

megabitdragon commented 2 years ago

@jesserockz , I have the exact same issue after updating the ESPHome addon to version 2021.12.3, also using EPS8266 platform. Here is the config file template that is used by all the affected devices. There are no errors in the device logs.

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

<<: !include ../wifi.yaml

logger:

api:
#  password: !secret esphome_api_password

ota:
#  password: !secret esphome_ota_password

status_led:
  pin:
    number: GPIO5 # Red LED
    inverted: True

output:
  - platform: gpio
    id: led_1
    pin:
      number: GPIO4
      inverted: True

light:
  - platform: binary
    id: white_led
    output: led_1
    restore_mode: RESTORE_DEFAULT_ON
    internal: True

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      inverted: True
    id: sensor
    internal: True

  - platform: gpio
    pin:
      number: GPIO13
      inverted: True
    id: button
    name: ${id} Button
    on_press:
      - switch.toggle: ${id}
    internal: True

switch:
  - platform: gpio
    id: relay
    pin:
      number: GPIO12
    restore_mode: RESTORE_DEFAULT_OFF
    internal: True

  - platform: restart
    name: ${project} REBOOT

  - platform: template
    name: ${project}
    id: ${id}
    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.turn_off: white_led
    turn_off_action:
      - if:
          condition:
            - binary_sensor.is_off: sensor
          then:
            - switch.turn_off: relay
            - light.turn_on: white_led
megabitdragon commented 2 years ago

One more piece of information, I rolled back to version 1.18.0 and everything works as expected. Is there any additional information that I can provide to get to the root cause?

jesserockz commented 2 years ago

One thing I just noticed is that you have GPIO15 (the relay) set up as both an output and a binary_sensor. A pin cannot do both input and output at the same time and is bound to cause issues. Move your on_state code to on_turn_on and on_turn_off of the light and try again.

I see you got that from the esphome-devices template so it is not your fault, but it is just plain wrong and should not be done like that.

whizzzkid commented 2 years ago

@jesserockz that was absolutely it:

# Basic Config
esphome:
  name: switch-esp-hall-light-001
  platform: ESP8266
  board: esp01_1m
  platformio_options:
    upload_speed: 115200

wifi:
  ssid: "[REDACTED]"
  password: "[REDACTED]"

  # Optional manual IP
  manual_ip:
    static_ip: [REDACTED]
    gateway: [REDACTED]
    subnet: [REDACTED]

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "[REDACTED]"
    password: "[REDACTED]"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
ota:

output:
  - platform: gpio
    pin:
      number: 15
    id: plug_outlet

  - platform: gpio
    pin:
      number: GPIO2
      inverted: yes
    id: blue_led

light:
  - platform: binary
    name: "Hall Light 001"
    id: switch_esp_hall_light_001
    output: plug_outlet
    on_turn_on:
      - output.turn_on: blue_led
    on_turn_off:
      - output.turn_off: blue_led

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
    id: switch_esp_hall_light_001_button
    on_press:
      light.toggle: switch_esp_hall_light_001

status_led:
  # Red LED
  pin:
    number: GPIO0
    inverted: yes

This now works. I'll raise a PR to fix those examples.