I believe you didn’t understand my answer.
After creating the button to run the script in esphome, you call the press button action in your automation in home assistant.
however has not resulted in any entity being published in HA, so assume this is not correct or should be injected into HA (somehow this does not appear to be correct)
please let me know where in the HA or ESP code you placed this code so that this script is exposed…
Note that what walberjunior suggested is still the most logical way. The solution for the OP provided is creating a service in the esp, define an api call in HA to trigger it, define a button in HA and create an automation for it to call the api.
What walberjunior suggested was: define a button in the esp to do what you need. That is all. Because the esp button gets exposed to HA, you will see the button there. You can use it there the way you use any other button.