Initial state binary sensor

Hi, I have a problem reading a very simple binary sensor: I used a delayed_on filter of 10 seconds and it works but when ESPHOME boot and the sensor was prior ON I can’t make automation “on_press”.
In logs I can see:
[09:52:54][D][binary_sensor:034]: ‘SENSOR’: Sending initial state ON
If I switch off:
[09:53:22][D][binary_sensor:036]: ‘SENSOR’: Sending state OFF
And I I switch on the right state on
[09:53:33][D][binary_sensor:036]: ‘SENSOR’: Sending state ON
So I just want to run automation even on initial state. How can I do? THANKS

I have the same question…

Not sure what you’re doing with the sensor, but it sounds like you just want to guarantee execution at boot, ie trigger an action at boot, reliably. The only way I’ve found is to use on_boot: under esphome:

esphome:
  name: huzzahwin9b
  on_boot:
    priority: 600     #  Defaults to 600 DOESN'T WAIT FOR WIFI    
          # -100 waits till ALL IS INITIALIZED but NO EXECUTION HERE if no WIFI
    then:      #   PUT ANY ACTIONS HERE
      - globals.set:
          id: global1i
          value: '11'

I had to search for this solution because, once I got something working perfectly, removing the WiFi Source would prevent it’s operation. I’m sure many projects suffer from this without knowing it, unaware of the dependency for the wifi connection to complete (among other boot steps) before evaluating sensors in the main body. That’s been my experience, anyway.

Find info on priority: under on_boot at the following