Esphome ping home assistant

Is there any way that i could ‘ping’ or see if home assistant is online?
i can do this with api.connected but this only works during boot and never checks again after that
or maybe i am using it wrong?

why do i need this?
i need my thermostat to work 24/7 and if home assistant goes offline i want it to revert to a internal sensor instead of using the home assistant sensor.

thanks!

my code:
this is a script that is run every time the screen dims but it doesnt update.

- id: api_check
    then:
      if:
        condition:
            api.connected:
        then:
          - lambda: |-
              id(api_check_int) = 1;
        else:
          - lambda: |-
              id(api_check_int) = 0;

There is a 3rd party ESPHome custom sensor:

As you said - none of the inbuilt components check after boot.

You have to get your HA reliable as it is by nature now since a while ! So if you have some problems of avalaibility of instance you have an other problem to solve first :wink:

Wrong. If you use interval you’ll check that condition every n seconds. I use as below for one LED to show status: lit if no connection, steady flashing when only wifi is connected and just quick flash when API is connected, too.

interval:
  - interval: 2s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - if:
              condition:
                api.connected:
              then:
                - switch.turn_on: ${device_name}_wifi_api_connected
                - delay: 1900ms
                - switch.turn_off: ${device_name}_wifi_api_connected
              else:
                - switch.turn_on: ${device_name}_wifi_api_connected
                - delay: 1000ms
                - switch.turn_off: ${device_name}_wifi_api_connected
        else:
          - switch.turn_off: ${device_name}_wifi_api_connected

switch:
#Switch WiFi connected LED  
  - platform: gpio
    pin: GPIO14
    id: ${device_name}_wifi_api_connected
    internal: true