I still don't understand how to use the trend sensor for humidity

@petro , in this case @Edwin_D is correct. There is something changing, and that is time, which is a fundamental aspect of a gradient. The unit_of_measurement of a gradient or derivative is always UoM/TimeUnit, such as km/hr, %/sec, etc.

By definition, if the sensor does not change value over a period of time the gradient is 0.

So it isn’t a feature request. It’s a bug report.

@Edwin_D thank you for posting the feature request. I have not looked at the details of your submission, but I guess the easiest way to implement this would be to add a time delta at which the value is reassessed. It really should be performing some sort of smoothing, otherwise the gradient will jump all over the place if the sensor is changing sporadically while time is progressing in set intervals.

But somewhere in the HA community someone knows how to do this correctly because of the way the Sensor graph is displayed without/with detail, which is still a smoothed line compared to the History Graph. The screen shot is the display of the same sensor in these 3 methods.

1 Like

I never said it was or wasn’t correct. Again, I’m not here to discuss what’s right or wrong. I’m describing how it works. That’s it.

The graphs have a spline fit on them, they do not show actual values between the datapoints. It’s a fancy graphic that makes the data points connect without sharp corners.

@petro all I’m saying is that time is also an input sensor to the gradient.

Yes, I know the mechanics of splinning. I’m suggesting that the same math be used to establish the gradient.

I’m on my mobile now. I’ll send other thoughts on how to do this correctly from my laptop.

@petro this is how I would do it.

Time is a sensor with input to the Gradient calculation. The user can decide on the units and time bucket size, for example “00:01:00” would re-evaluate the gradient every minute. The gradient value is calculated every time value change, when the value of the sensor is checked.

We can’t calculate a gradient until we have 2 values for the value sensor.

IF V_now <> V_last then 
    V_last = V_curr
    V_curr = V_now
    Gradient = (V_curr - V_Last) / (T_curr - T_last)
    T_last = T_curr  
ELSE
    Gradient = (V_curr - V_Last) / (T_curr - T_last)
ENDIF

Time is a sensor with input to the Gradient calculation. The user can decide on the units and time bucket.

We can’t calculate a gradient until we have 2 values for the value sensor.

I deleted my comment so that I wouldn’t get into this discussion :wink:

I am trying to solve the issue by using a template sensor.

This is a line in my configuration.yaml file

template: !include template_sensors.yaml

This is the template_sensors.yaml file

  - trigger:
      - platform: time_pattern
        # This will update every minute
        minutes: /1
    sensor:
      - name: "Tado Load Update"
        unique_id: tado_load_update
        unit_of_measurement: "°C"
        state: >-
          {{ states('sensor.tado_total_load') | float | round(2, default=0) }}

I should them be able to use the sensor.tado_load_update in my trend sensor to get the correct gradient values.

The problem is that the sensor.tado_load_update is unavailable.

What am I doing incorrectly?

updates throttled when the states are the same to minimize database changes.

Try adding a small random amount without truncating the value with a round

 {{ states('sensor.tado_total_load') | float(0) + [0.0001, -0.0001] | random }}
1 Like

Thanks for the tip @petro

I changed it to

{{ states('sensor.tado_total_load') | float(0) + range(-10000,10000) | random  / 100000000}}

As can be seen in the graph below, it is working perfectly.

It seems that Derivative sensor works great. So i’m setteling it like this I tink. My final automation looks like this and it works pretty great:

alias: Ventilation bathroom on off
description: fan UP when showering and wait with off until humidity drops
trigger:
  - platform: numeric_state
    entity_id: sensor.humidity_derivative
    above: 3
condition:
  - condition: state
    entity_id: light.badkamer
    state: "on"
action:
  - service: script.fan_max
    data: {}
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.humidity_derivative
        below: 0
    timeout:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - service: script.fan_medium
    data: {}
mode: single

@miles I’ll still wil study you efforts regarding the Trend sensor. Steep learning curve for me.

2 Likes

Could you post your template for sensor.humidity_derivative please? I’m still unsure how to make the improvements you’ve all made.

Thanks

You don’t have to make a template. Atleast, I didn’t.
Go to Settings, and then Devices & Services settings, and then the “helpers” tab and add the Derivative. Fill in the timewindow you want to measure and ID of the humidity sensor and you’re good to go.

Reboot and see the behaviour of the output of the derivative sensor in the History, to base your automation decisions on.

1 Like

I’m having some problems with this setup.

Here’s my automation.

description: Turn on Dehumidifier when showering and wait with off until humidity drops
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.bathroom_humidity_dirivative
    above: 5
condition: []
action:
  - service: homeassistant.turn_on
    data: {}
    target:
      entity_id: switch.trader_control_plug_1
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.bathroom_humidity_dirivative
        below: 0
    timeout:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - service: homeassistant.turn_off
    data: {}
    target:
      entity_id: switch.trader_control_plug_1


The automation triggers very quickly, which is great, however, as soon as the shower is done, the dehumidifier causes the derivative to dive very quickly. As a result the dehumidifier turns off way quicker than I would like.

2 Likes

Track the humidity and turn off the switch when the humidity reaches a desired level. Or just use a timer after the derivative drops. I put a 20 minute delay after the drop before turning off my switch.

1 Like