How to save light state, then restore it after an action?

There’s an addon you can install called Node-RED that uses this visual/flow programming style for automations. It is a full separate app from Home Assistant and can do a lot more stuff, but the HA integration is really good.