Template sensor using float that changes state depending on power consumption

HI all,

I have electric fire with a binary sensor created using a power monitoring plug. I have created a sensor to show on or off state depending on whether the power drawn is more than 1 watt.

binary_sensor:
  - platform: template
    sensors:
      fireplace_status:
        friendly_name: "Fireplace Status"
        value_template: "{{ states('sensor.living_room_fireplace_energy_current_consumption')|float > 1.0 }}"

This works great but I want to extend it further. I want the state to as “on” when power is above 1 watt. Then update to “low” when power usage is above 800 watts and “high” when it goes above 1500 watts. Then the last value of less than 1 watt showing as off.

I am struggling to determine the float values when its increasing to then show the correct state. Any ideas on how I can format this?

Hi, a binary sensor can only have 2 values, so you need to create a normal template sensor.

Go to settings, devices, helpers.
Create helper
Template
Sensor

Then the template will be something like this

{% set power = states('sensor.living_room_fireplace_energy_current_consumption')|float(0) %}
{% if power > 1500 %}
high
{% elif power > 800 %}
low
{% elif power > 0 %}
on
{% else %}
off
{% endif %}
2 Likes

This works great thank you. Didn’t know that about binary sensors. Created a load of them but never had to create a sensor with various values before.

Appreciate your help