Here is my flow that I use for numerous announcements and the alarm:
- Check current volume. If not desired volume, then set it to that volume.
- Log the previous volume.
- Reinstate previous volume after a set “wait” or a “delay” node.
[{"id":"eead7d9d.051e","type":"api-call-service","z":"f9a8a8ea.c4b0f8","name":"Set volume to 100%","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{\"entity_id\":\"media_player.bedroom_speaker\",\"volume_level\":1}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1780,"y":880,"wires":[[]]},{"id":"4494668b.223168","type":"switch","z":"f9a8a8ea.c4b0f8","name":"100%?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1430,"y":880,"wires":[["eead7d9d.051e","e39c7d3f.4ab0b"]]},{"id":"389f0326.13fb6c","type":"api-current-state","z":"f9a8a8ea.c4b0f8","name":"Bedroom Speaker","server":"1b36a1cc.1e72ee","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"media_player.bedroom_speaker","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1250,"y":880,"wires":[["4494668b.223168"]]},{"id":"e39c7d3f.4ab0b","type":"function","z":"f9a8a8ea.c4b0f8","name":"","func":"msg.payload =\n{\n \"data\":{\n \"entity_id\":\"media_player.bedroom_speaker\",\n \"volume_level\": msg.data.attributes.volume_level\n }\n}\nreturn msg;","outputs":1,"noerr":0,"x":1430,"y":940,"wires":[["4f516e52.57f07"]]},{"id":"c1afee90.99e03","type":"api-call-service","z":"f9a8a8ea.c4b0f8","name":"Set volume to Previous","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1790,"y":940,"wires":[[]]},{"id":"4f516e52.57f07","type":"ha-wait-until","z":"f9a8a8ea.c4b0f8","name":"","server":"1b36a1cc.1e72ee","outputs":1,"entityId":"alarm_control_panel.house","property":"state","comparator":"is","value":"disarmed","valueType":"str","timeout":0,"timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"x":1580,"y":940,"wires":[["c1afee90.99e03"]]},{"id":"1b36a1cc.1e72ee","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
[{"id":"f9af48c9.471648","type":"api-call-service","z":"63ea4fd.14ed3b","name":"Set volume to 50%","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{\"entity_id\": \"media_player.living_room_speaker\", \"volume_level\": 0.5 }","mergecontext":"","x":1570,"y":480,"wires":[[]]},{"id":"37589482.af76bc","type":"switch","z":"63ea4fd.14ed3b","name":"50% ?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1370,"y":540,"wires":[["f9af48c9.471648","b2037777.2d64a8"]]},{"id":"45c120d4.e132c","type":"api-current-state","z":"63ea4fd.14ed3b","name":"Speaker","server":"1b36a1cc.1e72ee","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"media_player.living_room_speaker","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1220,"y":540,"wires":[["37589482.af76bc"]]},{"id":"b2037777.2d64a8","type":"function","z":"63ea4fd.14ed3b","name":"","func":"msg.payload =\n{\n \"data\":{\n \"entity_id\":\"media_player.living_room_speaker\",\n \"volume_level\": msg.data.attributes.volume_level\n }\n}\nreturn msg;","outputs":1,"noerr":0,"x":1510,"y":540,"wires":[["76f78e06.d0958"]]},{"id":"76f78e06.d0958","type":"delay","z":"63ea4fd.14ed3b","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1640,"y":540,"wires":[["1d043b26.2af975"]]},{"id":"1d043b26.2af975","type":"api-call-service","z":"63ea4fd.14ed3b","name":"Set volume to Previous","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{}","mergecontext":"","x":1830,"y":540,"wires":[[]]},{"id":"1b36a1cc.1e72ee","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]