Home Assistant 0.115 got an ability to use variables in automation and scripts. You can declate variables even using templates and use them across the script or automation. Here is an example from rel...
Grav was with by Trilby Media.