esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

Substitutions for PINs #2342

Open dominik4545 opened 1 year ago

dominik4545 commented 1 year ago

Describe the problem you have/What new integration you would like Please make PIN values available for substitutions

Please describe your use case for this integration and alternatives you've tried: Currently I am working on a project automating my subfloor heating. This uses a WEMOS D1 Mini and a relay board to control the valves. Unfortunately 90 % of the configuration stays the same for all 6 rooms I am doing the automation for. The only things which are changing are the variable from Home Assistant storing the current temperature (available for substitution) and the PIN value (e.g. D2) used to open the relay (not available for substitution). My current workaround is to copy the whole section 6 times to cover all rooms but it would be much easier if the PIN values would be available for substitution as well.

Thank you very much in advance!

Additional context

I tried to add the following snippet to the main configuration for the WEMOS D1 Mini:

# Add thermostat configuration for kitchen
# D7 -> IN3 -> kitchen
<<: !include 
      file: common/thermostat.yaml
      vars:
        location: "kitchen"
        valve_pin: D7 

and this is the block I need to copy 6 times once for each room:

##########################################################################
#
# ESPHome configuration for heating based on WEMOS D1 Mini.
# Introduced in August 2023
#
##########################################################################

# Thermostat for the given room
climate:
  - platform: thermostat
    id: thermostat_${location}
    name: thermostat_${location}
    default_preset: home
    idle_action:
      - switch.turn_off: valve_${location}
    heat_action:
      - switch.turn_on: valve_${location}
    min_heating_off_time: 300s
    min_heating_run_time: 300s
    min_idle_time: 30s
    preset:
      - name: away
        default_target_temperature_low: 15 °C
      - name: comfort
        default_target_temperature_low: 22 °C
      - name: home
        default_target_temperature_low: 21.5 °C
      - name: sleep
        default_target_temperature_low: 17 °C
    sensor: temperature_${location}

# Temperature of the given room (from home assistant)
sensor:
  - platform: homeassistant
    id: temperature_${location}
    entity_id: sensor.temperature_${location}
    filters:
     - filter_out: nan
    internal: true

# Relais for valve
switch:
  - platform: gpio
    id: valve_${location}
    name: valve_${location}
    icon: "mdi:pipe-valve"
    pin:
      inverted: yes
      number: ${valve_pin}
    restore_mode: ALWAYS_OFF
afarago commented 9 months ago

I think they are enabled by now.

I have an rtttl snippet with defaults on

snippet

substitutions:
  # default, can be overwritten
  buzzer_platform: esp8266_pwm
  buzzer_port: D5

### BUZZER #############################################################
output:
  - platform: ${buzzer_platform} # esp8266:esp8266_pwm or esp32:ledc
    pin: ${buzzer_port}
    frequency: 1000 Hz
    id: buzzer_output
    # max_power: ${max_power} # set_max_power(0.0 - 1.0)

usage

packages:
  snippet__rtttlbuzzer:
    !include { file: .snippet.rtttlbuzzer.yaml, vars: { buzzer_port: D7 } }

platform matches my most used default, so no override needed below.