#Switch Style Condition

1 messages · Page 1 of 1 (latest)

high mesa
#

Maybe this already exists and I just couldn't find it in the docs.

Has there been any discussion on making switch programing style condition? My example would be for an alarm panel but could work for lots of other things. This could be blending the entity and choose condition:

Figured this could save in duplicating the condition entity_id, attributes, etc.

Ex:


switch:
  condition: state
  entity_id: alarm_control_panel.house_alarm
  conditions:
    - state: armed_away
      sequence:
        - action: switch.turn_off
    - state: armed_night
      sequence:
        - action: switch.turn_off
    - state: armed_home
      sequence:
        - action: switch.turn_on
half wasp
#

Reading that block, I have honestly no idea what it is supposed to do...

bold spindle
#

I assume you're looking for "choose" but looking at your pseudo code I also don't know what you're aiming for

#

(probably choose in combination with trigger ids)

vivid plume
#

I think the idea is that you specify what is being checked once (in this case, the state of the alarm_control_panel.house_alarm entity), and then in the branches you only need to provide a value - the branch is taken if the value matches, or skipped otherwise.

#

doesn't really fit into how conditions work in home assistant - if implemented, you wouldn't be able to use arbitrary conditions. The simplest way to do it would be to only support templates, and then check the output of the template to see which branch matches.

high mesa
#

Life got busy and forgot to check back here. @vivid plume is correct on what I was thinking.

Wasn’t sure if it would even possible with how automations are built under the hood. I just have several automations that feel very repetitive when setting up conditions.

half wasp
#

As it mixes an action with a condition I think it's pretty hard. Especially because you want need to make it compatible with all kinds of conditions. And it's also less flexable as you can't add a second condition etc. So think the duplicate button is just as easy here 😄

dusty elbow
#

I tend to template in a variable to get the state and there you can use choose with a template which means you only specify the state once at the top so changing the device/entity is easy.

Using variables also has the advantage that it is easy to check all the values in the trace.