Multiple conditions, with integers

Hello,

Have been using ESPHome for a few months now. Overall, pretty thrilled.

I have a question about a dehumidifier control project that I’m working on.

I’m stuck on trying to match 2 conditions:
Temperature is greater than 65.
Humidity is greater than 55.

I found an example with conditions matching boolean, but not with integers.

Thank you!

You’ll have to use “in range” https://esphome.io/components/sensor/index.html#sensor-in-range-condition in combination with the and condition

Forgive me… I’m a network guy that dabbles in programming… so I’m probably doing something really stupid. My code is failing when I check the conditions.

Please see below:

esphome:
  name: shop_upstairs_dehumidifier
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "<snipped>"
  password: "<snipped>"
  
#Sensors  
sensor:
  - platform: dht
    pin: 19
    model: DHT22
    temperature:
      name: "Shop Dehumidifier Temperature"
      id: dehumtemp
    humidity:
      name: "Shop Dehumdifer Humidity"
      id: dehumhum
    update_interval: 60s

  - platform: uptime
    name: Uptime Sensor
    id: uptime

#Binary Sensor
binary_sensor:
  - platform: gpio
    pin:
      number: 2
      mode: INPUT_PULLUP
    name: "Bucket Full"
    id: full


# Relays
switch:
  - platform: gpio
    pin: 25
    name: "Compressor"
    id: Compressor
    
  - platform: gpio
    pin: 16
    name: "Fan Speed Low"
    id: Low
    
  - platform: gpio
    pin: 17
    name: "Fan Speed Medium"
    id: Medium
    
  - platform: gpio
    pin: 18
    name: "Fan Speed High"
    id: High
    
#Automations
on_value_range:
  then:
  - if
    condition:
      and:
        sensor.in_range
          id: dehumtemp
	  above: 18.5
	sensor.in_range
	  id: dehumhum
	  below: 50
	  above: 55
  then:
    - delay 120s
    - switch.turn_on: Compressor 
    - switch.turn_on: High
  else:
    - switch.turn_off: Compressor 
    - switch.turn_off: High
    
# Enable logging
logger:

# Enable Home Assistant API
api:
  password: '<snipped>'

ota:
  password: '<snipped>'

Your code is looking good.
But you have issues with some colons and indentation.
I have no computer near me to assist you more formatting your code.
Pay attention in docs how things are indented. Both sensor.in range should be at the same level. Also sensor.in range are the same level so each one needs a - before
And sensor.in range needs a : at the end.
Again look carefully at docs a space or symbol missing and it would not work.

I fixed the spacing… Looks like I had a few tabs in there as well. I had to use Notepad++ to view the tabs, then removed. I believe this fixed the spacing. I will look at the documentation further, in the meantime…

Now getting this:
duplicate key: “-sensor.in_range”
in “/config/esphome/shop_upstairs_dehumidifier.yaml”, line 67, column 0

New code is below:

esphome:
  name: shop_upstairs_dehumidifier
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "<snipped>"
  password: "<snipped>"
  
#Sensors  
sensor:
  - platform: dht
    pin: 19
    model: DHT22
    temperature:
      name: "Shop Dehumidifier Temperature"
      id: dehumtemp
    humidity:
      name: "Shop Dehumdifer Humidity"
      id: dehumhum
    update_interval: 60s

  - platform: uptime
    name: Uptime Sensor
    id: uptime

#Binary Sensor
binary_sensor:
  - platform: gpio
    pin:
      number: 2
      mode: INPUT_PULLUP
    name: "Bucket Full"
    id: full


# Relays
switch:
  - platform: gpio
    pin: 25
    name: "Compressor"
    id: Compressor
    
  - platform: gpio
    pin: 16
    name: "Fan Speed Low"
    id: Low
    
  - platform: gpio
    pin: 17
    name: "Fan Speed Medium"
    id: Medium
    
  - platform: gpio
    pin: 18
    name: "Fan Speed High"
    id: High
    
#Automations

if:
  condition:
    and:
      -sensor.in_range:
        id: dehumtemp
        above: 18.5
      -sensor.in_range:  
        id: dehumhum
        below: 50
        above: 55
  then:
    - delay 120s
    - switch.turn_on: Compressor 
    - switch.turn_on: High
  else:
    - switch.turn_off: Compressor 
    - switch.turn_off: High
    
# Enable logging
logger:

# Enable Home Assistant API
api:
  password: '<snipped>'

ota:
  password: '<snipped>'

Missing space here - sensor ?

That did it! Getting closer!
Let me see if I can figure out the last few errors that I’m getting!

Ok. Hopefully one more issue… I think I’m causing the compiler to crash.

Error:
INFO Reading configuration...
ERROR Unexpected exception while reading configuration:
Traceback (most recent call last):
  File "/usr/local/bin/esphome", line 11, in <module>
    load_entry_point('esphome', 'console_scripts', 'esphome')()
  File "/opt/esphome/esphome/__main__.py", line 483, in main
    return run_esphome(sys.argv)
  File "/opt/esphome/esphome/__main__.py", line 466, in run_esphome
    config = read_config(args.verbose)
  File "/opt/esphome/esphome/config.py", line 803, in read_config
    res = load_config()
  File "/opt/esphome/esphome/config.py", line 663, in load_config
    return _load_config()
  File "/opt/esphome/esphome/config.py", line 651, in _load_config
    result = validate_config(config)
  File "/opt/esphome/esphome/config.py", line 440, in validate_config
    component = get_component(domain)
  File "/opt/esphome/esphome/config.py", line 171, in get_component
    assert '.' not in domain
AssertionError

new code:

esphome:
  name: shop_upstairs_dehumidifier
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "<snipped>"
  password: "<snipped>"
  
#Sensors  
sensor:
  - platform: dht
    pin: 19
    model: DHT22
    temperature:
      name: "Shop Dehumidifier Temperature"
      id: dehumtemp
    humidity:
      name: "Shop Dehumdifer Humidity"
      id: dehumhum
    update_interval: 60s

  - platform: uptime
    name: Uptime Sensor
    id: uptimeesp

#Binary Sensor
binary_sensor:
  - platform: gpio
    pin:
      number: 2
      mode: INPUT_PULLUP
    name: "Bucket Full"
    id: full


# Relays
switch:
  - platform: gpio
    pin: 25
    name: "Compressor"
    id: Compressor
    
  - platform: gpio
    pin: 16
    name: "Fan Speed Low"
    id: Low
    
  - platform: gpio
    pin: 17
    name: "Fan Speed Medium"
    id: Medium
    
  - platform: gpio
    pin: 18
    name: "Fan Speed High"
    id: High
    
#Automations
on_...:
  then:
    - if:
      condition:
        and:
          - sensor.in_range:
            id: dehumtemp
            above: 18.5
          - sensor.in_range:  
            id: dehumhum
            below: 50
            above: 55
      then:
        - delay 120s
        - switch.turn_on: Compressor 
        - switch.turn_on: High
      else:
        - switch.turn_off: Compressor 
        - switch.turn_off: High
    
# Enable logging
logger:

# Enable Home Assistant API
api:
  password: '<snipped>'

ota:
  password: '<snipped>'

On_… means you have to change the … by some trigger like on press button or something else. On_interval seems to work when you’re not sure which events to use.

That was my fear. I was trying to find what my options were, and wasn’t able to find any examples.

I changed to to “on_interval:” and now I get another error.
I’ve tried other variations with the same result. Hope this is something stupid at this point.

INFO Reading configuration...
Failed config

on_interval: [source /config/esphome/shop_upstairs_dehumidifier.yaml:61]
  
  Component not found: on_interval.
  then: 
    - if: 
      condition: 
        and: 
          - sensor.in_range: 
            id: dehumtemp
            above: 18.5
          - sensor.in_range: 
            id: dehumhum
            below: 50
            above: 55
        then: 
          - delay 120s
          - switch.turn_on: High
          - switch.turn_on: Compressor
        else: 
          - switch.turn_off: High
          - switch.turn_off: Compressor

wait wait wait…
Do I need to have the conditions up by the sensor code?

Sorry I was not clear enough
Use for trigger interval:
See interval docs for precise syntax:

Does anyone have an example of a completed project using and / or conditions? I think I was able to see something that works, I’d be able to see what’s wrong. I’m almost positive it due to my spacing.

I have look at the documentation, however it’s hard to understand when there’s snippets of code in th example with no reference of where it needs to be in the project.

I agree. Snippets are fine if you already know YAML and where to put them.
Also, when someone solves a problem, posting the solution would help others who follow with a similar problem.

Can you post your solution?