I have 5 Sonoff basics flashed with the following Esphome <espbasic.yaml> In Home Assistant the relays respond correctly, but the binary.sensor doesn’t display on/off along with button press. The led on the Sonoff toggles correctly with the relay. Also I get “no state history found” when I select a relay in HA LovelaceUI. I’m sure its a simple fix, but I’m not sure where to look.
here is the code i use for my sonoff basics (old style with solder traces):
esphome:
name: ${name}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pwd
reboot_timeout: 0s
fast_connect: true
manual_ip:
static_ip: ${ip}
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable logging
logger:
# Enable Home Assistant API
api:
#password: !secret esphome_api_pwd
reboot_timeout: 0s
ota:
#password: !secret esphome_ota_pwd
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
id: button
# name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
on_press:
- switch.toggle: relay_template
on_multi_click:
- timing:
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at least 0.2s
then:
- switch.turn_on: restart_sonoff
switch:
- platform: gpio
pin: GPIO12
id: relay
## https://esphomelib.com/esphomeyaml/components/switch/template.html
## tie the led & relay together & report status regardless of trigger method
- platform: template
name: ${friendly_name}
id: relay_template
lambda: |-
if (id(relay).state) {
return true;
} else {
return false;
}
turn_on_action:
- light.turn_on: status_led
- switch.turn_on: relay
turn_off_action:
- light.turn_off: status_led
- switch.turn_off: relay
# optimistic: true # this will change the toggle switch to individual on/off buttons
- platform: restart
#name: "Reboot Kitchen Sconce Sonoff"
id: restart_sonoff
output:
## https://esphomelib.com/esphomeyaml/components/output/esp8266_pwm.html
## create a PWM pin to control
- platform: esp8266_pwm
id: basic_green_led
pin:
number: GPIO13
inverted: True
light:
## https://esphomelib.com/esphomeyaml/components/light/monochromatic.html
## attach a monochrome light to the PWM pin
- platform: monochromatic
# name: "Sonoff Basic Green LED" # uncomment to expose the led as a light with brightness control
output: basic_green_led
id: status_led
default_transition_length: 1ms # controls the light fade/transition time
text_sensor:
- platform: version
name: ${friendly_name} ESPHome Version
sensor:
- platform: wifi_signal
name: ${friendly_name} WiFi Signal Strength
update_interval: 60s