I’ve got six identical Sonoff S31 power monitor plug-in switches, all of which use the same code, the only thing changing is the naming conventions. All six have button entities defined as follows:
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: ${friendly_name} Button
on_press:
- switch.toggle: relay
The code compiles w/o error, the device comes online, and when the button is pressed, the relay toggles. So far so good.
But, according to Home Assistant, the device entity, in this case “binary_sensor.sonoff_s31_5_6289_button” shows up as unavailable whereas the entity “binary_sensor.sonoff_s31_4_6907_button” shows up as available with a valid status.
Here’s all of the code which I have been staring at for so long, I cannot see the forest for the trees.
FYI, I have no ego, comment as you wish on the code, but if you’ve been able to spot that elusive difference, I’d be eternally grateful:
The code, for your perusal -
substitutions:
name: "sonoff-s31-5-6289"
friendly_name: "Sonoff S31-5-6289"
location: "Darkroom Heater Control"
wifi_update_interval: "60s"
data_update_interval: "6s"
#
esphome:
name: ${name}
platform: ESP8266
board: esp01_1m
# on_boot:
# priority: 600
# then:
# - switch.turn_on: relay
#
text_sensor:
- platform: wifi_info
ip_address:
name: ${friendly_name} IP Address
ssid:
name: ${friendly_name} SSID
bssid:
name: ${friendly_name} BSSID
mac_address:
name: ${friendly_name} MAC Address
- platform: version
name: "${friendly_name} ESPHome Version"
hide_timestamp: true
#
- platform: template
name: ${friendly_name} Location
lambda: |-
return { "${location}" };
#
# Enable logging
logger:
baud_rate: 0 # (UART logging interferes with cse7766)
# level: debug
# Enable Home Assistant API
api:
# password: !secret esphome_api_password
encryption:
key: !secret esphome_api_key
#
ota:
password: !secret esphome_api_password
#
wifi:
networks:
- ssid: "<SSID Redacted>"
- password: !secret esphome_wifi_password
#
# Enable fallback hotspot (captive portal) in case wifi connection fails
#
ap:
ssid: ${friendly_name} FB
password: !secret esphome_ap_fallback_pwd
#
captive_portal:
#
web_server:
port: 80
#
# Device Specific Config
#
uart:
rx_pin: RX
baud_rate: 4800
#
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: ${friendly_name} Button
on_press:
- switch.toggle: relay
#
- platform: status
name: ${friendly_name} Status
#
switch:
- platform: gpio
name: ${friendly_name} Relay
pin: GPIO12
id: relay
#
- platform: restart
name: ${friendly_name} Restart
#
sensor:
- platform: wifi_signal
name: ${friendly_name} WiFi Signal
update_interval: ${wifi_update_interval}
#
- platform: cse7766
update_interval: ${data_update_interval}
current:
id: cse7766_current
name: ${friendly_name} Current
accuracy_decimals: 3
unit_of_measurement: "A"
state_class: "measurement"
voltage:
id: cse7766_voltage
name: ${friendly_name} Voltage
accuracy_decimals: 1
unit_of_measurement: "V"
state_class: "measurement"
power:
id: cse7766_watts
name: ${friendly_name} Power
accuracy_decimals: 3
unit_of_measurement: "W"
state_class: "measurement"
energy:
id: cse7766_watthours
name: ${friendly_name} Energy
accuracy_decimals: 3
unit_of_measurement: "Wh"
state_class: "total"
#
- platform: total_daily_energy
name: ${friendly_name} Total kWh
power_id: cse7766_watts
unit_of_measurement: kWh
filters:
- multiply: 0.001
#
status_led:
pin: GPIO13
#
time:
- platform: sntp
id: sntp_time