Automation not triggering on passing boundaries

Apologies for this very basic question but I can’t figure it out. I have a cheap rain sensor which using ESPHome reports a voltage drop. I want to send out an email when that happens, so we know it’s raining and can bring the washing in :slight_smile:

The sensor, in ESP Home, is configured as below and I use the lambda to convert the value to a positive % instead of a voltage level drop. Looking at my Home Assistant dashboard, the values look fine.

  - platform: adc
    pin: A0
    name: "RainDensity"
    unit_of_measurement: "%"
    update_interval: 10s
    filters:
    - lambda: return (1 - x) * 100;

The automation is triggered like this:


platform: state
entity_id:
  - sensor.raindensity
for:
  hours: 0
  minutes: 0
  seconds: 0
from: "86"

But it never triggers although the value passes the 86 frequently. I tried many different values including 86%, 0.86 but it never works.

I’m wondering if it has something to do with the variable type of the reading returned by ESPHome that maybe it’s a string and not a number but not sure if that is the case or how to change that.

I put it in the configuration forum and not the ESPHome forum as I thought the problem is more likely to be in the Automation rather than the way the sensor is configured.

Thank you in advance for your guidance.

The State Trigger you defined will trigger only when the value changes from exactly 86 to some other value (higher or lower). It won’t trigger if the value changes from 85.9 to 86.1, only from 86 to another value.

I suggest you consider using a Numeric State Trigger. It will trigger the moment the sensor’s value crosses the threshold (86) value and rises above it (or below if you use the below option). It’s important to keep in mind it only triggers at the crossing of the threshold and not afterwards (it doesn’t continue triggering if the sensor’s value continues to increase above 86).

platform: numeric_state
entity_id: sensor.raindensity
above: 86

Thank you @123 - appreciate your help. I didn’t know that and again apologies about the basic question.

@123 - that worked. Thank you!

1 Like