4 channel touch light remote - blueprint

substitutions:
  light_id: "wiz_rgbw_tunable_xxxxxx"
  
esphome:
  name: light-remote
  friendly_name: light-remote

rp2040:
  board: rpipicow
  framework:
    # Required until https://github.com/platformio/platform-raspberrypi/pull/36 is merged
    platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git

# Enable logging
logger:
  level: debug

# Enable Home Assistant API
api:
  encryption:
    key: "hash"

ota:
  password: "hash"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "light-remote Fallback Hotspot"
    password: "hash"
    
  use_address: static

switch:
  - platform: restart
    name: "restart"

light:
  - platform: status_led
    pin: GPIO17
    id: status_blue

binary_sensor:
#touch_1
  - platform: gpio
    name: "power"
    pin:
      number: GPIO18
      mode:
        input: true
        pullup: false
    id: touch1
    internal: True
    on_press:
      then:
        - light.turn_on: status_blue
        - script.execute: toggle_light
    on_release:
      then:
        - light.turn_off: status_blue

#touch_2
  - platform: gpio
    name: "scene"
    pin:
      number: GPIO21
      mode:
        input: true
        pullup: false
    id: touch2
    internal: True
    on_press:
      then:
        - light.turn_on: status_blue
        - script.execute: select_scene
    on_release:
      then:
        - light.turn_off: status_blue

#touch_3
  - platform: gpio
    name: "sun"
    pin:
      number: GPIO20
      mode:
        input: true
        pullup: false
    id: touch3
    internal: True
    on_press:
      then:
        - light.turn_on: status_blue
        - script.execute: increase_brightness
    on_release:
      then:
        - light.turn_off: status_blue

#touch_4
  - platform: gpio
    name: "moon"
    pin:
      number: GPIO19
      mode:
        input: true
        pullup: false
    id: touch4
    internal: True
    on_press:
      then:
        - light.turn_on: status_blue
        - script.execute: decrease_brightness
    on_release:
      then:
        - light.turn_off: status_blue

select:
  - platform: template
    optimistic: true
    options:
      - "Relax"
      - "Focus"
      - "Warm White"
      - "Cool white"
    initial_option: "Warm White"
    id: scene
    on_value:
      then:
        - homeassistant.service:
            service: light.turn_on
            data:
              entity_id: light.${light_id}
            data_template:
              effect: !lambda return x.c_str();

sensor:
  - platform: homeassistant
    id: brightness
    entity_id: light.${light_id}
    attribute: brightness
    filters:
      - debounce: 5s
    on_value:
      then:
        - number.set:
            id: brightness_slider
            value: !lambda return x;

number:
  - platform: template
    optimistic: true
    min_value: 0
    max_value: 255
    step: 25
    id: brightness_slider
    on_value:
      then:
        - homeassistant.service:
            service: light.turn_on
            data:
              entity_id: light.${light_id}
            data_template:
              brightness: !lambda return x;

script:
  - id: toggle_light
    then:
      - homeassistant.service:
          service: light.toggle
          data:
            entity_id: light.${light_id}

  - id: select_scene
    then:
      - select.next:
          id: scene

  - id: increase_brightness
    then:
      - while:
          condition:
            and:
              - binary_sensor.is_on: touch3
              - number.in_range:
                  id: brightness_slider
                  below: 254
          then:
            - number.increment:
                id: brightness_slider
                cycle: False
            - delay: 200ms

  - id: decrease_brightness
    then:
      - while:
          condition:
            and:
              - binary_sensor.is_on: touch4
              - number.in_range:
                  id: brightness_slider
                  above: 26
          then:
            - number.decrement:
                id: brightness_slider
                cycle: False
            - delay: 200ms