Regarding the last line, I’m not sure what you mean? My last_alexa sensor now has underscores in it and everything is working even for those echoes that still have spaces in it? I have two echoes still named “Living Room” and “Echo Plus” in the Alexa app. They now show Living_Room and Echo_Plus in sensor.last_alexa. The only thing I changed was
It seems that it is more than just output the terminal, but it is the value that the py script returns to HA for that sensor. My automation works perfectly now with my echoes that contain a space.