Reduce the size of config file (yaml) - many repeats

Hi

I have built a button panel with the following features:

  • 8 push buttons
  • each button can do single click, double click and hold
  • each button has a led to signal mode
  • a buzzer (rtttl)
  • everything controlled by an ESP32

Having this many components and functions gives me a very long yaml file.
I looking for ways to reduce the repeated parts - actually looking for a discussion for the best approach and to learn something…

So I would love to get some tips and inputs to the below.

All the basic stuff is hidden away in an injected file called .base.yaml - I have included in at the end for completeness.

substitutions:
  device_name: kitchen-buttons
  friendly_name: Bedlamp
  ip_node: '222'

packages:
  base: !include .base.yaml

esphome:
  name: ${device_name}

esp32:
  board: node32s
  framework:
    type: arduino

switch:
################################################
#
#     Switch 1
#
#################################################
  - platform: template
    name: "Toggle 1 single"
    id: switch_1_single
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_1
        effect: "single"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_1

  - platform: template
    name: "Toggle 1 double"
    id: switch_1_double
    optimistic: true
    icon: mdi:numeric-1-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_1
        effect: "double"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_1

  - platform: template
    name: "Toggle 1 long"
    id: switch_1_long
    internal: true
    optimistic: true
    icon: mdi:chat-sleep
    on_turn_on:
    - light.turn_on: 
        id: button_led_1
        effect: "hold"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_1

################################################
#
#     Switch 2
#
#################################################
  - platform: template
    name: "Toggle 2 single"
    id: switch_2_single
    optimistic: true
    icon: mdi:numeric-2-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_2
        effect: "single"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_2

  - platform: template
    name: "Toggle 2 double"
    id: switch_2_double
    optimistic: true
    icon: mdi:numeric-2-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_2
        effect: "double"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_2

  - platform: template
    name: "Toggle 2 long"
    id: switch_2_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_2
        effect: "hold"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_2

################################################
#
#     Switch 3
#
#################################################
  - platform: template
    name: "Toggle 3 single"
    id: switch_3_single
    optimistic: true
    icon: mdi:numeric-3-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_3
        effect: "single"
    on_turn_off:
    - light.turn_off: button_led_3

  - platform: template
    name: "Toggle 3 double"
    id: switch_3_double
    optimistic: true
    icon: mdi:numeric-3-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_3
        effect: "double"
    on_turn_off:
    - light.turn_off: button_led_3

  - platform: template
    name: "Toggle 3 long"
    id: switch_3_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_3
        effect: "hold"
    on_turn_off:
    - light.turn_off: button_led_3

################################################
#
#     Switch 4
#
#################################################
  - platform: template
    name: "Toggle 4 single"
    id: switch_4_single
    optimistic: true
    icon: mdi:numeric-4-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_4
        effect: "single"
    on_turn_off:
    - light.turn_off: button_led_4

  - platform: template
    name: "Toggle 4 double"
    id: switch_4_double
    optimistic: true
    icon: mdi:numeric-4-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_4
        effect: "double"
    on_turn_off:
    - light.turn_off: button_led_4

  - platform: template
    name: "Toggle 4 long"
    id: switch_4_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_4
        effect: "hold"
    on_turn_off:
    - light.turn_off: button_led_4

################################################
#
#     Switch 5
#
#################################################
  - platform: template
    name: "Toggle 5 single"
    id: switch_5_single
    optimistic: true
    icon: mdi:numeric-5-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_5
        effect: "single"
    on_turn_off:
    - light.turn_off: button_led_5

  - platform: template
    name: "Toggle 5 double"
    id: switch_5_double
    optimistic: true
    icon: mdi:numeric-5-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_5
        effect: "double"
    on_turn_off:
    - light.turn_off: button_led_5

  - platform: template
    name: "Toggle 5 long"
    id: switch_5_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_5
        effect: "hold"
    on_turn_off:
    - light.turn_off: button_led_5

################################################
#
#     Switch 6
#
#################################################
  - platform: template
    name: "Toggle 6 single"
    id: switch_6_single
    optimistic: true
    icon: mdi:numeric-6-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_6
        effect: "single"
    on_turn_off:
    - light.turn_off: button_led_6

  - platform: template
    name: "Toggle 6 double"
    id: switch_6_double
    optimistic: true
    icon: mdi:numeric-6-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_6
        effect: "double"
    on_turn_off:
    - light.turn_off: button_led_6

  - platform: template
    name: "Toggle 6 long"
    id: switch_6_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_6
        effect: "hold"
    on_turn_off:
    - light.turn_off: button_led_6

################################################
#
#     Switch 7
#
#################################################
  - platform: template
    name: "Toggle 7 single"
    id: switch_7_single
    optimistic: true
    icon: mdi:numeric-7-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_7
        effect: "single"
    on_turn_off:
    - light.turn_off: button_led_7

  - platform: template
    name: "Toggle 7 double"
    id: switch_7_double
    optimistic: true
    icon: mdi:numeric-7-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_7
        effect: "double"
    on_turn_off:
    - light.turn_off: button_led_7

  - platform: template
    name: "Toggle 7 long"
    id: switch_7_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_7
        effect: "hold"
    on_turn_off:
    - light.turn_off: button_led_7

################################################
#
#     Switch 8
#
#################################################
  - platform: template
    name: "Toggle 8 single"
    id: switch_8_single
    optimistic: true
    icon: mdi:numeric-8-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_8
        effect: "single"
    on_turn_off:
    - light.turn_off: button_led_8

  - platform: template
    name: "Toggle 8 double"
    id: switch_8_double
    optimistic: true
    icon: mdi:numeric-8-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_8
        effect: "double"
    on_turn_off:
    - light.turn_off: button_led_8

  - platform: template
    name: "Toggle 8 long"
    id: switch_8_long
    internal: true
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_8
        effect: "hold"
    on_turn_off:
    - light.turn_off: button_led_8


binary_sensor:


################################################
#
#     Button 1
#
#################################################
  - name: "Button 1"
    id: button_1
    internal: true
    platform: gpio
    pin:
      number: 23
      mode:
        input: true
        pullup: true
      inverted: true

    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_1_double).toggle();
          - logger.log: "Button 1 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_1_single).toggle();
          - logger.log: "Button 1 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_1_single).turn_off();
          - lambda: !lambda id(switch_1_double).turn_off();
          - logger.log: "Button 1 Long"
  
################################################
#
#     Button 2
#
#################################################
  - name: "Button 2"
    id: button_2
    internal: true
    platform: gpio
    pin:
      number: 22
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_2_double).toggle();
          - logger.log: "Button 2 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_2_single).toggle();
          - logger.log: "Button 2 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_2_single).turn_off();
          - lambda: !lambda id(switch_2_double).turn_off();
          - logger.log: "Button 2 Long"
  
  ################################################
#
#     Button 3
#
#################################################
  - name: "Button 3"
    id: button_3
    internal: true
    platform: gpio
    pin:
      number: 4
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_3_double).toggle();
          - logger.log: "Button 3 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_3_single).toggle();
          - logger.log: "Button 3 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_3_single).turn_off();
          - lambda: !lambda id(switch_3_double).turn_off();
          - logger.log: "Button 3 Long"

  ################################################
#
#     Button 4
#
#################################################          
  - name: "Button 4"
    id: button_4
    internal: true
    platform: gpio
    pin:
      number: 3
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_4_double).toggle();
          - logger.log: "Button 4 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_4_single).toggle();
          - logger.log: "Button 4 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_4_single).turn_off();
          - lambda: !lambda id(switch_4_double).turn_off();
          - logger.log: "Button 4 Long"

################################################
#
#     Button 5
#
#################################################
  - name: "Button 5"
    id: button_5
    internal: true
    platform: gpio
    pin:
      number: 19
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_5_double).toggle();
          - logger.log: "Button 5 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_5_single).toggle();
          - logger.log: "Button 5 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_5_single).turn_off();
          - lambda: !lambda id(switch_5_double).turn_off();
          - logger.log: "Button 5 long"


  ################################################
#
#     Button 6
#
#################################################          
  - name: "Button 6"
    id: button_6
    internal: true
    platform: gpio
    pin:
      number: 18
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_6_double).toggle();
          - logger.log: "Button 6 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_6_single).toggle();
          - logger.log: "Button 6 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_6_single).turn_off();
          - lambda: !lambda id(switch_6_double).turn_off();
          - logger.log: "Button 6 long"


  ################################################
#
#     Button 7
#
#################################################        
  - name: "Button 7"
    id: button_7
    internal: true
    platform: gpio
    pin:
      number: 5
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_7_double).toggle();
          - logger.log: "Button 7 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_7_single).toggle();
          - logger.log: "Button 7 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_7_single).turn_off();
          - lambda: !lambda id(switch_7_double).turn_off();
          - logger.log: "Button 7 long"

################################################
#
#     Button 8
#
#################################################          
  - name: "Button 8"
    id: button_8
    internal: true
    platform: gpio
    pin:
      number: 17
      mode:
        input: true
        pullup: true
      inverted: true
      
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_8_double).toggle();
          - logger.log: "Button 8 Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_8_single).toggle();
          - logger.log: "Button 8 Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_8_single).turn_off();
          - lambda: !lambda id(switch_8_double).turn_off();
          - logger.log: "Button 8 long"

output:
  - platform: ledc
    pin: 16
    id: pin_led_1

  - platform: ledc
    pin: 27
    id: pin_led_2

  - platform: ledc
    pin: 14 #25
    id: pin_led_3

  - platform: ledc
    pin: 26 #33
    id: pin_led_4

  - platform: ledc
    pin: 25  #32
    id: pin_led_5

  - platform: ledc
    pin: 13
    id: pin_led_6

  - platform: ledc
    pin: 33   #14
    id: pin_led_7

  - platform: ledc
    pin: 32   #27
    id: pin_led_8
    
  - platform: ledc
    pin: 2
    id: rtttl_out

light:
################################################
#
#     Light 1
#
#################################################          
  - platform: monochromatic
    output: pin_led_1
    name: "Button 1 LED"
    id: button_led_1
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

################################################
#
#     Light 2
#
#################################################          
  - platform: monochromatic
    output: pin_led_2
    name: "Button 2 LED"
    id: button_led_2
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s
################################################
#
#     Light 3
#
#################################################          

  - platform: monochromatic
    output: pin_led_3
    name: "Button 3 LED"        
    id: button_led_3
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

################################################
#
#     Light 4
#
#################################################          

  - platform: monochromatic
    output: pin_led_4
    name: "Button 4 LED"
    id: button_led_4
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

################################################
#
#     Light 5
#
#################################################          

  - platform: monochromatic
    output: pin_led_5
    name: "Button 5 LED"    
    id: button_led_5
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

################################################
#
#     Light 6
#
#################################################          

  - platform: monochromatic
    output: pin_led_6
    name: "Button 6 LED"
    id: button_led_6
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

################################################
#
#     Light 7
#
#################################################          

  - platform: monochromatic
    output: pin_led_7
    name: "Button 7 LED"
    id: button_led_7
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

################################################
#
#     Light 8
#
#################################################          

  - platform: monochromatic
    output: pin_led_8
    name: "Button 8 LED"    
    id: button_led_8
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

rtttl:
  output: rtttl_out
  on_finished_playback:
    - logger.log: 'Song ended!'

api:
  services:
    - service: play_rtttl
      variables:
        song_str: string
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'

base.yaml:

logger:

api:

ota:
    password: !secret esphome_api_password

wifi:
    ssid: !secret wifi_ssid
    password: !secret wifi_password
    use_address: 192.168.0.${ip_node} 
    
    manual_ip:
        static_ip: 192.168.0.${ip_node}
        gateway: 192.168.0.100
        subnet: 255.255.255.0
        dns1: 192.168.0.100
    
    ap:
        ssid:  ${device_name} conf AP
        password: !secret fallback_password

captive_portal:

web_server:
    port: 80
    
time:
    - platform: homeassistant
      id: homeassistant_time

sensor:
    - platform: wifi_signal
      name: ${device_name} WiFi Sensor
      update_interval: 60s

    - platform: uptime
      name: ${device_name} Uptime Sensor
      filters:
        - lambda: return x / 3600;
      unit_of_measurement: "hours"
      accuracy_decimals: 2

binary_sensor:
    - platform: status
      name: "${device_name} Status"

I think the best way to condense or optimize this configuration is to combine the packages: mapping with the !include using substitutions. The repeated code seems to have 3 unique items, the id, input pin, and output pin. This allows all of the related entities needed for each instance to be consolidated into one file. The packages: mapping takes care of merging all of the similar configurations together. Using the substitution feature of the !include statement allows the single file to implement 8 nearly identical instances of the related entities.

substitutions:
  device_name: kitchen-buttons
  friendly_name: Bedlamp
  ip_node: '222'


esphome:
  name: ${device_name}

esp32:
  board: node32s
  framework:
    type: arduino

packages:
  base: !include .base.yaml
  button1: !include { file: .button.yaml, vars: { id : '1' , gpio_in: '23' , gpio_out: '16'} }
  button2: !include { file: .button.yaml, vars: { id : '2', gpio_in: '22', gpio_out: '27' } }
  button3: !include { file: .button.yaml, vars: { id : '3', gpio_in: '4', gpio_out: '14' } }
  button4: !include { file: .button.yaml, vars: { id : '4', gpio_in: '3', gpio_out: '26' } }
  button5: !include { file: .button.yaml, vars: { id : '5', gpio_in: '19', gpio_out: '25' } }
  button6: !include { file: .button.yaml, vars: { id : '6', gpio_in: '18', gpio_out: '13' } }
  button7: !include { file: .button.yaml, vars: { id : '7', gpio_in: '5', gpio_out: '33' } }
  button8: !include { file: .button.yaml, vars: { id : '8', gpio_in: '17', gpio_out: '32' } }
    

output:
  - platform: ledc
    pin: 2
    id: rtttl_out


rtttl:
  output: rtttl_out
  on_finished_playback:
    - logger.log: 'Song ended!'

api:
  services:
    - service: play_rtttl
      variables:
        song_str: string
      then:
        - rtttl.play:
            rtttl: !lambda 'return song_str;'    


############################################################################
#.button.yaml file contents

#Expected ${id} to substitute for index number
#Expected ${gpio_in} to substitute for the gpio button pin
#Expected ${gpio_out} to substitute for the gpio button pin

switch:
  - platform: template
    name: "Toggle ${id} single"
    id: switch_${id}_single
    optimistic: true
    icon: mdi:numeric-1-box
    on_turn_on:
    - light.turn_on: 
        id: button_led_${id}
        effect: "single"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_${id}

  - platform: template
    name: "Toggle ${id} double"
    id: switch_${id}_double
    optimistic: true
    icon: mdi:numeric-1-box-multiple
    on_turn_on:
    - light.turn_on: 
        id: button_led_${id}
        effect: "double"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_${id}

  - platform: template
    name: "Toggle ${id} long"
    id: switch_${id}_long
    internal: true
    optimistic: true
    icon: mdi:chat-sleep
    on_turn_on:
    - light.turn_on: 
        id: button_led_${id}
        effect: "hold"
        brightness: 50%
    on_turn_off:
    - light.turn_off: button_led_${id}


binary_sensor:
  - name: "Button ${id}"
    id: button_${id}
    internal: true
    platform: gpio
    pin:
      number: ${gpio_in}
      mode:
        input: true
        pullup: true
      inverted: true

    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 0.3s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: !lambda id(switch_${id}_double).toggle();
          - logger.log: "Button ${id} Double"
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_${id}_single).toggle();
          - logger.log: "Button ${id} Single"
      - timing:
          - ON for 1s to 2s
          - OFF for at least 0.5s
        then:
          - lambda: !lambda id(switch_${id}_single).turn_off();
          - lambda: !lambda id(switch_${id}_double).turn_off();
          - logger.log: "Button ${id} Long"
  

output:
  - platform: ledc
    pin:  ${gpio_out}
    id: pin_led_${id}

light:
  - platform: monochromatic
    output: pin_led_${id}
    name: "Button ${id} LED"
    id: button_led_${id}
    internal: true
    effects:
      - pulse:
          name: "single"
          transition_length: 2s
          update_interval: 4s
      - pulse:
          name: "double"
          transition_length: 1s
          update_interval: 2s
      - pulse:
          name: "hold"
          transition_length: 0.5s
          update_interval: 1s

9 Likes

Hi mulmcu

I remember seeing that it’s possible to pass variables to other packages - but never used it and never thought of it.

Thanks a mill for actually writing out the files - WITH the correct pins and everything. I could copy your code and compile it directly

You are a true gentleman, thank you sir!

3 Likes