I have the following as an attribute on a REST sensor:
[
{
"channel":0,
"Vrms":214.4288,
"Hz":50.0122
},
{
"channel":1,
"Watts":" 6",
"Pf":0.554446,
"reversed":true
},
{
"channel":2,
"Watts":" 5",
"Pf":0.352379
},
{
"channel":3,
"Watts":" 8",
"Pf":0.782653
},
{
"channel":4,
"Watts":"219",
"Pf":0.998824
},
{
"channel":7,
"Watts":"1554",
"Pf":0.984729
},
{
"channel":9,
"Watts":" 5",
"Pf":0.847378,
"reversed":true
},
{
"channel":10,
"Watts":" 0",
"Pf":0
},
{
"channel":11,
"Watts":" 0",
"Pf":0
},
{
"channel":12,
"Watts":" 0",
"Pf":0
},
{
"channel":13,
"Watts":"129",
"Pf":0.642825,
"reversed":true
},
{
"channel":14,
"Watts":"10",
"Pf":0.618324
}
]
And would like to create template sensors for each of the elements with something like this:
{% for input in states.sensor.iotawatt.attributes.inputs %}
{%- if input.Watts %}
{{ input.channel }}: {{ input.Watts }} W, {{input.Pf}}
{%- endif %}
{%- endfor %}
Is that possible or do I need to create 14 separate template sensors like this below?
sensor:
- platform: template
sensors:
iotawatt_input_1:
friendly_name_template: {{ states.sensor.iotawatt.attributes.inputs[1].channel }}
value_template: {{ states.sensor.iotawatt.attributes.inputs[1].Watts }}