I have a sensor that returns a single value from a JSON array of arrays, but I’d really like to have multiple templated values returned, or possibly an array that I can then extract the value I need in the script/automation. Is this possible?
This is the extract from my configuration.yaml
rest:
- authentication: basic
scan_interval: 28800
resource: http://192.168.20.145:8123/local/files/MediaPlayerLookUp.json
# unique_id: 8dc1ba09-da1d-4831-9e9f-92b70f6b32c1
sensor:
- name: "Media Look up Attributes"
json_attributes_path: "$.0"
value_template: >
{% for x in value_json %}
{% if is_state('input_text.requested_channel_name', x['intent']) %}
{{ x['satchannelnumber'] }}
{% break %}
{% endif %}
{% endfor %}
If I simply add attributes:
to the sensor then I get the attributes, but always from the first array in the JSON.
My JSON is something like this;
[
{
"intent": "bbc one",
"satchannelnumber": 101,
"satchannelname": "BBC ONE WstHD",
"freesatchannelid": 564,
"freesatchannelname": "BBC ONE South West HD",
"freesatlogourl": "BBCOneHD-Web-Logo-135x76.jpg",
"cablechannelnumber": 101,
"cablechannelname": "BBC ONE West HD",
"chromechannelnumber": 101,
"chromechannelname": "BBC ONE WEST HD"
},
{
"intent": "bbc two",
"satchannelnumber": 102,
"satchannelname": "BBC TWO HD",
"freesatchannelid": 700,
"freesatchannelname": "BBC TWO HD",
"freesatlogourl": "BBCTwoHD-Web-Logo-135x76.jpg",
"cablechannelnumber": 102,
"cablechannelname": "BBC TWO HD",
"chromechannelnumber": 102,
"chromechannelname": "BBC TWO HD"
},
...
Chris