Variables.yaml file included in automation

Hi All,

I tried to include a variable file into automation. Funny enough this works.
That means that you can add all kind of variables into a file and only use that variable into your automation that is needed. For me I have many repeated lines and want this much easier to manage.
Not I only have to change the variable file and all automations that use it will use the updated version.

Only question: Will this work without any issues or is there something in the background that will screwed up when using this?

variables.yaml

---
test: "{{ 100 if is_state('switch.balcony_light_switch', 'on') else 10 }}"

test.yaml

###########################################################################################
# TEST
###########################################################################################
- id: "87f1131c-fa9c-4b7e-bcb4-9b1b3b7abe82"
  alias: "TEST - Include variable file into automation"
  mode: restart
  trigger:
    - platform: state
      entity_id: switch.dressoir_light_switch

  variables: !include /config/integrations/variables.yaml

  condition: []

  action:
    - if:
        - "{{ (trigger.to_state.state == 'on') }}"
      then:
        - service: light.turn_on
          target:
            entity_id: light.dressoir_all
          data:
            brightness_pct: "{{ test }}"
            kelvin: "{{ states('sensor.adaptive_lighting_color_temperature') }}"
            effect: "none"

    - if:
        - "{{ (trigger.to_state.state == 'off') }}"
      then:
        - service: light.turn_off
          target:
            entity_id: light.dressoir_all

output when trace automation and check automation config

id: 87f1131c-fa9c-4b7e-bcb4-9b1b3b7abe82
alias: TEST - Include variable file into automation
mode: restart
trigger:
  - platform: state
    entity_id: switch.dressoir_light_switch
variables:
  test: '{{ 100 if is_state(''switch.balcony_light_switch'', ''on'') else 10 }}'
condition: []
action:
  - if:
      - '{{ (trigger.to_state.state == ''on'') }}'
    then:
      - service: light.turn_on
        target:
          entity_id: light.dressoir_all
        data:
          brightness_pct: '{{ test }}'
          kelvin: '{{ states(''sensor.adaptive_lighting_color_temperature'') }}'
          effect: none
    else:
      - service: light.turn_off
        target:
          entity_id: light.dressoir_all
1 Like