New to HA and scripting error

Please format your code correctly — see here:

There could be all sorts of indentation errors that we can't see without the correct formatting.