The error probably occur when you restart HA and it is because the values you have in your code have not been defined yet, when you use them first time.
With HA 2021.10 this returns an error.
You need to define defaults for your values.
Petro made a good post about it here: