HA API connected?

Ive copied the examples from the ESPHome docs to determine whether my Node is connected to HA or not, and I use a LED to determine whether its connected or not, but if I go look at the log of the node and then disconnect, the LED goes out - even tho HA is still connected.

I sort of understand that the OTA log through the ESPHome dashboard is done thru the API and that when it disconnects it executes on_client_disconnected.

At the moment, the LED is green, but I just dont understand why the LED turns off when I dont have a specific - light.turn_off statement. Why doesnt it STAY green (cos its still connected to HA) or even turn red on the disconnection of the OTA log

All I want to do is detect if HA is connected - green if its connected to HA, red if its not. Whether or not the ESPHome log connects thru the API or not is inconsequential and I dont want to impact the LED state connection status of the node to HA

What would I be doign wrong???

api:
  on_client_connected:
    - if:
        condition:
          lambda: 'return (0 == client_info.find("Home Assistant"));' 
        then:
          - light.turn_on:
              id: api_online
              brightness: 20%
              red: 0%
              green: 10%
              blue: 0%                

  on_client_disconnected:
      - if:
        condition:
          lambda: 'return (0 == client_info.find("Home Assistant"));'
        then:
          - light.turn_on:
              id: api_online
              brightness: 20%
              red: 10%
              green: 0%
              blue: 0%