I have an ESPHome device that i want to connect to wifi every 2 minutes, get some values from HA, reply that received the values and then disconnect the wifi until the next 2 minutes.
I have done a lot of searching but the fact that the device is disconnected make the whole process difficult…
I would like to do something like:
interval:
- interval: 120s
then:
- wifi.enable:
- delay: 40s
- service: switch_service
variables:
my_state: bool
my_number: int
my_string: string
then:
- lambda: |-
if ( my_state ) {
id(relay).turn_on();
ESP_LOGD("custom", "STATE ON curTime: %s", my_string.c_str());
}
else {
id(relay).turn_off();
ESP_LOGD("custom", "STATE OFF curTime: %s", my_string.c_str());
}
api.template("my_string_sensor").send_state("i received the value");
- wifi.disable:
What is the best way to do that?
I guess i could use MQTT also, but according to documentation, the api is preferred (although going offline causes many problems).