Lovelace toggle button behaviour

Hi

I am having a challenge trying to understand toggle button behaviour in the Lovelace GUI.

For example I have a simple entity card controlling an esp8266 with a relay using esp home. The actual control and detection of the relay state works perfectly. However, the toggle button in the entity card for the relay - will turn on correctly, but self toggles to off after a few seconds. The actual relay stays on as expected - so this seems to be purely an interface problem.

Also to turn the relay off, I have to toggle the card button on and quickly while it is still on toggle it off

I have seen some old posts suggesting this may be a browser issue , but this behaviour is occurring with the iOS apps and on multiple desktop computers

Here is a snippet of the ESPhome code

  - platform: gpio
    pin: 13
    id: relay4
    inverted: True
    restore_mode: RESTORE_DEFAULT_OFF
    
  - platform: template
    name: "light 4"
    
    turn_on_action:
    - switch.turn_on: relay4
    turn_off_action:
    - switch.turn_off: relay4

any assistance in pointing me in the right direction would be greatly appreciated

Al