esphome / esphome/feature-requests

Triggers for wifi/api connect/disconnect

Open
#2,272 3 comments 7 reactions 0 assignees View on GitHub
component: wifi
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

In many cases we need to execute code when Wi-Fi connection (or HA api) is lost / restored.

Currently there are no triggers for these events:

- `wifi.on_connect`
- `wifi.on_disconnect`
- `api.on_connect`
- `api.on_disconnect`

A recent PR (#746) added something similar for MQTT only.

**Please describe your use case for this integration and alternatives you've tried:**

Many examples found on internet suggest a workaround like:

```yaml
interval:
- interval: 1s
then:
- if:
condition:
- not: wifi.connected
then:
- (...)
- if:
condition:
- wifi.connected
then:
- (...)
```

While the above code works, polling is not the best way to solve this problem. A trigger could (presumably) reduce cpu usage.

**Additional context**

The above workaround has also two additional problems:

- The user is left to implement its own way to detect a _change_ in the state (otherwise the code will repeatedly run each 1s)
- The code is a bit verbose

All this could be solved with appropriate triggers for each event.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.