Can I trigger a HA script from ESPHome?

The above example should work fine, however it would help if you posted what you have already, then we might find out where the confusion lies.

Please check THIS post to see how to post code.