Unexpected results with "homemade" sensors configuration

Hello,

To detect the presence of my baby in her bed, I use two temperature sensors.
One under her mattress (sensor A), whose temperature rises when she’s in bed. A second, far from her (sensor B).
Next, I created a virtual sensor (sensor C) that subtracts sensor A from sensor B. If sensor C > 1°C, then I know my daughter is in bed.

Now I’d like to create trend sensors to track whether temperature of sensor C is increasing or decreasing. I need them to control the bedroom lights and speaker. If the temperature increases or is above 1°, my daughter is in bed and we turn everything on. If the temperature drops, she’s no longer in bed and everything has to be switched off.

My problem is about the trend sensors that don’t work as I’d like. I’ve tried configuring them with the following parameters:

  • Trend sensor is up if the temperature rises by 0.5° over a time interval of 10 minutes.
  • Sensor trend is up if the temperature rises by 0.6° over a 10-minute interval.

But as you can see from the annotated graph below, even very short micro variations (less than 10 minutes) counter-current point measurements distort the trend. I wish them not to influence the trends. And some trends are completely ignored, for example, the rise between 12 and 12.50.

Here is my configuration :

sensor:
  - platform: template
      ecart_temp_bed_child:
        friendly_name: "Bed presence sensor"
        unit_of_measurement: "°C"
        value_template: >
          {{ states('sensor.bed_baby_body_2')|float - states('sensor.bed_baby_temoin')|float }}

binary_sensor:
  - platform: trend
    sensors:
      ecart_temp_baby_trend:
        entity_id: sensor.ecart_temp_bed_child
        friendly_name: Trend increasing
        min_gradient: -0.0001
        sample_duration: 600

  - platform: trend
    sensors:
      ecart_temp_baby_trend_increase:
        entity_id: sensor.ecart_temp_bed_child
        friendly_name: Trend decreasing
        min_gradient: 0.00083
        sample_duration: 600

And here is a preview of results for today in Lovelace. I’ve added comments about things that are problematic for me:

I think there is something wrong with the configuration of my trend sensors. My point is of course to be able to turn off the speaker and the lights as soon as possible when the room is empty (I can’t take lullabies all day long :joy:) but also to avoid false positives to prevent baby to awake accidentaly. Can someone help me improve my settings?

Thank you so much.

Have you thought about a better sensor?

Many thanks @tom_l for your answer !
These days, between work and the baby, I’m not going to have much time to devote to making a sensor, and I have to admit that not being much of a DIYer, the tutorial scares me a bit :joy:

My method is home-made, but so far the C sensor works pretty well to tell whether the baby is in bed or not (temperature > 1°C). I’m more worried about managing trend sensors to turn off my devices more quickly when the temperature drops significantly.