How to get availability of a switch?

I want to make a “virtual” switch that gets its states from an actual switch but runs scripts when “toggled”. I tried using tap_action on the switch entity row but that only works when the name is tapped and not when the toggle is tapped. So now I think my best option is a Template Switch.

The docs have an example on how to copy a switch but it is incomplete. When the original switch becomes unavailable nothing happens to the “copied” switch. There is an availability_template setting but what should I put in there to copy the availability of the original switch?

This does not sound like the best way to do this.

What is the actual problem you are trying to solve?

I have a device that needs to be shut down properly (by HTTP request) before its power can be cut.