Template sum energy monitors

Hi All,

This template was working well to sum together my total ‘tracked’ power usage, which is helpful in identifying the ‘untracked’ (total - tracked) energy use in the house… But, has recently stopped working

 {{ states.sensor 
        | selectattr('attributes.unit_of_measurement', 'equalto', 'W') 
        | selectattr('entity_id', '!=', 'sensor.household_power_usage')
        | selectattr('entity_id', '!=', ' sensor.shelly_shem_c45bbe79043f_2_current_consumption')
        | selectattr('entity_id', '!=', 'sensor.total_tracked_devices_energy_now')
        | selectattr('entity_id', '!=', 'sensor.unaccounted_energy_use')
        | map(attribute='state') | map('float') | list | sum }}

I now get an error: UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'unit_of_measurement' Could someone point me in the right direction, I’m guessing a recent upgrade has made my code problematic?

TIA

Looks like since then you have a sensor that has not got the unit_of_measurement attribute, so you should check for entities having it first.

add

        | selectattr('attributes.unit_of_measurement', 'defined')

before

        | selectattr('attributes.unit_of_measurement', 'equalto', 'W') 
1 Like

Thanks, would there be an easy way to find that, I have a lot of entities! 50+ within this template

Was the need for this ever announced as a breaking change?

Just discovered one of my templates (that you helped me with :slight_smile:) didn’t work because of this but there was nothing in the logs to say it was failing.