I have a similar question and I just can’t find such an example.
I have a script to call a service, just starting to program all things after.
Here is the script:
alias: Check and Add Spotify Favorite
sequence:
- action: spotifyplus.check_track_favorites
metadata: {}
data:
entity_id: media_player.spotifyplus_kevin_brown
response_variable: favorite_exists
- variables:
test: |
{{ favorite_exists }}
description: Checks and adds a favorite if the song is not already in favorites
icon: mdi:account-plus
The response in the service is like this (some info redacted):
this:
entity_id: script.check_and_add_spotify_favorite
state: 'off'
attributes:
last_triggered: '2024-10-22T22:07:03.487018+00:00'
mode: single
current: 0
icon: mdi:account-plus
friendly_name: Check and Add Spotify Favorite
last_changed: '2024-10-22T22:07:03.769852+00:00'
last_reported: '2024-10-22T22:07:03.769852+00:00'
last_updated: '2024-10-22T22:07:03.769852+00:00'
context:
id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
parent_id: null
user_id: xxxxxxxxxxxxxxxxxxxxxx
context:
id: xxxxxxxxxxxxxxxxxxxxx
parent_id: null
user_id: xxxxxxxxxxxxxxxxxxx
favorite_exists:
user_profile:
country: US
display_name: Kevin Brown
email: xxxxxxxxxxxxxxxxxxxxxxxxxx
id: xxxxxxxxxxxxxxxxxxxx
product: premium
type: user
uri: spotify:user:xxxxxxxxxxxxxxxxxxxxxxx
result:
2tUBqZG2AbRi7Q0BIrVrEj: false
The only thing I want is the “false” or “true” at the end. This literally means the current song is my favorites “true” or not “false”.
I cannot even seem to get the value. If I look at the variable, it is populated:
test:
user_profile:
country: US
display_name: Kevin Brown
email: xxxxxxxxxxxxxxxxxxx
id: xxxxxxxxxxxxxxxxxxxxxxxx
product: premium
type: user
uri: spotify:user:xxxxxxxxxxxxxxxxxxx
result:
2tUBqZG2AbRi7Q0BIrVrEj: false
The key “2tUBqZG2AbRi7Q0BIrVrEj” changes with each request.
I can get deeper with this:
variables:
test: |
{{ favorite_exists.result }}
Which yields:
test:
50nfwKoDiSYg8zOCREWAm5: false
How do I get this value under result, what is the syntax? Simply put, in the following I would like to edit that template for test so that it returns “true” or “false” for further processing in the script to update GUI in certain ways.
- variables:
test: |
{{ favorite_exists.result**what_belongs_here** }}
Note: I suppose I can just create a new sensor that updates with each song change and just use that, but I was hoping not to do that
Solution is:
variables:
test: "{{ (favorite_exists.result.values() | list)[0] }}"