SOLVED! Conflicting automation when fired at same time?

Hi all! I am experiencing a bit strange behavior when triggering automations at regular intervals on ESPHOME devices.
Here is the description:

HA: 2024.1.1
ESPHOME: 2023.12.5

I have 6 Humidity sensors:
h1,h2,h3,h4,h5,shth1
and one switch: relay

I want to check the sensor values every minute and:

  1. if any of the sensor values (logic OR) goes above 68, then I want to switch on the relay.
  2. switch off the relay when all the sensors (logic AND) are below 65

I have implemented following yaml script:

interval:
  - interval: 1min
    then:
      if:
        condition:
          or:
            lambda: |-
              return id(h1).state >68;
              return id(h2).state >68;
              return id(h3).state >68;
              return id(h4).state >68;
              return id(h5).state >68;
              return id(shth1).state >68;
            
        then:
          - switch.turn_on: relay

  - interval: 1min
    then:
      if:
        condition:
          and:
            lambda: |-
              return id(h1).state <65;
              return id(h2).state <65;
              return id(h3).state <65;
              return id(h4).state <65;
              return id(h5).state <65;
              return id(shth1).state <65;
            
        then:
          - switch.turn_off: relay

What happens is that only the “and” condition works, while the “or” condition doesn´t.

Then, I have tried to remove the “and” condition and only keep the “or” condition, and this time the logic works.

So my question is: Could it be that the two automation logic went into conflict since fired at same time?

Or, am I doing something wrong?

Thanks for any help or suggestions.

You only have one condition in each. The lambda counts as one condition. Try this:

        condition:
          or:
            - lambda: |-
                return id(h1).state >68;
            - lambda: |-
                return id(h2).state >68;
            - lambda: |-
                return id(h3).state >68;
            - lambda: |-
                return id(h4).state >68;
            - lambda: |-
                return id(h5).state >68;
            - lambda: |-
                return id(shth1).state >68;

Same for the AND condition.

Kind of unrelated but im curious. If 6 sensors are being used to turn on/off a relay that i presume goes to a dehumidifier. If each sensor can trigger the relay on/off and theyre all set to the same value, you would think that unless you have perfect air movement and one dehumidifier doesnt cause areas of higher or lower humidity in a zone of 6 sensors. I kind of wonder if you’ll ever see a 1min interval where it isnt turning on or off . What are you working on that needs 6 humidity sensors for 1 zone? You arent growing that whacky weed are you?

Many Thanks! That was the issue!
Works like a charm!

Thanks for the question!
No I am not growing weed but you gave me a good hint! (just kidding!)

The sensors are under the house, in Sweden where I live it is called “Krypgrund”. There is a dehumidifier which is drying the air with the help of a fan, so when it is on the air is in movement.
The reason why I placed 6 sensors is that the area is divided by several concrete beams so I need to check the status in each section.

It works fine, by checking the humidity in the all area instead of only looking at the data coming fron the de-humidifier I was able to save something like 10Kwh…per day!