Numeric_state above threshold, but only if it was 0 previously

I need a trigger for a numeric value, that goes off when the state value is above a specific value, but ONLY if the previous value is 0 (zero).

The numeric_state does not allow ‘from:’.

How do I achieve this?

Use from zero as the trigger, and the condition is over specified number.

Thanks. Will test both this and the other way around

automation:

  - alias: test1
    trigger:
      - platform: numeric_state
        entity_id: sensor.random
        above: '1'
    condition:
      - condition: state
        entity_id: sensor.random
        from: '0'
    action:
      - service: notify.telegram
        data_template:
          message: "Test 1 - Sensor has raised above {{ trigger.to_state.state }} {{ trigger.to_state.attributes.unit_of_measurement }}."

  - alias: test2
    trigger:
      - platform: state
        entity_id: sensor.random
        from: '0'
    condition:
      - condition: numeric_state
        entity_id: sensor.random
        above: '1'
    action:
      - service: notify.telegram
        data_template:
          message: "Test 2 - Sensor has raised above {{ trigger.to_state.state }} {{ trigger.to_state.attributes.unit_of_measurement }}."
1 Like

Strangely enough, only test 2 is a valid configuration.

@anon43302295 Do you know why?

1 Like

Because condition doesn’t support from :slight_smile:

That makes sense. :slight_smile:
From the documentation only state: is supported, I guess

I have been experimenting the last few days. And have not found a solution yet. Probably because the sensor can have both 0 as 0.0 (mind the decimal) as a value. Because of this, I think, the from: trigger does not work.

This happens with the Buienradar sensor

What is working, of course, is a notification when not using a from trigger and not using a condition:

sensor:
  - platform: buienradar
    name: Buienradar
    latitude: !secret home_latitude
    longitude: !secret home_longitude
    timeframe: 30
    monitored_conditions:
      - precipitation_forecast_average

automation:
  - alias: Rain Alarm
    trigger:
      - platform: state
        entity_id: sensor.buienradar_precipitation_forecast_average
    action:
      - service: notify.telegram
        data_template:
          title: "Regenalarm"
          message: "De komende 30 minuten wordt {{ trigger.to_state.state }} {{ trigger.to_state.attributes.unit_of_measurement }} neerslag verwacht"

I am now trying a platform: template trigger.

I use forcast_total, which because of the low trigger level only triggers if it has been 0 before;

    platform: numeric_state
    entity_id: sensor.br_precipitation_forecast_total
    above: 0.01

By the way, if the problem is caused by 0 and 0.0 can’t you just round the result within your template? Otherwise you can set and input boolean when it’s zero and use that as a condition.

Do you use the numeric state as a trigger or condition?

Rounding it means creating a value template. I think I can’t use the trigger.to_state.state any longer.

As a trigger.