Using Input Select as an Array (Global variables) in Automations

Tags: #<Tag:0x00007f739b74cf28>

Not sure if this has been documented anywhere, but I have been using Input select as Global variables lists (Arrays) in Automations.

Take the following input Select

Array:
    name : Array Test
    options:
      - Option A
      - Option B
      - Option C
      - Option D

You can convert this to a list in JInga2 with the following

{% set arraytest = state_attr("input_select.array","options") %}

You can extract an array element by using

`{% set obj = arraytest[1] %}` 
{{obj}}

This will return ‘Option B’ Jinga2 lists start at element 0

I use this to trigger actions from Alexa using a virtual bulb . The brightness level corresponds to an element in the item select.

see

Hope this is of some use

2 Likes