ESPHome syntax for if: with multiple conditions

I have spent hours going around and around trying to find the correct syntax.
ESPHome documentation has only the simplest of examples; and stating that condition, all or any can be used … but the Device Builder seem to be following different rules stating that Cannot have two conditions in one item :frowning:

My objective: I have a Latching Solenoid Valve to turn on/off the water flow for misting in my orchid greenhouse. BUT maybe the is_misting switch template is FALSE but water is actually flowing through the valve - that is an error needing to be fixed.
The mist_water_flow sensor is checked regularly, so this seems the best place to check for water leaks.

switch:
  # I use Grove TB6612FNG Motor Drive to open or close the Latching Solenoid Valve.
  #   The water valve has only 2 wires and uses a 30ms pulse of +4.5V to open,  and a 30ms -4.5V pulse to close.
  #    To get +ve and -ve on the same wire use an H-Bridge (typically used to drive a motor). 
  # The Grove TB6612FNG Motor Drive has an I²C interface
  - platform: template
    id:   is_misting
    name: is_misting
    restore_mode: RESTORE_DEFAULT_OFF
    turn_on_action:
      - logger.log: "# turning ON the switch should OPEN the Solenoid Valve"
      - script.execute:
          id: toggle_TB6612FNG
    turn_off_action:
      - logger.log: "# turning OFF the switch should CLOSE the Solenoid Valve"
      - script.execute:
          id: toggle_TB6612FNG

sensor:
  - platform: pulse_counter
    name: Mist water flow
    id:   mist_water_flow
    pin: 
      number: GPIO5
      mode: INPUT_PULLUP
    update_interval: $update_interval_sensor
    on_value:
      then:
        - if:
            all: 
                switch.is_off: "is_misting"
                sensor.in_range:
                  id: x
                  above: 0
            then:
              logger.log: "############### shouldn't be any water flowing if misting is OFF"


script:
  - id: toggle_TB6612FNG
    then:
      - logger.log: "**** toggle_TB6612FNG ******  "
      - logger.log:
          format: ">>>>>>   is_misting=%s "
          args: [ 'id(is_misting).state ? "true" : "false"' ]
      - grove_tb6612fng.no_standby:   # bring out of standby, ready to accept command
          id: test_motor
      - delay: 2s
      # FB6612 uses motor terminology: speed = the voltage sent, direction is +ve or -ve
      - if:
          condition: 
            lambda: 'return id(is_misting).state;'
          then:
            - logger.log: "# already ON, so turn misting OFF by BACKWARD motion"
            - grove_tb6612fng.run:
                id: test_motor
                channel: 0            # TB6612FNG can control 2 motors (or switches)
                direction: "BACKWARD" # motor Forward = our valve Close
                speed: 250            # motor speed is determined by the voltage sent. 4.5v = 230/255 of 5V
          else:
            - logger.log: "# already OFF, so turn misting ON by FORWARD motion"
            - grove_tb6612fng.run:
                id: test_motor
                channel: 0            # TB6612FNG can control 2 motors (or switches)
                direction: "FORWARD"  # motor Forward = our valve Open
                speed: 250            # motor speed is determined by the voltage sent. 4.5v = 230/255 of 5V
      - delay: $latching_switch_delay
      - grove_tb6612fng.stop:         # turn off (stop powering) the relay
          id: test_motor
          channel: 0
      - grove_tb6612fng.standby:      # standby to reduce power consumption
          id: test_motor
      - logger.log: 
          format: "**** end of toggle_TB6612FNG ******  >>>>>>   is_misting=%s "
          args: [ 'id(is_misting).state ? "true" : "false"' ]

It’s unclear what you are referring too. What line is the builder complaining about in this yaml?

“any” and “all” are lists not dictionaries. i.e. each condition needs to be proceeded by “-”.

        - if:
            all: 
               - switch.is_off: "is_misting"
               - sensor.in_range:
                   id: x
                   above: 0

Thanks Tom … that has changed the error to Couldn't find ID 'x'

Fair enough. ‘x’ is not a separate entity, as sensor.in_range is wanting … but the value from the trigger … which I can get from a lambda condition ?

  - platform: pulse_counter
    name: Mist water flow
    id:   mist_water_flow
    pin: 
      number: GPIO5
      mode: INPUT_PULLUP
    update_interval: $update_interval_sensor
    on_value:
      then:
        - if:
            all: 
              - switch.is_off: "is_misting"
              - lambda: 'return x > 0;'
            then:
              - logger.log: "############### shouldn't be any water flowing if misting is OFF"
              - switch.turn_off: is_misting

and … IT COMPILES ! Thanks Tom and Daryl.