I have a json-list that looks like this:
{"playlist": "["Endorfin", "Flatline", "Nedforsbacke pa varen", "Husbat", "Brotfest", "Electartica", ".DS_Store", "Solnedgang och ol", "Sjunga med", "Ledset", "00s gott", "Elektronisk lowpop", "Ambient", "Afusktiskt", "Raggaragga", "cgi-bin", "Sweet n sour", "Chill", "Konstig pop", "Forfest", "Nyklassiskt"]"}
and I’m trying to get it like this:
- platform: rest
resource: http://127.0.0.1:8091/cgi-bin/playlist.py
value_template: '{{value_json.playlist}}'
name: playlist
I would like to use the values of that list as the values in a dropdown, but right now I only get “unkown”, i can change the json if that helps, I wrote it
fabaff
(Fabian Affolter)
June 4, 2017, 7:55pm
2
This doesn’t look like valid JSON.
The documentation contains an example about how to access data in a list.
1 Like
Yes, it was invalid, however still not sure how/if I could use that list in an input_select, I tried this for example:
input_select:
playlist:
options: {{ states.sensor.playlist.state }}
but it doesn’t work, and there seems to be no data_options: attribute.
I tried this aswell, but it seems to just make a string of it.
- platform: rest
resource: http://127.0.0.1:8091/cgi-bin/playlist.py
value_template: >-
{% for playlist in value_json.playlist %}
- {{ playlist }}
{% endfor %}
name: playlist
fabaff
(Fabian Affolter)
June 5, 2017, 8:05am
5
There you can find an example of how to get a value out of a list.
The API returns…
{
"smartd": [
{
"username": "root",
"status": "S",
"cpu_times": [
0.01,
0,
0,
0
],
"name": "smartd",
"mandatory_stats": true,
"cmdline": "/usr/sbin/smartd -n -q never",
"standard_stats": true,
"cpu_percent": 2,
"pid": 1077,
"io_counters": [
0,
0,
0,
0,
0
],
"memory_percent": 0.02557626287395782,
"memory_info": [
…
1 Like
Thankyou! The actual problem:
I have a rest-sensor that outputs this:
['Endorfin', 'Flatline', 'Nedforsbacke pa varen', 'Husbat', 'Brotfest', 'Electartica', '.DS Store', 'Solnedgang och ol', 'Sjunga med', 'Ledset', '00s gott', 'Elektronisk lowpop', 'Ambient', 'Afusktiskt', 'Raggaragga', 'cgi-bin', 'Sweet n sour', 'Chill', 'Konstig pop', 'Forfest', 'Nyklassiskt']
I would like to use it as an input to options, currently It’s hardcoded like this:
input_select:
playlist:
options:
- Endorfin
- Flatline
...…