Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api disconnect action #3014

Open
fran6120 opened this issue Jan 6, 2025 · 0 comments
Open

Api disconnect action #3014

fran6120 opened this issue Jan 6, 2025 · 0 comments

Comments

@fran6120
Copy link

fran6120 commented Jan 6, 2025

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:

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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant