How to create custom variable for use across automations?

Hi Home Assistant Community,
Long time lurker, first time poster.

I’ve been using HA for a while now and I’m looking to improve on some of my automations. I have a few automations that turn on living room lights based on time of day/sunrise/sunset and they’re working just fine. I also have an automation that turns off living room lights when I leave home if I forget to turn them off.

However, I’d like the “turn off lights when I leave” automation to not turn off the lights if they should be on because of the aforementioned time/sunrise/sunset-based automations.

I was thinking that one way to do this would be to have the time/sunrise/sunset-based automations set a global variable to true/false to indicate the lights should be on/off Then, in my “turn off lights when I leave” automation, I would only turn off the lights if they shouldn’t be on based on that global variable (i.e., if the lights are on in the evening and I leave home, keep them on; if the lights are normally off during the day and I leave home, turn them off).

Is this something that I can accomplish in HA? If so, what’s the best way to do that? Are there global variables that can be set by an automation and used by other automations? Or am I going about this all wrong?

Thanks in advance for any help you can provide!

One way is use a helper.
Another: Trigger based template sensor to store global variables

2 Likes

+1 for trigger based template sensor you can make those things do some wild stuff.

1 Like

Thank you so much for your help!

I was able to get the helper set up, update my lights automations to turn the light schedule helper on/off, and then update my leaving home automation to only turn off the lights if the helper says the light schedule is off.

1 Like