Choosing a vlaue for a template sensor

Would anyone be kind enough to help me with choosing a template sensor value? I’m trying to estimate the output of my heat pump using flow rate and flow/return temperatures. I want to set the current flow rate according to which pump is on.
HP_WaterPump1Status is 1 if the heatpump is circulating, 0 if it is off and its flow rate is input_number.flow_rate_hw (e.g. 14 l/min)
HP_WaterPump2Status is 1 if the underfloor heating pump is on and the flow rate increases to
input_number.flow_rate_htg (e.g. 17 l/min).
The is the entry in configuration.yaml I came up with:

template:
  - sensor:
     - name: HP flow rate now
      state: "{{ states('HP_WaterPump1Status')|float * states('input_number.flow_rate_hw')|float + states('HP_WaterPump2Status')|float * (states('input_number.flow_rate_htg')|float - states('input_number.flow_rate_hw')|float) }}"
      unit_of_measurement: l/min
      unique_id: HP_flow_rate_now

It returns “unavailable”.
A more logical solution whould be to choose between 3 values (0, 14 or 17 in this example) according to which pump is on. I couldn’t see any examples on the forum showing how to do this so I resorted to arithmentic!

this above is not an entity, should be something like sensor.hp_…
try it out first in devtools > template

1 Like

As vingerha stated above, you did not actually include the entity id’s for your water pump status entities. Below I have assumed that they are in the sensor domain, make sure to adjust them if that is not the case.

template:
  - sensor:
     - name: HP flow rate now
        state: > 
          {% if states('sensor.hp_waterpump2status') | bool %}
            {{ states('input_number.flow_rate_htg') }}
          {% elif states('sensor.hp_waterpump1status') | bool %}
            {{ states('input_number.flow_rate_hw') }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: l/min
        state_class: measurement
        unique_id: HP_flow_rate_now

Thank you both. I would dearly love to know how to do these things without constantly asking for help. Is there a syntax manual or tutorial that I can access?

That would be this one to start with.
Lots of trying it out is the best way and you will get there… in time :slight_smile:
Templating - Home Assistant (home-assistant.io)

1 Like