Detecting NaN sensor (DS18b20) lambda/else

Trying to detect when a DS18b20 goes offline or NaN and then execute a LED based on the state

I have referred to this post: https://community.home-assistant.io/t/sensor-nan-value-as-trigger/480230/4?u=domain_int butI really need to add an else in the statement and dont know how to do it

I tried doing this:

      then:
        - if:
            condition:
              lambda: (id(temp_probe_error).state)) == "NaN";
            then:
              - light.turn_on: sensor_check
          else:
            - light.turn_off: sensor_check

tried this

       - lambda:
          if (isnan(id(temp_probe_error).state)) {id(sensor_check).turn_off();} else {id(sensor_check).turn_on();}

and I tried this

  - platform: dallas_temp
    name: ${name}-probe-error
    update_interval: 10s
    id: temp_probe_error
    on_value:
      then:
        - lambda: 
            if (isnan(id(temp_probe_error).state)) {
              id(sensor_check).turn_on();
            } else {
              id(sensor_check).turn_on();
            }

I am a newb when it comes to lambdas but am not afraid to search

The main issue is to do with the else statement

Hope someone can help

any help???

I tried this too:

  - platform: dallas_temp
    name: temp_probe
    update_interval: 1s
    id: temp1
    filters:
      - skip_initial: 5
      - clamp:
          min_value: 2
          max_value: 90
          ignore_out_of_range: true
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3       
      - lambda: |-
          if (isnan(x)) {
            return -997;
        } else {
            return x;
          }          

Bevor
dallas_temp

You have one wire and get the ID from the sensor?

Errrrr… would there be something more constructive to contribute behind such an inane reply instead of clocking up your reply count?

    lambda: |-
      int volts = 120;
      if (!(isnan(id(voltage).state))) {
        volts = id(voltage).state;
      }
      return (id(current0).state * volts);

Instead of else, set a base variable.