Wifi Signal Loss as Trigger

Looking to trigger an automation to so something (inside ESP, not a HA automation) when wifi connection is lost. I’ve seen the wifi signal sensor, but what’s the value I’m looking for when signal is gone?

Thanks!

With tasmota, check the trigger “Wifi#Disconnected”: https://github.com/arendst/Tasmota/wiki/Rules

Thanks; however Tasmota won’t suit my needs on this one, looking for an ESPHome solution!

This will turn off a switch if connection to HA is lost, whatever the reason

text_sensor:
  - platform: homeassistant
    name: "Uptime from Home Assistant"
    id: watchdog
    entity_id: sensor.time
    on_value:
      then:
        - lambda: !lambda |-
            auto time_now = id(homeassistant_time).utcnow();
            id(last_value_from_ha) = time_now.timestamp;
interval:
  - interval: 15s
    then:
    - if:
        condition:
          - lambda: !lambda |-
              auto time_now = id(homeassistant_time).utcnow();
              
              if(time_now.timestamp - id(last_value_from_ha) > 120)
                return true;
              
              return false;
        then:
          - switch.turn_off: ventil # lost connection, turn off
time:
  - platform: homeassistant
    id: homeassistant_time
globals:
  - id: last_value_from_ha
    type: int
    initial_value: '0'
4 Likes

This might be useful: https://esphome.io/components/wifi.html#wifi-connected-condition

Exactly what I was looking for. Great!

Many thanks.

@ReDaLeRt @mrrodge
I use this one:

Sorry to resurrect an old one. How do I use the inverse of this i.e. a condition if wifi.connected is false?

Thanks!

You might use the “else” case, not just the “then”.

Now there’s a facepalm moment. Thanks!