Hi there!
Just wanted to share my approach to automate lighting and switches for my setup.
It uses a declarative way to define automation so less code is required to set up and it’s easy to understand what’s happening IMHO.
You may find code, examples, and description at https://github.com/Godhart/hass-lights-control
Hope someone finds it useful too. Maybe there is more HASSish way to do the same things without a lot of code, please let me know!