How do I set a variable globally, enabling using it in multiple automations?

Is it possible to make a global variable, e.g. INTERIOR_LIGHTS_ON and EXTERNAL_LIGHTS_ON, based on sun elevation?

INTERIOR_LIGHTS_ON== true
EXTERNAL_LIGHTS_ON== false

Here is the trigger I use for external light.

trigger:
  platform: numeric_state
  entity_id: sun.sun
  value_template: '{{ state.attributes.elevation }}'
  below: '-3.0'

However; it gets darker inside the house before we need to turn on the external lights, so this trigger would work for turning on internal lights.

trigger:
  - platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.elevation }}'
    below: '1.0'

So I have this idea; If I could make some kind of state for when external and internal lights should be on, enabling to use this parameter in several automations and scrips.
That would save some code writing :slight_smile:

Create an input_boolean

1 Like

Or a template sensor with

value_template:  '{{ states.sun.sun.attributes.elevation < 1.0 }}'

It’s even one of the first examples: