esphome / esphome/feature-requests
Api disconnect action
- 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**
I have a solar battery powered esp32-c3 device that collects data from various sensors. Due to the variability of solar power availability, I need to manage the battery usage state.
When the battery voltage is very low, I use the deep_sleep component to preserve it. It works great, when the device goes into deep sleep mode, the state of the entities in Home Assistant retains the values.
Other times, when the battery voltage is low, but not nearly enough to shut down the device, to preserve the battery, I disable wifi with disable wifi action and then I can continue collecting data from sensors without losing filters and other time-based data, to then after a certain time, enable wifi and connect to home assistant.
That works fine, but Home Assistant shows the entities as unavailable (obvious thing while the device connection is not present).
So, this is the reason to submit a feature request, to implement an api.disconnet action that manually disconnects the device from the api just like the deep_sleep component does and that keeps the values of the entity states in home assistant until they are updated on the next connection.
**Please describe your use case for this integration and alternatives you've tried:**
The use I want to give it is to manually manage the connection to keep the battery charge status at values that allow collecting information from the sensors, from a mode of continuous updates, to a mode of very basic and periodic updates, passing through intermediate modes of variations in the periodicity of the updates.
**Additional context**
An example of the use I want to give it would be something similar to this:
``` yaml
on_some_:
- if:
condition:
- lambda: 'return id(battery).state <= ${some_threshold};'
then:
- deep_sleep.enter:
id: control_deep_sleep
sleep_duration: ${some_duration}
else:
- if:
condition:
- lambda: 'return id(battery).state >= ${another_threshold};'
then:
- deep_sleep.prevent: control_deep_sleep
else:
- if:
condition:
- sun.is_above_horizon:
then:
- delay: 2s
- api.disconnect: # expected disconnection maintaining state values as deep_sleep does
- wifi.disable:
- delay: ${t_wifi_off_day}
- wifi.enable:
else:
- delay: 2s
- api.disconnect: # expected disconnection maintaining state values as deep_sleep does
- wifi.disable:
- delay: ${t_wifi_off_night}
- wifi.enable:
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the existing deep_sleep component and wifi.disable and wifi.enable actions, then trace how the device connection affects Home Assistant entity availability. The work is done when an api.disconnect action can disconnect the device while retaining entity states and allow them to update after the next connection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- yaml
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100