I’ve created my first Trend sensor in my HA config YAML file with the following:
binary_sensor:
- platform: trend
sensors:
oil_drop:
entity_id: sensor.distance_to_oil
sample_duration: 30
max_samples: 30
min_gradient: 0.01
This is with the intention of detecting if the level of heating oil in my tank starts to drop at a rate much higher than normal usage rate with the heating on. This will hopefully indicate a sudden leak or theft for example.
In the event of one of these happening, the distance from the oil surface to the sensor will increase, so I have made the min_gradient positive, and as a starting point, based it on a change of 0.01m per second (guessing the rate would be higher than this in the event of a theft/being siphoned out).
With the sensor on my desk plugged into my ESPhome board I’m trying to get this Trend sensor setup and tested before fitting the level sensor to the tank, but I’m a bit unsure about the results I am seeing.
Upon a reboot of my ESPHome device, the Trend sensor shows a status of ‘unknown’ for around a minute or so. Am I correct in in my understanding that this would remain in an unknown state until there is at least some change in my distance reading from the sensor, at which time it will stay in an ‘off’ state until the readings create a gradient of at least 0.01? When this happens, how long will the Trend sensor remain in the ‘on’ state? Until the gradient from 30 samples goes below 0.01? As my sensor takes a reading every 1 second (just for testing purposes), then it will take a minimum of 30 seconds for the sensor to go off again if the gradient has reduced?
If that’s the case, I’m not sure what’s wrong, as during testing, and invoking a positive change in distance, my sensor showed a state of ‘on’ but remained in this state for over an hour - even though the distance did not change at all during this hour.