How to describe "when crossing a value" in an automation

I would like to automate some lights when the luminosity in the room crosses a certain threshold (say, 30 lux).

By “crosses” I mean that the trigger would be the fact that the luminosity was < 30 lux, and then becomes > 30 lux. I do not want to continuously switch on the lights when it is > 30 lux because someone may have decided they want to have the lights switched off (and switch them off after the automation switched them on). If the condition was simply > 30 lux, then the lights would get back on in the next cycle check.

What kind of trigger should I look at to do this?

This is exactly what a numeric_state trigger does.

It will only trigger when it goes from outside to inside the bounds by looking at the previous and current state.

1 Like

You will want to build in some “hysteresis” in that you don’t want the lights going on and off and on again if a cloud goes by and changes the luminance just a little for a short time. You want a gap between the ‘turn on’ luminance and the ‘turn off’ luminance.
For mine, I set it up using two separate automations. For one passing above ‘850’ turns the lights on, and for the other, passing below ‘750’ turns them off. That way they will remain on after being triggered, even if the ambient light goes below 850 and then above it again moments later.

Have you considered using a Threshold Binary Sensor?

Configuration Variables

  • entity_id string Required
    The entity to monitor. Only sensors are supported.

  • lower float (Optional)
    The lower threshold which the observed value is compared against.

  • upper float (Optional)
    The upper threshold which the observed value is compared against.

  • hysteresis float (Optional, default: 0.0)
    The distance the observed value must be from the threshold before the state is changed.

  • name string (Optional, default: Threshold)
    Name of the sensor to use in the frontend.

I’ll certainly look into it further, but from initial scan it wasn’t immediately apparent to me how to execute one or another action depending on which threshold was crossed. Being somewhat ‘old school’ I’m used to having to cobble needed functionality out of coarser raw materials, so hadn’t expected an integration like this to exist, but am glad to know it does. Thanks!