Conditions - Help!

Hi,

I am looking to create the following senario.

An automation tries to fire every 1 minute, and needs to check the status of input booleans. If any of the inputs are ON, the service switches on a boiler.

If ALL of the inputs are OFF, the boiler switches off.

I got this far: -

alias: Boiler Call for Heat
description: ''
trigger:
  - platform: time_pattern
    seconds: '60'
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.lr_call_heat
        state: 'on'
      - condition: or
        conditions:
          - condition: state
            entity_id: input_boolean.kt_call_heat
            state: 'on'
          - condition: or
            conditions:
              - condition: state
                entity_id: input_boolean.mb_call_heat
                state: 'on'
              - condition: or
                conditions:
                  - condition: state
                    entity_id: input_boolean.of_call_heat
                    state: 'on'
                  - condition: or
                    conditions:
                      - condition: state
                        entity_id: input_boolean.fb_call_heat
                        state: 'on'
action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.shelly1_40f52000485c
mode: single

This is the automation to switch on the boiler. I also as above want to switch the boiler off if ALL of the booleans are OFF.

Any ideas?

Thanks.

Try this. It combines both automation into one.

alias: Boiler Call for Heat
description: ''
mode: single
trigger:
  - platform: time_pattern
    minutes: /1
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: input_boolean.kt_call_heat
                state: 'on'
              - condition: state
                entity_id: input_boolean.lr_call_heat
                state: 'on'
              - condition: state
                entity_id: input_boolean.mb_call_heat
                state: 'on'
              - condition: state
                entity_id: input_boolean.of_call_heat
                state: 'on'
              - condition: state
                entity_id: input_boolean.fb_call_heat
                state: 'on'
        sequence:
          - service: switch.turn_on
            data: {}
            entity_id: switch.shelly1_40f52000485c
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: input_boolean.kt_call_heat
                state: 'off'
              - condition: state
                entity_id: input_boolean.lr_call_heat
                state: 'off'
              - condition: state
                entity_id: input_boolean.mb_call_heat
                state: 'off'
              - condition: state
                entity_id: input_boolean.of_call_heat
                state: 'off'
              - condition: state
                entity_id: input_boolean.fb_call_heat
                state: 'off'
        sequence:
          - service: switch.turn_off
            data: {}
            entity_id: switch.shelly1_40f52000485c        
    default: []
1 Like

Pretty sure you are going to have to change your trigger to:

trigger:
  - platform: time_pattern
    minutes: /1

As the maximum allowable number of seconds is 59.

See the breaking change in v0.115:

Time Pattern Trigger

The time_pattern trigger will now reject invalid expressions that were previously accepted (but did not work as expected).

For example the minutes: /60 would have been accepted previously, but could never trigger.

2 Likes

Thanks this worked very well.

Why not use a State Trigger instead of a Time Pattern Trigger?

  • When any of the input_booleans turns on, the automation is triggered and turns on the boiler.
  • When any of the input_booleans turns off, the automation is triggered and checks if it’s the last input_boolean to turn off and then turns off the boiler.

Let me know if you need help converting your automation to use a State Trigger. It’s far more efficient than polling every minute.

3 Likes

This would be really helpful, would love to see this as an automation :slight_smile:

Step 1

Create a group containing all five of the “call_heat” input_booleans.

call_heat:
  name: Call Heat
  entities:
    - input_boolean.kt_call_heat
    - input_boolean.lr_call_heat
    - input_boolean.mb_call_heat
    - input_boolean.of_call_heat
    - input_boolean.fb_call_heat
  • The group’s state will be on when at least one of the input_booleans is on.
  • The group’s state will be off when all of the input_booleans are off.

Step 2

Create an automation triggered by the group’s state-changes.

alias: Boiler Control
description: 'Turn boiler on/off.'
mode: single
trigger:
  - platform: state
    entity_id: group.call_heat
condition: []
action:
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    entity_id: switch.shelly1_40f52000485c

Or skip the group and just trigger direct from the booleans

alias: Boiler control
trigger:
  platform: state
  entity_id:
    - input_boolean.kt_call_heat
    - input_boolean.lr_call_heat
    - input_boolean.mb_call_heat
    - input_boolean.of_call_heat
    - input_boolean.fb_call_heat
action:
  service: 'switch.turn_{{ trigger.to_state.state }}'
  entity_id: switch.shelly1_40f52000485c

Real question is why so complicated that there are 5 booleans in the first place.

Marc, you automation will not function as required. All the entities have to be off for the boiler to turn off.

I think that will turn off the boiler the moment any of the input_booleans gets turned off. The OP wants to turn it off after the last input_boolean is turned off (i.e only when all input_booleans are off). The group makes it easy to comply with this requirement.


EDIT

Ninja’d again!

1 Like

Thats correct, so if all bools are off, boiler switches off. If any of the bools are on, the boiler switches on.

I am building a multi-room TRV heating solution (there is a good reason i am doing it this way)

The other advantage of using a group is that gives you global control over all five input_booleans (i.e. easily turn them all off at once should there ever be a need to do so). The group can also be referenced by other automations in the future. Plus it’s easy to add more input_booleans to it (and all automations that reference it will use the additional input_booleans).

I was trying to point out that having 5 booleans doing this is daft. I realise now that I didn’t put enough sarcasm in my post for this to shine through.

Not if each Boolean also has another function, like opening a valve, or enabling rooms to be isolated from heating?

This is the setup:

Boolean is set to “on” or “off” basis the set point of TRV, for example, if the measured temperature is less than the setpoint, the boolean is set to “on”. If the temperature is matching the setpoint, the boolean is set to off.

This means that i have a “call for heat” for each TRV (well, each room).

Now, what i am doing is firing an automation every 1 minute to check the status of the booleans, if any of them are on, the boiler fires. If they are all off, the boiler shuts down.

If i placed all booleans in a group, would this still work?

You may have missed the entire point of what I proposed.

I’m suggesting to stop thinking along the lines of polling and use events. In other words, instead of checking for the state of the input_booleans every minute, let their own state-changes control when the switch should be turned on/off.

Analogy is you have assigned someone a task and now ask them every minute if they have finished it. The strategy I offered is to allow that person to report when they are finished.

1 Like

Yup, but also as I suspected above, this means that you end up with a shed load of automations all on top of each other turning booleans on and off and then those booleans triggering other automations.

Multiple middle players creates many more opportunities for errors to creep in.

Better to trigger directly and reduce the number of middle players. ie whatever circumstances currently turn the booleans on and off should trigger the automation that turns the boiler on or off directly instead. The booleans are highly likely to be redundant in this scenario.

What if you want to add a delay to the change in state? I presume a “wait” condition?

This makes sense and I’ll have a play over the next couple of days. I am new-Ish to HA and have spent my life programming big building management systems which operate differently

1 Like

How do you mean? Do you want the state to be unchanged (static); for a certain period of time before the trigger occurs or do you simply want to pause for a period of time after it triggers before continuing?