I use sonoff devices with ESPHome, all the devices comes unavailable at rondom times. and mostly all together. At the same time. After that I have an haunted house. With lights switching on. Is there a way to prevent this?
The wifi sensor gives a solid connection.
This is my template.
#Sonoff Mini
#Pin Function
#GPIO0 Button (inverted)
#GPIO4 SW Input (S2)
#GPIO12 Relay and Red LED
#GPIO13 Blue LED (inverted)
#GPIO16 Optional sensor
substitutions:
project_name: 'schakelaarbadkamerbeneden'
friendly_name: 'schakelaar_badkamer_beneden'
SSID_password: 'xxxxxx'
SSID_name: 'xxxxxx'
# switch_icon: '' #mdi:ICON https://materialdesignicons.com/
esphome:
name: ${project_name}
platform: ESP8266
board: esp8285
wifi:
ssid: ${SSID_name}
password: ${SSID_password}
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${friendly_name} FB
password: ${SSID_password}
#captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "xxxxxx"
binary_sensor:
- platform: gpio
id: button
pin:
number: GPIO4
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:
- text_sensor.template.publish:
id: buttons
state: "button_pressed"
- delay: 50ms
- text_sensor.template.publish:
id: buttons
state: "button_single"
- 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_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_triple"
- 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_long"
sensor:
- platform: wifi_signal
id: wifi2
update_interval: 60s
- platform: template
name: ${friendly_name} - Wifi signal
unit_of_measurement: '%'
accuracy_decimals: 0
icon: "mdi:wifi"
lambda: |-
if (id(wifi2).state < -92.0)
return 100.0;
if (id(wifi2).state > -21.0)
return 1.0;
else
return round(( -0.0154 * id(wifi2).state * id(wifi2).state ) - ( 0.3794 * id(wifi2).state ) + 98.182 );
text_sensor:
- platform: template
name: ${friendly_name} - Switches
id: buttons
icon: "mdi:light-switch"
At night around 11 clients, and the logs show around ā-67db, -60db, -58dbā The network is running on two wifi accespoint (wifi 6 enabled) with an edimax router.
Iāam using a pushbutton switch for single, double, triple and long press. If home-assistant report unavailable ESPhome / home assistant resend the last status and it triggers the automation, is it not possible to configure esphome or homeassistent to ignore the status after status āunavailableā
alias: Gang boven licht aan
description: ''
trigger:
- entity_id: sensor.schakelaar_boven_gang_switches
platform: state
to: button_single
condition: []
action:
- entity_id: light.0x14b457fffe2623f5_light
service: light.toggle
mode: single
Make sure you set addresses that are outside the routerās DHCP range or reserved within it. Try just setting it on one or two devices at first ā Iāll bet they stay up when the rest go offlineā¦
@sender If ESPs cant connect intermittently it is very likely to be a wifi issue.
I think Troonās advice is the best thing to try.
Iāve got more ESPHome devices than I can be bothered counting and they all stay connected, 100%. Unless they are Kogan V1 smart power monitoring sockets. Those bastards die about one hour after their warranty expires.
Mind you I have 4 wifi access points arround my house broadcasting different SSIDs and each ESP is programmed to connect to the nearest SSID. And each ESP has a static IP address.
Agreed, thatās why I asked if there are other issues with wifi. And advised to up the frequency for wifi signal scanner.
I once had a wifi ap via poe, giving me huge headaches (did not know this was the culprit a that time)ā¦ turned out the cable was good enough for poe but not the ehternet signal. Max speed was 100Mbps and bot 1Gbps. Replaced the cable and since rock solid. So hence my suggestion not to stare blind on wifi. A cable or network error to and from homeassistant can also give a totally wrong picture of these kind of problems.
Static ip is not the solution for me, still sometimes homeassistant report āunavailableā. Tonight Iām using a different approach. After the use from the pushbutton, I add a new state ābutton_restā So if homeassistant reports āunavailableā it will return with the status ābutton_restā. And there is no automation on ābutton_restā. So hopefully this will resolve my haunted house problem. Fingers crossed.
on_multi_click:
- timing:
- 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_single"
- delay: 50ms
- text_sensor.template.publish:
id: buttons
state: "button_rest"
Itās a workaround rather than a solution, but this may help:
One of my ESPHome units (a Wemos D1 Mini with OLED screen) used to drop its connection to HA but maintain its network connection, which was annoying as this is the temperature sensor for my central heating system.
The ESPHome API reboot_timeout didnāt work, but I found that forcing it off the wifi triggered the wifi reboot_timeout. As I can control this from HA with my Unifi gear, I threw this automation together to force a reboot if it dropped offline (where switch.hall_temperature_sensor is created by the Unifi integration and blocks it from the wifi when off):
- alias: Climate - fix hall sensor becoming unavailable
description: >-
Hall temperature sensor is an ESP unit that can drop off the API
occasionally. If it does this, this automation tries to kick it
back into life by disconnecting it from the wifi for 5 mins.
We also turn off the central heating as a safety precaution.
id: 78d4a304-1723-4676-8bf5-d8baa5ee4700
trigger:
- platform: state
entity_id: sensor.hall_temperature
to: 'unavailable'
for:
seconds: 30
action:
- service: notify.admin
data_template:
message: 'Hall temperature sensor offline! Trying to reconnect...'
- service: switch.turn_off
entity_id: switch.hall_temperature_sensor
- service: switch.turn_off
entity_id: switch.chc_central_heating_relay
- delay: 300
- service: switch.turn_on
entity_id: switch.hall_temperature_sensor
- service: notify.admin
data_template:
message: 'Done. If still offline, please solve manually.'
A subsequent update to the ESPHome OLED driver has fixed my problem now.
Shouldnāt be. I have several ESPHome devices (mostly D1 Mini, couple of flashes Shellys) that can see two of my three APs, all of which are running the same four SSIDs (home + guest on 2.4 and 5GHz). They choose one at bootup and donāt roam unless one of the APs goes down.
Hereās the relevant section of code that I use on all my devices:
I have the same problem with one of my Esphome device which is Sonoff T1 3relays UK.
I have it configured with two Thermostat Climate Controller components controlling the two relays plus the third relay is alway on.
What is happening when all the three relays are turned on the ESPhome looses connection to HomeAssistant but the WiFi connection on the ESPhome is still up as reported by the Access point, as soon I turn off one of the relays the connection to HomeAssistant resumes. WiFi signal is -42 dB so reception is not a problem.
As you can see I can easily replicate the issue by turning on all 3 relays.
Have tried static IP, have tried to remove status light component as suggested and as well WiFi sleep setting have been configured as advised on the ESPhome FAQ.