If the value needs to by dynamic/editable through HA actions then your best bet is probably:
If the json is going to be relatively static, and you don’t mind being limited to manually editing it, you could also store and retrieve it in the same way you do Template macros. This is an undocumented use of the custom templates files, but it does work generally… though, I’ve never tested it for this exact use.
In use you would just copy paste your set statement from your post into a file, for example cd_changer.jinja, then your action would be something along the lines of:
alias: New automation
description: ""
triggers:
- trigger: state
entity_id:
- sensor.esp8266_test_playing_disk
conditions: []
actions:
- action: input_select.set_options
metadata: {}
data:
options: |
{% from 'cd_changer.jinja' import my_test_json %}
{{ my_test_json.cd[states('sensor.esp8266_test_playing_disk') |int -1].Tracks}}
target:
entity_id: input_select.cdp_cd_list
mode: single
Note that I have altered the action you had in your original post since it did not make sense to use the value from the NumberTracks attribute there.
FWIW, you would probably be better off using a Template Select instead of an Input Select + multiple automations.
