# Passing a payload when a value changes by a specific value

I’m drawing a blank.

What node would I be using if I wanted to watch a sensor, like a thermometer, but I wanted a notification every time the sensor changed by a value of 5.

So, if it started at 32 degrees, at 37 degrees I would get a notification. Again at 42, and again at 47, etc. Or 30 - 35 - 40 - 35 - 40 - 45 - 50 - 45, etc.

So every time it shifted by that value, the message would be passed to the next node.

Is this start value fixed or should it be set at some time of the day?

I would use a function node.
But that is because I can see a logic and have no issues with the code.

My HA installation is currently down since we moved two weeks ago so all I can give you is pseudo.

Have a input number with the integer divider of the temperature.
What I mean is, let’s say we start at 10 and input_number = 0.
The temperature goes up to 15.
The calculation would be Math.floor((15-10)/5) = 1
When you get to 20:
Math.floor((20-10)/5) = 2

And so on.

This calculation is set to the input_number.
When the temperature drops the input number will also drop.

Now that I think about it…
It doesn’t have to be an input_number. It can be a template sensor.
Just use int to truncate the decimals instead of math.floor.

Then just use the input number as your start in the sequence.
That is probably the easiest.
Sorry I can’t give you a better code/configuration.

The start value could be set at a specific time of day, or based on some other criteria. I can figure out a way to generate a start value based upon conditions.

So, you’re saying as long as there’s a basis, you can create a scale of increments based upon a denominator, then just watch for the increment change and fire the message at that point.

So, if it starts at zero, we divide each state value by 5 until the value is at least 1. When the calculated value changes from zero to 1 (i.e. zero to 5 / 5), we have our trigger. Then, again when we have 2.

How do I handle converting the division from a float to a rounded integer so I don’t round up or down to the next or previous number?

Something like this:
Assuming you are going to use a input_number as start value that will be set with an automation at a specific.

``````{{ ((states('input_number.start')-states('sensor.temperature'))/5) | int }}
``````

This should truncate the value.
Meaning
1.1 = 1
1.99999 = 1

That is probably what you want and not rounding as it trigger at the wrong temperatures

Use RBE node for that

I’ll probably be storing the current value of the sensor at a given time in a global variable which I’d then use as the basis, and then that starting value could vary from day to day, hour to hour, etc…depending on what I’m measuring.