Conditions etc

Hi. I am doing some test yaml-ing and planning for an Olimex ESP32-POE-ISO that is going to serve as a controller unit for my DIY-music rack, ie audio sources, preamp, active xover, amps etc.

The main objectives are that I shall not have to switch on and off every gear separately and also in specific orders to avoid potential loud audible thumps if for example the preamp is turned off while amps are still on etc. So convenience and safety.

I have learned how to perform some Actions, for example to sequence on a series of output pins (they are on two daisy chained 74HC565 to get enough of them), and off in reverse order with on_click short and long and it works fine.

Now I am on to further modelling and creating conditions in the yaml, like for example checking if amps pins are off before allowing shutting down preamp pin.

And my first question are:
If I do an “on_click - switch.turn_on: pin x”, do I need to check if that pin already is on and do some if/else stuff, or will it just ignore the turn_on if it is already turned on?

Maybe have a single template switch that turns on your GPIO switches in the correct order and with a suitable delay?

No - it will just switch it on if it’s off and do nothing if it’s on.

1 Like

As for now I have done the sequencing like this

binary_sensor:    
  - platform: gpio
    name: "Switch 1"
    id: switch_1
    pin: 
      number: GPIO5
      inverted: True
      mode: 
        input: True
    on_click:
      - min_length: 50ms
        max_length: 450ms          
        then:
        - switch.turn_on: pin_0
        - delay: 2s         
        - switch.turn_on: pin_1
        - delay: 2s
        - switch.turn_on: pin_2
        - delay: 2s
        - switch.turn_on: pin_3    
      - min_length: 500ms
        max_length: 3s
        then:
        - switch.turn_off: pin_3
        - delay: 2s
        - switch.turn_off: pin_2
        - delay: 2s
        - switch.turn_off: pin_1
        - delay: 2s        
        - switch.turn_off: pin_0

It there is better ways I’m all ears :slight_smile:

No - that’s fine. The main reason you may use a template switch is that you could hide all the gpio switches from HA (internal: true), that would then allow you to control from Home Assistant as well as from the ESPHome device.

1 Like

I managed to do a condition test. I need to get some logic into what shall happen in given situations pressing buttons for inputs like digital or vinyl and outputs like speakers or headphones. Shall it switch or turn off etc. The indentation rules are crazy to get a grip on. Any hints on how to think?

binary_sensor:    

  - platform: gpio
    name: "Input Digital"
    id: switch_1
    pin: 
      number: GPIO5
      inverted: True
      mode: 
        input: True
    on_click:
      - min_length: 20ms
        max_length: 499ms          
        then:           
        - if:
            condition:
              switch.is_off: pin_4
            then:
              - switch.turn_on: pin_0
              - delay: 2s         
              - switch.turn_on: pin_1
            else:
              - switch.turn_on: pin_2
              - delay: 2s
              - switch.turn_on: pin_3    
      - min_length: 500ms
        max_length: 3s
        then:
        - switch.turn_off: pin_3
        - delay: 2s
        - switch.turn_off: pin_2
        - delay: 2s
        - switch.turn_off: pin_1
        - delay: 2s        
        - switch.turn_off: pin_0