NEED HELP WITH LOCKING LOGIC: 105A Three Phase heaters

I need some logic help:

I have to control 3 105A three phase burners. Im using Shelly 1 Pros connected to a 150A contactor (just for details here and yes It is being certified by a licensed electrical engineer)

I have 3 input bools lets call them B1,B2,+B3 and these are in the frontend as buttons using call_service: input_bool: toggle. These 3 bools have device automations that control 3 Shelly 1Pro devices. Lets call them P1 P2 + P3.

I need to make a way of locking out the ability to press one of the three input bools if any of 2 the Shellys have states as ON. The locked out bool MUST be the bool for the DEVICE (shelly) that is NOT ON. The states of the bools MUST be derived from the Shellys specifically.

Its doing my head in that the state of an input_bool cant be derived from a device.

Any help is REALLLLLLY appreciated.

You can get the state of the Shelly entity.

Create a group of your input booleans (lets call it group.ipbools) then do something like this:

  - platform: state
      - input_boolean.b1
      - input_boolean.b2
      - input_boolean.b3
  - choose:
      - conditions:
          - "{{ trigger.to_state.state == 'off' }}"
          - service: switch.turn_off
              entity_id: "{{ switch.p ~ trigger.entitiy_id[-1] }}"
      - conditions:
          - "{{ trigger.to_state.state == 'on }}"
          - choose:
              - conditions:
                  - "{{ expand('group.ipbools')|selectattr('state', 'eq', 'on')|list|count < 2 }}"
                  - service: switch.turn_on
                      entity_id: "{{ switch.p ~ trigger.entitiy_id[-1] }}"
                  - service: homeassistant.turn_off
                      entity_id: "{{ trigger.entitiy_id }}"

This assumes your switch entity id’s are switch.p1, switch.p2, switch.p3

There’s a bit going on here, so unpacking it:

  • The trigger occurs on any state change of any of the listed input_booleans. Because of the null to: it ignores attribute changes.
  • The first choose action tests if the input boolean that triggered the automation changed to on or off. If it was ‘off’ then switch off the corresponding switch, and that is all.
  • If the triggering input boolean changed to ‘on’, then test if there are already 2 input booleans on. If there are less than 2 input booleans on, then switch on the corresponding switch. If there are 2 or more input booleans already on, then turn off the triggering input boolean right away.

This is untested and going on my past experience is likely to contain errors.

1 Like

WOW - Tom

Yes theres a lot to unpack here - I didnt expect this level of detail. You are a Jinja master.

I will unpack this and see if if fits the bill but what youve suggested better than i would have ever thought of myself.

Tq. Let u know how it works out.

“{{ expand(‘group.ipbools’)|selectattr(‘state’, ‘eq’, ‘on’)|list|count < 2 }}”

This is truly beyond my jinja knowledge but Im willing to educate myself

first time seeing ‘expand’


Can I just ask if you need to have these 3 contactors interlocked, have you also done this physically with wiring? It’s simple to do and will ensure that you aren’t just relying on code to provide your interlock.

Would you mind explaining the function of this? (particularly the [-1]) As a jinja noob I’m intrigued.

Python string slicing. [-1] is the last character of the string.


Hey thanks to @tom_l. His insight was the seed for achieving this. After playing with his template what I was trying to achieve got way too convoluted. In the end I didnt use the jinja code - i simplified it by using groups and a bunch of input booleans as inhibits of the elements that could not be active and then use the restriction card to restrict the selection of the elements that cant be used based on the states of the inhibits.

There are physical inhibits as mandated by the Electrical Engineer for safety - However I needed inhibits within HA as well so that the physical ones dont get activated (as they are a manual/physical reset) if they are ever triggered.