Check from esp side if connected to HA?

Is there a easier/better way to check from esp side if you are connected to HA?

this is what i am using now

class Ha_online : public Component, public Switch {
  public:
    void setup() override {
      // This will be called by App.setup()
    }
    void write_state(bool state) override {
      // This will be called every time the user requests a state change.
      extern char ha_online_state;
      ha_online_state = state;
      // Acknowledge new state by publishing it
      publish_state(state);
    }
};

and then i set the switch to ON in a automation so ON= HA connected.

i use “extern char ha_online_state;” to pass the state between different custom components.

But this only works when esp starts not when it loses connection to ha, esp reboots after 15 min with no ha connection so after 15 min i will know that HA are down or whatever, but i want to know faster then this so i can start “offline” mode in my mixed custom components so i have some functionality when if HA connection are lost
I guess i can change the state of the switch every 30 sec in a HA automation and check this from esp side but i would prefer something smarter, any ideas?

I may not understand correctly your request but what about this:

1 Like

That will tell home assistant the status of esphome, i need it the other way around. I need esphome to know if it is connected to home assistant.

Did you find a better way, I need the same?

Regards, Dave

Yes.

Yes.

Thanks, will take a look

Regards, Dave