A subtraction of 2 sensor values in a Lovelace Gauge card

Hi

Trying hard to get a subtraction value of 2 sensors into a Lovelace gauge card. I have a water heating system on solar panels and I like to know the delta T between outgoing and ingoing T.

This is what I put into it:
‘’’
type: gauge
sensor:

  • platform: template
    sensors:
    delta_t_solar_heating:
    friendly_name: Delta T
    unit_of_measurement: C
    value_template: >- {{(states(‘sensor.sonoff_1000bee0f9_temperature’) | float | round(1)) - (states(‘sensor.sonoff_1000bee815_temperature’) | float | round(1))}}

entity: sensor.delta_t_solar_heating
min: 0
max: 5
name: Delta T Solar Heating
‘’’
I get entity not available. Not a big surprise but what am I doing wrong here?

Could you please format your pasted code correctly.

no. I tried

See step 11 here: Help us help you

again I have tried but no clue how it’s done.

You’re using the wrong key. Don’t use the single or double quote mark. Use the tick mark that’s on the same key as the tilde.

No such key on my board

Probably hidden.

Can somebody help me with my real issue here please :pray::pray::pray:

No we cant. The photo you have taken not only makes it difficult for us to copy and paste a reply but it does not even show the entire template.

The key you want is between z and left shift on your keyboard. You need to learn how to do this. We’re not being difficult, it really is important as the link I posted explained.

Looking at your original post, the formatting is all wrong, so that’s why it wouldnt work. However since it’s not posted as a codeblock, the formatting could be fine. No way to tell.

Looking at your other post that has a photo of the template editor, the entity: sensor.delta_t_solar_heating is entirely out of place, and doesnt have the same code as your first post. Hence it’s quite helpful to see the entirety of your code, correctly formatted, to be able to see where the issue is.


sensor:
  - platform: template
    sensors:
      delta_t_solar_heating:
        friendly_name: Delta T
        unit_of_measurement: °C
        value_template: >-
          {{ ( states('sensor.sonoff_1000bee0f9_temperature') | float |
          round(1)) -  ( states('sensor.sonoff_1000bee815_temperature') | float
          | round(1))}}
type: gauge
name: Delta T Solar Heating
entity: sensor.delta_t_solar_heating
max: 100
min: 0

this is what i have done

If you have all of that in Lovelace for a gauge card, that won’t work.

The sensor part needs to be defined in your configuration.yaml (or elsewhere if you have a split-up configuration or are using packages).
IE this part needs to be in you configuration (not lovelace):

sensor:
  - platform: template
    sensors:
      delta_t_solar_heating:
        friendly_name: Delta T
        unit_of_measurement: °C
        value_template: >-
          {{ ( states('sensor.sonoff_1000bee0f9_temperature') | float |
          round(1)) -  ( states('sensor.sonoff_1000bee815_temperature') | float
          | round(1))}}

Then the other parts of the code, where you define the gauge, those should be in lovelace.

The value_template looks good and should work.

1 Like

Thanks :+1:

The value template I have tested and it returns the right value.

I will adapt my config.yaml and see.

Thanks again and sorry about the format…

1 Like

It works! I learned somethings :sweat_smile: THANKS

1 Like

Hi,
Your post was helpfull to make a subtraction between to power sensors.
I’m calculating the remain not used solar power that i’m returning to grid.
This is my code and is working:

  • platform: template
    sensors:
    producao_menos_consumo:
    friendly_name: ‘Retorno à Rede’
    unit_of_measurement: ‘W’
    value_template: >-
    {{ ( states(‘sensor.scb_ac_power_2’) | float |
    round(1)) - ( states(‘sensor.scb_home_power_2’) | float
    | round(1))}}

I need to put some code that the product of this subtraction only will be show if positive.
Can you help?

Is it working or not? You say it’s working but you need help. :man_shrugging:

And as probably 10 posts in this topic has covered. Post the yaml withing a code block os that it’s readable

I need to know what can I put on the yaml code to obtain pnly positive values.
I want to discard negative values
Thanks

not sure if still needed, but you can try something like this:

template:
  - sensor:
      - name: "PV Leistung"
        unit_of_measurement: "W"
        state: "{% if states('sensor.PV_Power')is not none %}
            {% if states('sensor.PV_Power') | int < 0 or states('sensor.PV_Power') | int > 10000 %} 
            {{0}}
            {% else %}
            {{ states('sensor.PV_Power') | int }}
            {% endif %}
            {% else %}
            {% endif %}"

Thanks :+1:t2:
I did found a solution.

A bit late, but the next time you can always use ALT codes( ALT+123)
https://www.alt-codes.net/