SOLVED: Custom sensor becomes unavailable after update to 0.116.0

Dear all, I was hopping you can help me as I dont know what else to try.

I have a sensor which measures my daily energy consumption, sensor as follows:

power_consumption_today_total:
        value_template: '{{ (float(states.sensor.todays_power_consumption_normal.state) + float(states.sensor.todays_power_consumption_low.state) + (float(states.sensor.pv_outputpowertoday.state) - float(states.sensor.power_production_today_total.state))) | round(2) }}'
        unit_of_measurement: 'kWh'
        friendly_name: "DSRM Power consumption today"

When I put this in the template I get this outcome:

power_consumption_today_total:
value_template: ‘4.2’
unit_of_measurement: ‘kWh’
friendly_name: “DSRM Power consumption today”

However in lovelace the sensor shows unavailable. If I roll back to 1.114.4, the sensor works, so I dont know what broke in the mean time. I read all breaking changes but there was nothing related to custom sensors.

Did you upgrade to 0.115 or jump straight to 0.116 ?
I ask as there were changes made to how template entity updates were triggered in 0.115

Have a read of the ‘Startup’ section at the link below, it may be the solution to your problem

So instead of

states.sensor.todays_power_consumption_normal.state

You’d have

states('sensor.todays_power_consumption_normal')

Excellent! I jumped directly to 0.116.1.

So I changed the code to"

      power_consumption_today_total:
        value_template: '{{ ((states.sensor.todays_power_consumption_normal.state) | float + (states.sensor.todays_power_consumption_low.state) | float + ((states.sensor.pv_outputpowertoday.state) | float - (states.sensor.power_production_today_total.state) | float)) | round(2) }}'
        unit_of_measurement: 'kWh'
        friendly_name: "DSRM Power consumption today"

Now it works, so basically moving the custom float to the end of the statement when declaring the sensor.

Interesting that the old way was still working in the template part, but not in lovelace.

In anycase this is solved, big thanks!

1 Like