I am using a template to convert a pool water value from C to F. I cannot change the original sensor value from C to F because it doesnt have it’s own unique ID. Issue is, it takes a few seconds upon startup for the original sensor to load and then it gives me an error in the system log that "there are no defualt values.
Error
TemplateError(‘ValueError: Template error: float got invalid input ‘unknown’ when rendering template ‘{{ (float(states(‘sensor.aqualogic_pool_temperature’)) * 9 / 5 + 32) | round(1) }}’ but no default was specified’) while processing template ‘Template<template=({{ (float(states(‘sensor.aqualogic_pool_temperature’)) * 9 / 5 + 32) | round(1) }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_current_temp_f’
Here is my template formula
“{{ (states(‘sensor.aqualogic_pool_temperature’) | float )*9/5+32 | round(2) }}”
How could I amend my formula to prevent this error?
You can either provide a default value to the float filter, or you can provide an availability template so that your template sensor is unavailable whenever the source sensor is unavailable.
This will default to using 0°C in your formula whenever the pool temperature is unavailable:
The availability template can only be defined in YAML. If your sensor was created using the UI, you’d need to delete it and recreate it in YAML.
template:
- sensor:
name: Pool Temperature Fahrenheit
unit_of_measurement: "°F"
state_class: measurement
device_class: temperature
state: "{{ ((states('sensor.aqualogic_pool_temperature') | float )*9/5+32) | round(2) }}"
availability: "{{ has_value('sensor.aqualogic_pool_temperature') }}"
Edit: also watch your order of operations. You were only sending the value of 32 to the round filter. The filter operator binds more tightly than multiplication or addition.