Hi,
Anything is possible whether the solution is elegant or stable is a different matter 
Firstly I think this topic should be listed under ESP Home, where I’m sure there are real experts around
In terms of a solution I would probably do something like
-
Create an automation on HA or nodered (choose your poison) to publish an MQTT topic whenever the alarm state changes. Let’s say a topic like ‘alarm/armed’
-
From the ESP Home sample provided I would add an mqtt subscription to this file
As per https://www.esphome.io/components/mqtt.html
mqtt:
on_message:
- topic: alarm/armed
then:
- rtttl.play: "success:d=24,o=5,b=100:c,g,b"
Finally a disclaimer from me. I’ve not used ESPHome but it’s more straight forward than compiling flash like I’m used to but by that very nature I do not know how well ESPHome performs when tasked like this.
Good luck and I hope this helps or gives you an idea to a better solution