Arduino_Automation:
I put it above, so that my sketch now looks like this:
You did not delete the line in loop() when you put the definition at the top so now you have two variables with the same name and, within loop(), only the local version is used.
...R