Using 'analogure_threshold' sensor in ESPHome

I have a ADC measuring battery voltage, and create an analogue_threshold sensor from this.

My problem is this line:

             binary_sensor.is_true: Septic_tank_12v_battery

The error is “Unable to find condition with the name ‘binary_sensor.is_true’”

Any help to fix this much appreciated :slight_smile:

sensor:
  - platform: adc
    name: "${friendly_name} Battery Voltage"
    pin: GPIO36              # VP pin ADC1_ch0
    id: Septic_tank_12v_battery
    update_interval: 30s
    unit_of_measurement: "V"
    accuracy_decimals: 2
    attenuation: auto # 11db
    filters:
      - multiply: 4.5  

binary_sensor:
  - platform: analog_threshold
    name: "Septic Tank Mains power FAILED"
    sensor_id: Septic_tank_12v_battery
    threshold:
        upper: 13.0
        lower: 12.5
    filters:
        - delayed_on: 60s
        - delayed_off: 2s 

# if battery voltage < 12.5V for > 1 minute then turn on alarm buzzer
    on_state:
      then:
        - if:
           condition:
             binary_sensor.is_true: Septic_tank_12v_battery
           then:
            - switch.turn_on: alarm_piezo_relay  

BTW, I did try a lambda function:

  - platform: analog_threshold
    name: "Septic Tank Mains power FAILED"
    sensor_id: Septic_tank_12v_battery
    threshold:
        upper: 13.0
        lower: 12.5
    filters:
        - delayed_on: 60s
        - delayed_off: 2s 

    lambda: |-
      if (id(Septic_tank_12v_battery).state = "true"){ 
             id(alarm_piezio_relay).turn_off();
      }

The error here is “[lambda] is an invalid option for [binary_sensor.analog_threshold]. Please check the indentation.”

“on” not “true”

binary_sensor.is_on: Septic_tank_12v_battery

Thanks… I had actually tried “on”, and this is the error:

“ID ‘Septic_tank_12v_battery’ of type adc::ADCSensor doesn’t inherit from binary_sensor::BinarySensor. Please double check your ID is pointing to the correct value.”

Is it ok to use ‘on_state’ within ‘binary_sensor’?

Try this:

binary_sensor:
  - platform: analog_threshold
    name: "Septic Tank Mains power FAILED"
    id: septic_threshold
    sensor_id: Septic_tank_12v_battery
    threshold:
        upper: 13.0
        lower: 12.5
    filters:
        - delayed_on: 60s
        - delayed_off: 2s 

# if battery voltage < 12.5V for > 1 minute then turn on alarm buzzer
    on_state:
      then:
        - if:
           condition:
             binary_sensor.is_on: septic_threshold

sensor_id is the the source entity the threshold component uses. Not the id of the binary sensor it creates.

1 Like

Thank you! That was the problem… really appreciate your help :slight_smile:

1 Like