How to combine blueprint conditions with new condition selector

I’m creating a blueprint that takes additional conditions using the new condition selector, but I’m unsure on how to combine them with other, fixed conditions. This is what I came up with, and while it works, I’m looking for a cleaner version - if any.

condition:
  - condition: and
    conditions:
      - condition: and
        conditions: !input additional_conditions
      # Skip if control was not taken
      - alias: "Control taken"
        condition: not
        conditions:
          - condition: state
            entity_id: !input control_entity
            state: Automatic

Is there a better way of combining two arrays in yaml?

Read thru this again. There’s lots of ways to make this cleaner. For instance, and is implied and often not necessary. There is also shortcut notation.

I’ve looked that up, too, with the exact same use-case. A blueprint that already includes conditions and gives the user a way to add additional conditions.

In YAML you cannot merge or unpack lists. Merging also only works with objects (that have a key). I ended up doing the same thing as you, while including the shorthand syntax as hinted by @Sir_Goodenough:

condition:
  - condition: and
    conditions:
      - and: !input additional_conditions
      # Skip if control was not taken
      - alias: "Control taken"
        condition: not
        conditions:
          - condition: state
            entity_id: !input control_entity
            state: Automatic

And as the and is implicit already, we can remove one level of and conditions:

    condition:
      - and: !input additional_conditions
      # Skip if control was not taken
      - alias: "Control taken"
        condition: not
        conditions:
          - condition: state
            entity_id: !input control_entity
            state: Automatic

Now it’s a one-liner and that should be enough :slight_smile: Thanks for @Sir_Goodenough for letting us know the potential for improvement!

This is where I ended up going for this. Put it into most of my BP’s, where it made sense, for users utility.
Like you said, the and is implied…

1 Like