Hello all,
Could someone help me with the proper way to give the result of some math into a template sensor. The issue is I believe one or more of my sensors that are being added have a value of none? Are zero and none the same thing??
I should also add, I don’t know what I am doing so I am going to provide what I know and hope you guys can help me determine how to get it done.
I would also like to divide the results of the below by 25.4 because the input sensors are in mm but I would like the end of the math results to be in inches.
Thank you all!
Below are the 3 sensors I am trying to make:
previous_rainfall:
friendly_name: "Past 48h Rainfall"
unit_of_measurement: "in"
value_template: "{{ state_attr('sensor.rainfactor2', 'day0rain') | float + state_attr('sensor.rainfactor2', 'day1rain') | float }}"
previous_rainfall_five_day:
friendly_name: "Past 5d Rainfall"
unit_of_measurement: "in"
value_template: "{{ state_attr('sensor.rainfactor2', 'day0rain') | float + state_attr('sensor.rainfactor2', 'day1rain') | float + state_attr('sensor.rainfactor2', 'day2rain') | float + state_attr('sensor.rainfactor2', 'day3rain') | float + state_attr('sensor.rainfactor2', 'day4rain') | float }}"
daily_rainfall:
friendly_name: "Daily Rainfall"
unit_of_measurement: "in"
value_template: "{{ state_attr('sensor.rainfactor2', 'day0rain') | float }}"
Below is the error I am getting in the logs:
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:197
integration: Template (documentation, issues)
First occurred: June 8, 2024 at 10:00:46 PM (3 occurrences)
Last logged: June 8, 2024 at 10:00:46 PM
TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{{ state_attr('sensor.rainfactor2', 'day0rain') | float + state_attr('sensor.rainfactor2', 'day1rain') | float }}' but no default was specified') while processing template 'Template<template=({{ state_attr('sensor.rainfactor2', 'day0rain') | float + state_attr('sensor.rainfactor2', 'day1rain') | float }}) renders=6>' for attribute '_attr_native_value' in entity 'sensor.previous_rainfall'
TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{{ state_attr('sensor.rainfactor2', 'day0rain') | float + state_attr('sensor.rainfactor2', 'day1rain') | float + state_attr('sensor.rainfactor2', 'day2rain') | float + state_attr('sensor.rainfactor2', 'day3rain') | float + state_attr('sensor.rainfactor2', 'day4rain') | float }}' but no default was specified') while processing template 'Template<template=({{ state_attr('sensor.rainfactor2', 'day0rain') | float + state_attr('sensor.rainfactor2', 'day1rain') | float + state_attr('sensor.rainfactor2', 'day2rain') | float + state_attr('sensor.rainfactor2', 'day3rain') | float + state_attr('sensor.rainfactor2', 'day4rain') | float }}) renders=6>' for attribute '_attr_native_value' in entity 'sensor.previous_rainfall_five_day'
TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{{ state_attr('sensor.rainfactor2', 'day0rain') | float }}' but no default was specified') while processing template 'Template<template=({{ state_attr('sensor.rainfactor2', 'day0rain') | float }}) renders=6>' for attribute '_attr_native_value' in entity 'sensor.daily_rainfall'
Below is the sensor attributes I am trying to add together: