Test if X of X Conditions are TRUE or FALSE

I’m trying to write an automation that would run if 2 of 3 conditions are true. However, I cannot figure out how to do it, if there is a way to do it. Does anyone know if there’s a way to do this in the GUI (for someone who doesn’t know how to write the code)?

First you need to have made an input_number helper (lets call it tally), Best to make it a hidden one since nothing else needs to reference it.

Then for your automation set a trigger that if any of the conditions are true, it triggers.

Then in the variables, set tally to 0.
If condition 1 is true, set tally to tally +1
If condition 2 is true, set tally to tally +1
If condition 3 is true, set tally to tally +1

Then for the conditions if tally > 1 let it pass and do your thing.

Set automation type to queued.

What three conditions?

Thanks for the input.

@tom_l , my doors all have 3 sensors on them; a z-wave open/close sensor, an open/close sensor as part of the z-wave lock, and an open/close sensor as part of the SimpliSafe security system.

The SimpliSafe sensor is the most reliable, but the SimpliSafe integration only poles the SimpliSafe system for sensor status every 60 seconds.

The z-wave door lock open/close sensor wasn’t particularly reliable in reporting status to HA, so I bought another Aeotec Z-wave sensor. It is more reliable than the lock’s sensor at reporting to HA, but also has it’s less reliable moments.

I have door status lights that are on a HomeSeer switch that will change color/blink status based on different variables of whether or not the door is open, closed, locked, unlocked, etc. Given the statuses aren’t always reliable from the z-wave on reliability, I was thinking of making it 2/3 in agreement as that usually works out.

But I’m still not sure I’m going about this the correct way.

@Sir_Goodenough, I think I’m following your instructions, but it isn’t working. I’ll keep playing with it and see if I find success. I keep thinking of aborting the idea. It isn’t the most useful automation, just an automation leveraging devices to make use of unused devices.

I meant please share the config for the three conditions. I can then convert these to a template condition for you.

Wouldn’t it be better to sort the unreliability rather than piling on 2-3 sensors on each door hoping to get a state change? I don’t use Z-wave but something seems off, my zigbee sensors (a single on on each door) never skip a state change.

@fleskefjes That would be preferred, but my understanding is that this is a problem with the latency of Z-wave. i.e., when the door opens and closes within only 2-3 seconds, it doesn’t always keep up. I’ve noticed this even with my lights that use Z-wave: Sometimes, when I toggle one (on/off or off/on) quickly, the second action doesn’t always take. Perhaps I should integrate some zigbee in my system. I went with z-wave because it seemed there were more options for z-wave in the US than zigbee, at least for light switches.

@tom_l , I appreciate the offer and I may take you up on it once I figure out the direction I’m going to go with this.

condition:
  - platform: template
    value_template: >
      {% set first = your first template condition goes here %}
      {% set second = your second template condition goes here %}
      {% set third = your third template condition goes here %}
      {{ [first, second, third] | select('eq', true) | list | count >= 2 }}

While I would also suggest you use templating to keep it easy to read, it can be done in the UI editor by using an Or condition that contains 3 And conditions.

YAML configuration for above
condition: or
conditions:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.test_bool_1
        state: "on"
      - condition: state
        entity_id: input_boolean.test_bool_2
        state: "on"
    alias: Test if Conditions 1 & 2
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.test_bool_2
        state: "on"
      - condition: state
        entity_id: input_boolean.test_bool_3
        state: "on"
    alias: Test if Conditions 2 & 3
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.test_bool_1
        state: "on"
      - condition: state
        entity_id: input_boolean.test_bool_3
        state: "on"
    alias: Test if Conditions 1 & 3