I am trying to create a template senor that will return “On” if a physical sensors value is between 2 values set by input_numbers or “Off” if it falls outside. The template I have works in developer tools > Template but the sensor’s state appears as unavailable.
Here’s what i have tried:
binary_sensor:
- platform: template
sensors:
res1_safe:
friendly_name: "Reservoir 1 pH Safe"
value_template: >
{% set upper = states('input_number.reservoir_1_ph_max') | float %}
{% set lower = states('input_number.reservoir_1_ph_min') | float %}
{% set current = states('sensor.reservoir_1_ph') | float %}
{{ current >= lower and current <= upper}}
binary_sensor:
- platform: template
sensors:
res1_safe:
friendly_name: "Reservoir 1 pH Safe"
value_template: >
{% set upper = states('input_number.reservoir_1_ph_maximum') | float(default=0) %}
{% set lower = states('input_number.reservoir_1_ph_minimum') | float(default=0) %}
{% set current = states('sensor.reservoir_1_ph') | float(default=0) %}
{{ current >= lower and current <= upper}}
this is strange though…
my config is copied from a working live HA up to date env running on a Hyper V platform, the only difference now is this HA env is running directly on a physical x64 based machine… previously it never cared if floats had defaults or not but now it does!