Button event fired when goes available/unavailable

Hi, I have an esphome device and a template button in there. I have an automation in Hassio triggered by the button pressed. It works as expected - except it starts every time when the esphome device becomes available or unavailable (so 2x during a reboot).

platform: device
device_id: 2d3977cd9c6bb3eabebc9e012e264cb9
domain: button
entity_id: button.doorbell
type: pressed

This is my trigger. Any idea what is wrong here?
Thank you

You could perhaps move the automation to the ESP instead.
So instead of ESP sending the button press to HA it just sends the command directly to HA.

What is the action of your automation? And what is the ESP yaml for the button?

My idea is that the esp has only the button and the logic is in HA - the esp won’t see the devices (in this case a speaker to sound the bell). I could send an event from esphome (probably it won’t fire when it goes unavailable)

That is what I’m saying. Move the automation to the device instead.