Hi all,
I have a question about template sensors. I’m trying to define a template sensor which divides the values of two sensors, and does not give an error when the value in the denominator is zero.
So in my example, I have a template sensor which calculates the percentage of energy consumption that is monitored by pows as a fraction of the total power consumption. Now, for some reason, this total power consumption sometimes is zero and the template sensor gives errors. I think there must be a way to avoid this when creating the template.
Any advice is appreciated
PPee
- platform: template
sensors:
power_perc_pows:
value_template: "{{ '{:.1f}%'.format( (
states('sensor.power_realtime_total_pows') | float(0) /
states('sensor.dsmr_power') | float(0)) *100) }}"