Send value on change

Hi there,
I’m new to HA and especially ESPHome.
I’ve set up an wemos d1 mini to measure temperatures of my heating system. I want to capture the Temperature quite fast and calculate the temperature change with a derivative helper in HA. That works fine sofar.
But I am thinking of reducing wifi traffic by doing the calculation of the temperature change on the ESP and only send an update if the value changes, to avoid unnecessarily wifi traffic. Currently I’m sending the values every second.
Can anyone help me with the code?
Here is the current code:

dallas:
  - pin: GPIO14
    update_interval: 1s



sensor:
  - platform: dallas
    address: 0xb13ce10457bb2d28
    name: "Temperatur Zirkulation Vorlauf"

  - platform: dallas
    address: 0x843ce1045777a928
    name: "Temperatur Zirkulation Rücklauf"

If you manage to stop sending values if there’s no change, then beware that the HA derivative sensor will not work well because of it. The derivative will only calculate on new data. If there is no change, the derivative should go to zero. But it won’t, if you don’t send the duplicate value. So you will need to find a way to get around that until it is fixed.

My goal is not to use the derivative sensor in HA, and do the calculation on the ESP instead.
Current situation: ESP sends temperatures every second to HA and there I use the derivative sensor to detect changes.

Plan: detect the temperature change on the ESP and only send a value if its greater than a certain value.

According to the docs, you can set the temp sensor to internal to prevent sending the data to HA:

  • internal (Optional, boolean): Mark this component as internal. Internal components will not be exposed to the frontend (like Home Assistant). Only specifying an id without a name will implicitly set this to true.
    Sensor Component — ESPHome

A simple version of a derivative can be calculated using this description:

However, I doubt that will work well on temperatures, a better one will be harder, maybe by calculating an average using a filter (see also the filter docs I mention in the next point).

And if you want to only send the derivative if its value is above a certain value, a delta filter would help you avoid sending smaller values:

But remember, if you only send the derivative if it is high, how would you react to it changing from small to big or vice versa? Or is it that you only want to sent the temperature if the derivative is high? That would be weird because the temperature in HA would not change after a long gradual rise or fall.

Sending a value every second isn’t particularly taxing on your wifi.

However if you want to slow things down there are many filters.

I think the best solution for you here is to not actually calculate the delta, but to use a delta filter this way with an or: filter.

Best of both worlds, quick updates when something changes, with a reasonable time based backbone.

You could for example have your sensor updating every 1s, but results only being pushed to HA if the change is more than 1 degree or at most 10s.

Please, how this can be done?

It’s pretty much per the example in my link.

Reducing wifi traffic and by limiting the frequency of a sensor value? Did your wifi router come free when you signed signed up with AOL and bought a 56k dial-up modem by chance??