Help - difference in percentage of the first value

Hi,

I’ve got a numeric value which is basically an euro valuta: € 1000,- this doesn’t change.
Another value (in euro) does change every now and then.

I want to know the difference in percentage of the first value.
How can I set this up?

Is a numeric helper a way to go? I don’t think so because then I need to define a step size…

Use a template sensor.

How to set up the first value? the value that doesn’t change.

I think that I need to have a statistics sensor a “state characteristic change”
and a template sensor that gives me the percentage, but I don’t know how to define the static numeric value.

You don’t have to define numeric constants, you just use them in your templates.

template:
  - sensor:
      - name: "Percent difference from 1000"
        state: "{{ 100 * ( 1000 - states('sensor.your_sensor_here')|float(0) ) / 1000 }}"
        unit_of_measurement: "%"
        availability: "{{ states('sensor.your_sensor_here')|is_number }}"

Ty for the suggestion. If the static value of 1000 changes in the future, do I only need to change the 1000 in the state line (twice)?

Nevermind.
My phone refused to scroll completely to the right. :frowning:

And yes replace 1000 twice in the calculation.

If the static value changes then it is not static and you should use an input number helper so that you can change it from your dashboard.

template:
  - sensor:
      - name: "Percent difference from a non-static number"
        state: "{{ 100 * ( states('input_number.your_non_static_number')|float(0) - states('sensor.your_sensor_here')|float(0) ) / states('input_number.your_non_static_number')|float(0) }}"
        unit_of_measurement: "%"
        availability: "{{ states('sensor.your_sensor_here')|is_number and states('input_number.your_non_static_number')|is_number }}"
1 Like

I’m testing with this but I get a not expected outcome of 96,07%
I have set the input number to 100 and the “sensor.you_sensor_here” is currently 3,93 €

But it should be 2444 % (rounded), right?
I’ve used Percentage Calculator (%)
from 3,93 to 100 = 2444.5292620865134%

Try this:

state: "{{ 100 * ( states('input_number.your_non_static_number')|float(0) - states('sensor.your_sensor_here')|float(0) ) / states('sensor.your_sensor_here')|float(0) }}"

((value1 - value2) / value1) * 100

Nope.

((value2 - value1) / value1) * 100

( 100 - 3.93 ) / 3.93 ) * 100 = 2444

Which is what I wrote.

My suggestion is calculating the percentage difference in relation to the value first value.
Tom_l’s suggestion is calculating the percentage difference in relation to the second value.

Both are valid. It is a question of what the person wants of view.

ok to make it concrete. I have a break even amount on investments that is 3.5 euros. if the share price reaches 4 euros, I want to know how many percent it has gone up or down

Hm two suggestions, not sure which one I’m looking for haha

((4,0 - 3,5) / 3,5) * 100%= 14,28571428571%

3,5 * 14,28571428571% = 0,5

They told us. There is no question.

Thank you both!