Add condition key for a service call

Hi there, I’m not sure whether the title does justice to my actual idea, so let me explain:

If I understand correctly, currently we can assign a condition to one single action only by embedding it into a choose action with a condition, which will make the sequence look unnecessarily confusing.
So therefore I suggest this:

- service: persistent_notification.create
  condition: "{{ now().hour > 9 }}"
  data:
    message: Doorbell rang

I’m not sure whether it’s better to stay consistent with the naming scheme and call the key condition: or rather avoid confusion and call it if: or something else.
Luckily I’m nowhere near smart enough to be the one who has to decide :smirk::grin:

I generally like the idea, but would probably do it a bit differently. Rather than embedded the condition in the service call, have a construct like this:

- condition: "{{ now().hour > 9 }}"
  sequence:
    - service: persistent_notification.create
      data:
        message: Doorbell rang

Where you could have any number of actions that will only execute if the condition is true. It’s essentially an extension of the existing inline condition that either continues or exits.

Thanks for your opinion! :slight_smile: I like it too, but to me it feels a bit odd, because I want to assign a condition to a service call, not the other way around.

If one wanted to have multiple service calls, I think it makes sense to go the choose route, because it’s very flexible. I however wanted a neater and tidier option to exclude one action from a sequence. (and keep the other actions going regardless of that condition).

Essentially, your suggestion is basically a tidier redesign of a one-condition choose action. Which, honestly, isn’t bad at all, but not what I wanted to request here.
But why not have both? I’d love it!

This is bass-ackward.

A service call is a commitment to perform an action. The decision whether to perform the action (or not) comes before it, not after.

What rccoleman suggested does a better job of conforming to how conditions and actions are used in Home Assistant.

Alright, didn’t know. Sounds reasonable.
But, can’t we still have both, as both serve slightly different purposes?