Wall Switch Combine "on_state" & "on_click"

Dear Community,

I would like to make my wall switch a little smarter.
The to the ESP physically connected switch is an on / off switch.

My goal is:

  1. “on_state” the light / relay will be toggled.
  2. “on_click” my boolean “home_state” will be toggled. There fore i would like to a virtual sensor which will be exposed to home assistant.

Here is my current config. I know it’s not working like this, could you help me get it right please?

For “on_state” somehow i need to add a condition, to only get published if no other state change happens within e.g 400ms.

#Variables
substitutions:
  device_name: shelly_2_hall_light
  friendly_name: Hall
  #ip_address:

# Basic Config
esphome:
  name: "${device_name}"
  platform: ESP8266
  board: esp01_1m

#Network Settings
<<: !include includes/network.yaml

# Device Specific Config
output:                                
  - platform: gpio                     
    pin: GPIO4                         
    id: output_relay

light:                                 
  - platform: binary                   
    name: "${friendly_name}"              
    output: output_relay                     
    id: lightid                        
                                       
binary_sensor:                         
  - platform: gpio                     
    pin: GPIO5                    
    name: "${friendly_name}"             
    on_state:
      min_length: 5000ms
      then:                            
        - light.toggle: lightid        
    internal: true

  - platform: template
    name: "toggle_home_state"
    id: home_state
    on_click:
      min_length: 50ms
      max_length: 350ms

Have You solved that issue ?