"Pin 4 is used in multiple places" since update?

Hi all,

I applied the latest ESPHome update (2023.12.1) to HA tonight and then updated all my online devices (17) and all but one went fine and that gives a validation error as per the title?

I’m no coder so don’t know what would have changed before and after the update that would bring this error as an issue?

esphome:
  name: co2-sensor-2
  platform: ESP32
  board: "featheresp32"  

# Enable Home Assistant API
api:

ota:

wifi:
  ssid: !secret ssid
  password: !secret password
  
  #  use_address: 192.168.0.207
  
  manual_ip:
   static_ip: 192.168.0.198
   gateway: 192.168.0.100
   subnet: 255.255.255.0      
  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Co2-Sensor-2 Fallback Hotspot"
    password: "+++"

captive_portal:

logger:
  level: DEBUG
  logs:
    component: ERROR

# CO2 sensor
uart:
  rx_pin: 27
  tx_pin: 26
  baud_rate: 9600

# Dipslay driver: ST7789
spi:
  clk_pin: GPIO18
  mosi_pin: GPIO19

font:
  - file: "Oswald-Light.ttf"
    id: font_70
    size: 70
    glyphs: 0123456789 # Only used for CO2 level

  - file: "Oswald-Light.ttf"
    id: font_30
    size: 30

color:
  - id: color_black
    red: 0%
    green: 0%
    blue: 0%
    white: 0%
  - id: color_green
    red: 0%
    green: 100%
    blue: 0%
  - id: color_yellow
    red: 100%
    green: 100%
    blue: 0%
  - id: color_orange
    red: 100%
    green: 55%
    blue: 0%
  - id: color_red
    red: 100%
    green: 0%
    blue: 0%
  - id: color_white
    red: 100%
    green: 100%
    blue: 100%

display:
  - platform: st7789v
    model: TTGO TDisplay 135x240  # added bit
    id: my_display
    backlight_pin: GPIO4
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23
 #   brightness: 100%
    rotation: 90
    pages:
      # Page 1: Current CO2 levels
      #    0    - 1000 -> Green
      #    1000 - 1600 -> Yellow
      #    1600 - 2000 -> Orange
      #    >2000       -> Red
      - id: page1
        lambda: |-
          if(!id(co2_sensor_2).has_state() ){
            it.print(
              it.get_width()/2,
              it.get_height()/2,
              id(font_70),
              color_white,
              TextAlign::CENTER,
              "Starting..."
            );
            return;
          }
         
          auto bg_color = id(color_black);
          auto text_color = id(color_green);
          auto co2 = id(co2_sensor_2).state;
          if(co2 > 1000) text_color = id(color_yellow);
          if(co2 > 1600) text_color = id(color_orange);
          if(co2 > 2000){
            text_color = id(color_white);
            bg_color = id(color_red);
          }
          it.filled_rectangle(0, 0, it.get_width(), it.get_height(), bg_color);
          it.printf(
            it.get_width()/2, 
            it.get_height()/2, 
            id(font_70), 
            text_color, 
            TextAlign::CENTER, 
            "%.0f",
            co2
          );
      # Page 2: WiFi information
      - id: page2
        lambda: |-
          it.print(
            0, 0,
            id(font_30),
            id(color_white),
            "WiFi details"
          );
          it.printf(
            0, 30,
            id(font_30),
            id(color_white),
            "%s",
            id(wifi_ssid).state.c_str()
          );
          it.printf(
            0, 60,
            id(font_30),
            id(color_white),
            "%s",
            id(wifi_ip_addr).state.c_str()
          );
switch:
  - platform: gpio
    pin: GPIO4
    id: backlight
    internal: true

sensor:
  - platform: mhz19
    co2:
      name: "CO2 Sensor 2"
      id: "co2_sensor_2"
    temperature:
      name: "CO2 sensor 2 temperature"
      internal: true
    update_interval: 60s
    automatic_baseline_calibration: false
    
  - platform: wifi_signal
    name: "CO2 sensor 2 WiFi"
    update_interval: 60s   

text_sensor:
  - platform: wifi_info
    ip_address:
      internal: true
      id: wifi_ip_addr
    ssid:
      internal: true
      id: wifi_ssid

binary_sensor:
  # Button to cycle through pages on the display
  - platform: gpio
    pin:
      number: GPIO35
      inverted: true
    id: button_1
    on_click:
      then:
        - display.page.show_next: my_display
        - component.update: my_display

  # Button to toggle the backlight (for use at night)
  - platform: gpio
    pin:
      number: GPIO0
      inverted: true
    id: button_2
    on_click:
      then:
        - switch.toggle: backlight
        
button:
  - platform: restart
    name: "CO2 sensor 2 restart"  

When I validate it says:

Failed config

display.st7789v: [source <unicode string>:84]
  
  Pin 4 is used in multiple places.

I understand what ‘Pin 4 is used in multiple places’ appears to suggest, just that if it was an actual issue, how could it have been working all this time and what to do about it now please?.

The answer is in the changelog.

Hi Nick and thanks for the prompt reply.

I did try to look for the changelog but admit that I couldn’t find it but did see a very similar question posted here after I hit send on mine and so think a solution may be in ‘allow_other_uses: true’ and I’m trying that now (thanks). :wink:

Changelog is linked on the esphome.io page, ESPHome 2023.12.0 - 20th December 2023 — ESPHome

Thanks again, appreciated.

Unfortunately I don’t seem to understand how to use the example as when I do like this (copied from a quoted usage elsewhere):

display:
  - platform: st7789v
    model: TTGO TDisplay 135x240  # added bit
    id: my_display
    backlight_pin: GPIO4
     allow_other_uses: true
    cs_pin: GPIO5
    dc_pin: GPIO16
    reset_pin: GPIO23

I get on validation: (were row 88 is the allow_other_uses line in question):
“mapping values are not allowed in this context
in “”, line 88, column 22”

I’ve tried it on the first re to P4, both, without the ‘true’ …

I have the same issue but not sure how to proceed and what this means for me:
Pin Reuse validation¶
There is a new validation performed on configurations to ensure that pins are not reused unintentionally. This is a common source of issues and generally a pin does not need to be reused across multiple components in a single configuration. The error can be bypassed by specifically adding another config item to all of the duplicate pin definitions. See the Pin Schema for details.

I use pin 17 2 times…

INFO ESPHome 2023.12.1
INFO Reading configuration /config/esphome/sprinklerrelais4x.yaml…
Failed config

sensor.pulse_counter: [source :163]

Pin 17 is used in multiple places.
platform: pulse_counter
name: Water Flow Hoofdkraan hr
id: flow_hoofdkraan_hr
pin:
number: 17
mode:
input: True
output: False
open_drain: False
pullup: False
pulldown: False
inverted: False
ignore_strapping_warning: False
drive_strength: 20.0
update_interval: 10s
filters:
- lambda: !lambda |-
return (x / 400.0) * 60.0;
unit_of_measurement: L/hr
disabled_by_default: False
force_update: False
icon: mdi:pulse
accuracy_decimals: 2
state_class: measurement
count_mode:
rising_edge: INCREMENT
falling_edge: DISABLE
use_pcnt: True
internal_filter: 13us
sensor.pulse_counter: [source :172]

Pin 17 is used in multiple places.
platform: pulse_counter
name: Water Flow Hoofdkraan min
id: flow_hoofdkraan_min
pin:
number: 17
mode:
input: True
output: False
open_drain: False
pullup: False
pulldown: False
inverted: False
ignore_strapping_warning: False
drive_strength: 20.0
update_interval: 1s
filters:
- lambda: !lambda |-
return (x / 400.0);
unit_of_measurement: L/min
disabled_by_default: False
force_update: False
icon: mdi:pulse
accuracy_decimals: 2
state_class: measurement
count_mode:
rising_edge: INCREMENT
falling_edge: DISABLE
use_pcnt: True
internal_filter: 13us

Frikking layout button, where are you after forum update.

I think you are supposed to add the indented:

allow_other_uses: true

on the line after all the lines where the same GPIO pin has been defined, like:

switch:
  - platform: gpio
    pin: GPIO4
     allow_other_uses: true
    id: backlight
    internal: true

That didn’t work for me so I just edited out the switch function that toggles the backlight on and off and to my surprise / pleasure, it works (and removed the need to try to get the override to work). :wink:

Folks could you please format your posts correctly. It’s the </> button. Or use three backticks as explained here https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

2 Likes

Sorry and thanks for the hint re how to make it work Tom. :wink:

1 Like

I had to tinker with this for a bit also. I think what your problem is, you needed to set the pin number(GPIO4) on a different line, then add the allow_other_uses after that line. Try doing this, of course you have to add this to the to pin GPIO04

switch:
  - platform: gpio
    pin: 
      number: GPIO4
      allow_other_uses: true
    id: backlight
    internal: true
5 Likes

Yep, exactly where the changelog points you to:

Pin Schema

Try it in a mobile interface yourself and you’ll see its undoable there…

It is doable

Test code

There see, from my tablet.

A tablet is not a mobile.

I’ve done it from my phone too, you need to find backtick on your keyboard.

Sent from my mobile:
yes: it is possible

It’s the first option in the cog menu button.

1 Like

Nick, you seem upset / frustrated that not everyone finds all this as easy as you seem to?

Imagine looking at a block of code or even the information on pin-schema and effectively seeing hieroglyphics?

Imagine having dyslexia or dyscalculia but really wanting to play with this stuff and just not always seeing stuff as easily as others do?

Should those of us who have to live with such things not ask in help forums for help and support and if / when we do, would it be reasonable that we be given help / support that actually helps, rather than just sends us down other rabbit holes?

Maybe it’s because I spent most of my career in ‘IT Support’ and know what it’s like to have the answers and to really be able to help others with my experience. Personally I relished that position / opportunity and learned help was only really help if it helped (the person asking for help). :wink:

In the end I helped myself (because I couldn’t make sense of the help) by removing the pin duplication as it wasn’t a function I was using anyway (backlight on/off) and just happened to be part of the code I used as it was offered by another person wiling to share.

7 Likes

I guess I probably assumed that someone who was already programming in esphome would be able to follow the docs, as you have to have a certain understanding of the docs to start with.

Thanks. This is way more constructive feedback than @nickrout’s “read the docs …”.

4 Likes

Well, that’s probably not a completely bogus assumption, please be aware that many of us are able to handle the tech (especially as it all becomes more ‘Auto-magic’) but might only copy-paste existing code, rather than create any from scratch, or be able to just read say a manual on ‘How to be a brain surgeon’ and become one overnight. :wink:

I think I can state that in my years using HA, right now, today I’m very little better doing the coding than I was at the beginning. What I have maybe picked up is the ‘steps’ involved in getting to my goal (a functional solution), how to check for a ‘good’ project to copy and how to Google to a solution.

There is little point me actively trying to learn how to code because:

If I couldn’t pick it up when I was 15 I’m not likely to be able to at 65.

Because I’m not coding regularly, I am unlikely to be able to keep up or remember, especially given my current obligations.

I would rather pay someone to do that side while I enjoy doing the bits I do like (basically everything else).

Re ‘the docs’ … I’ve never been a big reader … I mean I can, it’s just not what I enjoy, I’d rather explore something (and why the GUI was invented) and one of the things that has attracted me to HA is how intuitive it has been (considering).

As I mentioned, I’d much rather watch the Youtube ‘Launch Parties’ with the guys, see if something is of interest and take it from there.

‘Different strokes for different folks’ as they say. :wink:

5 Likes