You haven’t really fully defined what you’re looking for and what all the events and entities are and how they’re related, but I can provide some general feedback to start…
First, you say "day, evening, night’, yet the code so far only has two cases that are time dependent. You might want to create a template sensor whose value indicates day, evening or night. Then you don’t have to repeat all the time comparisons, making your automation(s) easier.
Next, to answer the question, “Can I use a {% %} block for the whole data_template part so I don’t need to use redundant time period checks?”, the answer is no. Templates are values of YAML keys. They cannot span multiple YAML keys.
Lastly, you might consider defining scenes. It will make the action part of your automation easier because you just specify the scene, and hence you don’t have to spell out all the details (entity_id & brightness, at least), reducing the number of templates you’ll need.
You can always guarantee Phil’s answer will be better than mine (not saying much), and better than most people’s. That’s why the gave him Thunderbird 2.
Thank you Phil and all. I will definitely look into template sensors and scenes.
Just a general question: I’m coming from FHEM, where you are able to write perl-functions with entity-states as variables, making you totally free in creating your own logic. I found this a nice option for complex automations like the one above - is anything like this possible with Home Assistant, or is YAML always the way to go? Not criticizing anything, I’m just curious
HA has the Python Scripts component and that can make some things easier (I’ve written and used several), but it’s not a replacement for automations (they can be called, though, from automations just like “normal” HA Scripts), and they run in a fairly limited “sandbox” environment. If you want to do more complex things then you probably have to look at other options, such as AppDaemon or Node-RED (neither of which I know much about, only that I see a lot of people use them.)
Error while executing automation automation.aeon_wallmote_quad_button_1. Service not found for call_service at pos 1: Unable to find service scene/turn_on