Unable to trigger light / led from dallas sensor

Spent hours on this, I cannot get this to switch on the LED.

I have checked the truth of if (float(id($temp_id).state) > float(id(pid_data).target_temperature_low)) and it is true, and just to prove that it’s not the condition that’s not firing, I actually forced it on outside of the condition.

but it just refuses to switch on, I can trigger it manually from home ssistant no problem, what am I doing wrong ?

light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: 27
    num_leds: 1
    rgb_order: GRB
#    id: ${name}_led
    id: status_led
    name: ${name} Status LED
    effects:
      - random:
      - flicker:
      - addressable_rainbow:


sensor:

  ## DS18S20B One Wire
  - platform: dallas
    id: $temp_id
    name: $name Temperature
    index: 0
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    filters:
      - exponential_moving_average:  
         alpha: 0.1
         send_every: 1

    on_value:
      then:   
        lambda: |-

          if (float(id($temp_id).state) > float(id(pid_data).target_temperature_low)) {
            id(status_led).turn_on();
          }
          else {
            id(status_led).turn_off();
          }

          id(status_led).turn_on();

Any particular reason you want to do this with lambda? Maybe you are over complicating things :thinking:

Not sure what your goal is exactly but something like this might come in handy for you:

sensor:
  - platform: dallas
    # ...
    on_value_range:
      - below: 5.0
        then:
          - light.turn_on: status_led
      - above: 5.0
        below: 10.0
        then:
          - light.turn_off: status_led
      - above: 10.0
        then:
          - light.turn_on:
              id: status_led
              brightness: 100%
              effect: random

ESPHome Sensor Component #on-value-range

Thanks, but no that wont work.

I need to switch on the LED when the actual temperature is above the set / target temperature of the climate.target_temperature.

There’s no fixed value to trigger on, as the climate target temperature changes and is not fixed.

Wasn’t aware that a climate component is included somewhere in your set up :thinking:

Still you should be able to work around it more or less easily - for example if your climate component is in home assistant and you want your status led to react on “off”, “idle” and “heating” (for example) you could do something like that:

text_sensor:
  - platform: homeassistant
    id: ha_thermostat_state # "off" , "idle" or "heating" for example
    entity_id: climate.thermostat
    attribute: hvac_action
    on_value:
      then:
        - if:
            condition:
              lambda: |-
                return x == "idle";
            then: 
              - light.turn_on: 
                  id: status_led
                  effect: pulse
            else:
              - if:
                  condition:
                    lambda: |-
                      return x == "heating";
                  then: 
                    - light.turn_on: status_led
                  else:
                    - light.turn_off: status_led

In that case the led will pulse when the climate component is idling and the led will be on when it is heating. In other cases (off) the status led will be off :bulb:

Thanks, based on your example I ended up with this:

  ## DS18S20B One Wire
  - platform: dallas
    id: $temp_id
    name: $name Temperature
    index: 0
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    filters:
      - exponential_moving_average:  
         alpha: 0.1
         send_every: 1

    on_value:
      then:
      - if:
          condition:
            lambda: return (x > float(id(pid_data).target_temperature_low));
          then:
            - light.turn_on:
                id: status_led
                effect: pulse
          else:
            - light.turn_on:
                id: status_led
                effect: none   


1 Like