I would like to get the solution about the status of light and binary-sensor in sonoff basic by ESPHOME.
I prepared the sonoff basic and I connected it to the my Home Assistant based on the basic information described in the web site below.
Then, I confirmed that it works and I can control the on-off function But the light and binary sensorare not working. The light is not working regardless of power-onoff or any connection to internet. Even, the status of the binary-sensor is unavailable. as well
I also check there are two kinds of the sonoff basic. But as the sonoff basic i have is not a new model, It seems that there is no problem.
I checked the GPIO information and any other related items But I don’t know why it is not working.
Is there anyone who has the same problem? If available, Please let me know what the problems are or any solution.
Thank you for your comment. But, I found out that I made the typo just in here. And the typing in my ESPHOME is correct.Any idea to make the issue clear?
The LED operation is different to Tasmota / Sonoff operation:
Status LED
The status_led hooks into all ESPHome components and can indicate the status of the device. Specifically, it will:
Blink slowly (about every second) when a warning is active. Warnings are active when for example reading a sensor value fails temporarily or the WiFi/MQTT connections are disrupted.
Blink quickly (multiple times per second) when an error is active. Errors indicate that ESPHome has found an error while setting up. In most cases, ESPHome will still try to recover from the error and continue with all other operations.
Stay off otherwise.
So it being off is a good thing.
The binary sensor being unavailable is strange. Your configuration looks correct.
Here is the code I use for an original Sonoff Basic that also uses an input on the internal pins to allow control of the Sonoff from a wall mounted light switch.
I use two files for my ESPHome configs - a “base” config that will be the same for every one of the same type of device and a device specific config.
Here is the “base” code:
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:
reboot_timeout: 0s
ota:
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
- platform: gpio
pin:
#number: GPIO3 # (RX Pin) - if using the newer Sonoff Basic with Wires instead of traces
number: GPIO14
mode: INPUT_PULLUP
#inverted: True
id: wall_switch
filters:
- delayed_on: 100ms
- delayed_off: 100ms
# name: "Sonoff Basic Button" # uncomment to expose the button as a binary senor
on_press:
- switch.toggle: relay_template
on_release:
- 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
then when you compile only compile the device specific config and it will import the info from the “base” config and it will compile correctly. If you try to compile the “base” config it will give you errors.
these configs will toggle the green LED in sync with the state of the relay just like the original firmware.
the common files are stored separately from the device files.
so for example I use the file called “common_sonoff_basic_old_wall.yaml” with the generic config stuff.
then I have another file that might be called “kitchen_lights.yaml” that contains all of the device specific config substitution data.
And then another one “livingroom_lights.yaml”, etc using the same common file.
then when you compile the program you will use the device specific file and it will pull all of the code from the generic file into the .bin file to flash to the device.
Once you create the properly coded common file you should never need to touch it again and from then on will only work with the device specific files