Template sensor stop working after upgrade from 2021.7.6 to 2021.8.7

Hello, I recently upgrade from 2021.7.6 to 2021.8.7 and unfortunately my template for Iotawatt doesn’t work anymore, I’m getting the value “Unknown” for both sensors (iotawatt_total & iotawatt_pool). I’ve looked into the doc / release and suspect that this may seem like an old nomenclature of template but it is unclear for me how to translate into the new one (if any).

Help is welcome, thanks.

#---------------------------- IotaWatt -------------------------------
  - platform: rest
    name: iotawatt
    json_attributes:
      - inputs
      - outputs
    resource: http://xxx.xxx.xxx.xxx/status?inputs=yes&outputs=yes
    value_template: '{{ value_json.inputs[0].Vrms }}v'
    scan_interval: 5

  - platform: template
    sensors:
      iotawatt_total:
        friendly_name_template: '{{ states.sensor.iotawatt.attributes["outputs"][0].name }}'
        unit_of_measurement: 'Watts'
        value_template: '{{ states.sensor.iotawatt.attributes["outputs"][0].value }}'

      iotawatt_pool:
        friendly_name_template: '{{ states.sensor.iotawatt.attributes["outputs"][10].name }}'
        unit_of_measurement: 'Watts'
        value_template: '{{ states.sensor.iotawatt.attributes["outputs"][10].value }}'


Do you still get values in your rest sensor ?

The Rest values work as I can display the sensor.iotawatt.
Also when I browse the resource URL I have the following:

{
“inputs”:
[{“channel”:0,“Vrms”:122.6721,“Hz”:60.0306,“phase”:0.07},{“channel”:1,“Watts”:“1196”,“Pf”:0.832978,“phase”:1,“lastphase”:0.93},{“channel”:2,“Watts”:“966”,“Pf”:0.878513,“phase”:1,“lastphase”:0.93},{“channel”:3,“Watts”:“779”,“Pf”:0.633783,“phase”:0.8,“lastphase”:0.73},{“channel”:4,“Watts”:" 0",“Pf”:0,“phase”:0.9,“lastphase”:0.83},{“channel”:5,“Watts”:" 0",“Pf”:0,“phase”:2,“lastphase”:1.93},{“channel”:6,“Watts”:“25”,“Pf”:0.989812,“phase”:2,“lastphase”:1.93},{“channel”:7,“Watts”:“25”,“Pf”:0.990173,“phase”:2,“lastphase”:1.93},{“channel”:8,“Watts”:“438”,“Pf”:0.658838,“phase”:1.7,“lastphase”:1.63},{“channel”:9,“Watts”:“214”,“Pf”:0.910605,“phase”:1.9,“lastphase”:1.83},{“channel”:10,“Watts”:“221”,“Pf”:0.87504,“phase”:1.8,“lastphase”:1.73},{“channel”:11,“Watts”:“90”,“Pf”:0.606376,“reversed”:true,“phase”:1.9,“lastphase”:1.83},{“channel”:14,“Watts”:" 0",“Pf”:0,“phase”:2,“lastphase”:1.93}],

“outputs”:
[{“name”:“a_Main_T_W”,“units”:“Watts”,“value”:2162.141},{“name”:“b_Main_T_A”,“units”:“Amps”,“value”:20.66936},{“name”:“b_Main1_A”,“units”:“Amps”,“value”:11.70371},{“name”:“b_Main2_A”,“units”:“Amps”,“value”:8.965653},{“name”:“c_Main_hz”,“units”:“Hz”,“value”:60.0306},{“name”:“d_Main1_VA”,“units”:“VA”,“value”:1435.718},{“name”:“d_Main2_VA”,“units”:“VA”,“value”:1099.835},{“name”:“e_Main1_PF”,“units”:“PF”,“value”:0.832978},{“name”:“e_Main2_PF”,“units”:“PF”,“value”:0.878513},{“name”:“HP_T”,“units”:“Watts”,“value”:487.2964},{“name”:“Pool”,“units”:“Watts”,“value”:778.6001},{“name”:“Unknown”,“units”:“Watts”,“value”:370.7785}
]}

I test JSON values with STATES from the developer tools and all values appear for sensor.iotawatt.

Also I just test developer tools with template and the value is good.

When using the value with a lovelace card

I don’t know why it worked before, but I checked here :

for legacy template sensor, there is friendly_name, but no friendly_name_template

1 Like

It’s a sensor, which does support it, apparently

But it is indeed the culprit.
OP, you should see an error in your logs: AttributeError: Attribute '_attr_name' does not exist

The root cause is that friendly_name_template is somewhat broken if the “source” (states.sensor.iotawatt.attributes["outputs"][0].name) is not available when the template is initialized.
Then, the creation of the template sensor fails, and never recovers.

Bottom-line: remove friendly_name_template
Adding the name as an attribute should work.

2 Likes

Thanks it fixed the issue by removing dynamic name “_template” and making it static. Look also I may need to redo a lot of my config that begin to be old method.