Problem trying to use input_number (rookie post)

Hi community.
Since a couple of months I’ve started with HA, I’ve work with Arduino quite a lot, basically using code around and modifying according to my needs, Until HA appears… YAML is a pain you know where…
This problem basically is trying to use helpers - input_numbers, it work since I used this variable (or whatever) in my proyect wich is a simple wemos with dht11 and ssd1306 I2C display.

As I said before I can see in my display the number that I’ve set in HA, but I could not use that number into a simple comparison to start or stop a fan, in the code you’ll see two integers (60.0 and 58.0) harcoded as maximum an minimum value, the idea is to replace those number by input_number that I set in HA

Any help will be appreciated
Here’s the code / thanks

switch:
  - platform: gpio
    pin: D6
    id: "relay"
    name: "Extractor Ducha"
    inverted: true
    
sensor:
  - platform: homeassistant
    name: "Setpoint Humedad"
    entity_id: input_number.setpoint_humedad
    id: setpoint
    internal: true
    
  - platform: dht
    model: "DHT11"
    pin: D3
    temperature:
     id: temperatura
     name: "Temperatura Ducha"
    humidity:
     id: humedad
     name: "Humedad Ducha"
    
     on_value_range:
      - above: 60.0
        then:
          - switch.turn_on: "relay"
      - below: 58.0
        then:
          - switch.turn_off: "relay"
    update_interval: 10s

i2c:
  sda: D2
  scl: D1

font:
  - file: 'NunitoSans-Regular.ttf'
    id: font1
    size: 17
    
  - file: 'NunitoSans-Regular.ttf'    
    id: font2
    size: 22
    
  - file: 'NunitoSans-Regular.ttf'   
    id: font3
    size: 40   

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
     it.printf(0, 0, id(font2), "%.1f°C  %.f%%", id(temperatura).state, id(humedad).state);
     it.printf(0, 25, id(font1), "Setpoint"); 
     it.printf(0, 42, id(font1), "Humedad"); 
     it.printf(80, 20, id(font3), "%.f", id(setpoint).state); 

Personally, I would use the Bang-Bang Climate component. However, you should be able to do it using the number component. The number component will create number entities in Home Assistant that you can interact with similarly to how you would with Input number helpers.

switch:
  - platform: gpio
    pin: D6
    id: relay
    name: "Extractor Ducha"
    inverted: true

number:
  - platform: template
    name: "Humedad Maxima Ducha"
    id: hum_max
    unit_of_measurement: %
    optimistic: true
    min_value: 0
    max_value: 100
    step: 1

  - platform: template
    name: "Humedad Minima Ducha"
    id: hum_min
    unit_of_measurement: "%"
    optimistic: true
    min_value: 0
    max_value: 100
    step: 1

sensor:    
  - platform: dht
    model: "DHT11"
    pin: D3
    temperature:
     id: temperatura
     name: "Temperatura Ducha"
    humidity:
     id: humedad
     name: "Humedad Ducha"    
     on_value_range:
      - above: !lambda 'return id(hum_max).state;'
        then:
          - switch.turn_on: relay
      - below: !lambda 'return id(hum_min).state;'
        then:
          - switch.turn_off: relay
    update_interval: 10s

i2c:
  sda: D2
  scl: D1

font:
  - file: 'NunitoSans-Regular.ttf'
    id: font1
    size: 17
    
  - file: 'NunitoSans-Regular.ttf'    
    id: font2
    size: 22
    
  - file: 'NunitoSans-Regular.ttf'   
    id: font3
    size: 40   

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
     it.printf(0, 0, id(font2), "%.1f°C  %.f%%", id(temperatura).state, id(humedad).state);
     it.printf(0, 25, id(font1), "Setpoint"); 
     it.printf(0, 42, id(font1), "Humedad"); 
     it.printf(80, 20, id(font3), "%.f", id(hum_max).state); 

Hi there! thanks for your feedback…
I ve the following error message
image

but I’m interested on bang-bang solution, How it will be in my case (sorry but I’m learning in the hard way all YAML related issues…)

Thanks again!

I’ve comment unit_of_measurement: %, and it apperars to be working! congrats!
Still my question about bang-bang …
Perhaps is an silly question… wich component or how to setup the gauge with min and max values?

Best regards!

I think the issue with unit_of_measurement is a lack of quotation marks… if you want to have it assign the unit, try unit_of_meaurement: "%"

When using the bang-bang climate component in a situation like this with a fan or dehumidifier, you would set it up as if it is an air conditioner.

climate:
  - platform: bang_bang
    name: "Control de Humedad Ducha"
    sensor: humedad
    default_target_temperature_low: 58
    default_target_temperature_high: 60

    cool_action:
      - switch.turn_on: relay
    idle_action:
      - switch.turn_off: relay

Make sure to comment out or remove the on_value_range actions from the sensor section of your configuration if you use the bang-bang component.

I think the gauge shown in the example is just a standard Thermostat card.

1 Like

The component will set up the defaults, or use the options shown here Climate Component — ESPHome

Hi Nick
I’ve a little problem… every time the esp restart hum_max & hum_min returns to zero, how could save the last values into the esp?
As allways thank you

If you are using the Number component, set the restore_value tag.

number:
  - platform: template
    name: "Humedad Maxima Ducha"
    id: hum_max
    unit_of_measurement: %
    optimistic: true
    min_value: 0
    max_value: 100
    step: 1
    restore_value: true

  - platform: template
    name: "Humedad Minima Ducha"
    id: hum_min
    unit_of_measurement: "%"
    optimistic: true
    min_value: 0
    max_value: 100
    step: 1
    restore_value: true

Hi again… really sorry
I’ve tried but didn’t work
I’ve tried this scenario setting using harcoded values, but it is not what I’m looking for

number:
  - platform: template
    name: "Humedad Maxima Ducha"
    id: hum_max
#    unit_of_measurement: %
    optimistic: true
    min_value: 50
    max_value: 70
    step: 1
    restore_value: true

  - platform: template
    name: "Humedad Minima Ducha"
    id: hum_min
#    unit_of_measurement: %
    optimistic: true
    min_value: 48
    max_value: 68
    step: 1
    restore_value: true

sensor:    
  - platform: dht
    model: "DHT11"
    pin: D3
    temperature:
     id: temperatura
     name: "Temperatura Ducha"
    humidity:
     id: humedad
     name: "Humedad Ducha"    
     on_value_range:
      - above: !lambda 'return id(hum_max).state;'
        then:
          - switch.turn_on: relay
      - below: !lambda 'return id(hum_min).state;'
        then:
          - switch.turn_off: relay
    update_interval: 10s

Also, and I’m sorry I din not mention before, I just need a maximum value and in the line

- below: !lambda 'return id(hum_min).state;'

I need to set instead hum_min, hum_max - 2 (like histeresis setting), but also I can not make it work, it is very frustrating, the info into esphome it far away to my undertandings… hate YAML jajaja

I think input_number in HA will solve this issue but as I said at the very beggining, I could’t use that value into a lambda to turn ON / OFF the relay

Best Regards

Please clarify… what I posted does not use hardcoded values, it sets up a number entity that can be changed from the HA frontend (In the example below, this entity should appear in HA as number.humedad_maxima_ducha). By enabling restore_value the value of the number entity should not reset back to the min_value if the ESP restarts.

If you only want to set the max and then calculate the min based on a fixed value you do not need to set up the hum_min number entity. You can modify the lambda in the on_value_range action for the below key.

number:
  - platform: template
    name: "Humedad Maxima Ducha"
    id: hum_max
    optimistic: true
    min_value: 50
    max_value: 70
    step: 1
    restore_value: true

sensor:    
  - platform: dht
    model: "DHT11"
    pin: D3
    temperature:
     id: temperatura
     name: "Temperatura Ducha"
    humidity:
     id: humedad
     name: "Humedad Ducha"    
     on_value_range:
      - above: !lambda 'return id(hum_max).state;'
        then:
          - switch.turn_on: relay
      - below: !lambda 'return id(hum_max).state - 2;'
        then:
          - switch.turn_off: relay
    update_interval: 10s

What issue is it that you think an Input number helper will solve? Using an Input number helper is very similar to using the Number component, but it requires additional coding in ESPHome. Using the Number component has the additional benefit that it will show as ‘unavailable’ in HA if the ESP is not working. Since an Input number is created in HA, it doesn’t “know” whether the ESP is working.

Hello again…
As you probably noted I’m kind of stubborn jajjajaa
I come back to input number and with your help I figured out how to do it.
Here’s the result

captive_portal:

switch:
  - platform: gpio
    pin: D6
    id: "relay"
    name: "Extractor Ducha"
    inverted: true
    
sensor:
  - platform: homeassistant
    name: "Setpoint Humedad"
    entity_id: input_number.setpoint_humedad
    id: setpoint
    internal: true
    
  - platform: dht
    model: "DHT11"
    pin: D3
    temperature:
     id: temperatura
     name: "Temperatura Ducha"
    humidity:
     id: humedad
     name: "Humedad Ducha"
    
     on_value_range:
      - above: !lambda 'return id(setpoint).state;'
        then:
          - switch.turn_on: relay
      - below: !lambda 'return id(setpoint).state - 2;'
        then:
          - switch.turn_off: relay
          
    update_interval: 10s

i2c:
  sda: D2
  scl: D1

font:
  - file: 'NunitoSans-Regular.ttf'
    id: font1
    size: 17
    
  - file: 'NunitoSans-Regular.ttf'    
    id: font2
    size: 22
    
  - file: 'NunitoSans-Regular.ttf'   
    id: font3
    size: 40   

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
     it.printf(0, 0, id(font2), "%.1f°C  %.f%%", id(temperatura).state, id(humedad).state);
     it.printf(0, 25, id(font1), "Setpoint"); 
     it.printf(0, 42, id(font1), "Humedad"); 
     it.printf(80, 20, id(font3), "%.f", id(setpoint).state); 

Really thank you very much!