Branching in on_value_range

In a number template, the on_value_range works perfectly.
How can I create another if statement within above: 1.9?

    on_value_range:
      - below: 0.1
        then:
          - script.execute: scr_dauer_aus
      - above: 0.9
        below: 1.9
        then:
          - script.execute: scr_dauer_ein
      - above: 1.9
        then:
          if ((id(differenz_).state) <= 2) {
            - script.execute: scr_auto_ein
          } else {
            - script.execute: scr_auto_aus
          }

Error:

mapping values are not allowed here
  in "/Users/reinhard/Mein/Homeassistant/pool-esp-oled.yaml", line 82, column 29

You are mixing C++ lambdas and yaml quite wild way.

then:
  - if:
      condition:
        lambda: 'return id(differenz_).state <= 2;'
      then:
        - script.execute: scr_auto_ein
      else:
        - script.execute: scr_auto_aus

You just don’t know what the cool kids are doing these days… We call it, “Wild C++ yamdas”. That’s just how some of us roll, ya dig?

1 Like

#Karosm, thanks, your post put me on the right track. After removing the clamp behind “.state”, it worked.

Ahh, sorry for that…

Also, be aware that on_value_range does nothing if you stay within the same range. For example the conditional script execute is run only once even if your value fluctuates between 1.91 and 2.5

1 Like