Trying to add some odd hardware

I have an ESP32-based device that has two UART sensors on the same RX/TX pins via a bus switch chip. If a pin is high, the bus switch connects UART to sensor A, if low then sensor B. I currently have a working configuration that just sets the bus switch pin always high and only has configuration for sensor A.

Is it possible to have both sensors added to the configuration and have the firmware automatically set the bus switch pin appropriately when it wants to poll a sensor? I’ve looked through the list of Components in the documentation and I don’t see anything that would do this, but then I’m pretty new to ESPHome so I may be missing something obvious.

I’m confident it’s doable. You can poll the sensors “manually” with interval for example, switching the sensor before poll. For better suggestions, post specs of your hardware…

Thanks for the suggestion. What kind of specs would be helpful? This device is using the “ESP32-DEVKITC-32E” module. The two sensors connected to the UART line are the PMS5003 and the MH-Z19.
Config for the sensors:

sensor:
- platform: pmsx003
    type: PMSX003
    pm_1_0:
      name: "Particulate Matter <1.0µm Concentration"
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
    update_interval: 120s
    uart_id: softuart
sensor:
- platform: mhz19
    co2:
      name: CO2 PPM
    temperature:
      name: MH-Z19 Temperature
    uart_id: softuart

I currently only have one sensor type added in the config and also have this to permanently set the switch:

esphome:
  on_boot:
    - priority: 600
      then:
        - output.turn_on: gpio_en_pms5003

What would the config look like for manually polling a sensor?

Never tried, but I don’t see it could not be done.

So set both sensors update_interval: never
and give them both id

interval:
  - interval: 30s
    then:
      # Select PMS sensor
      - output.turn_on: gpio_en_pms5003
      - delay: 2s
      - component.update: pmsx

      # Switch to MH-Z19
      - output.turn_off: gpio_en_pms5003
      - delay: 500ms
      - component.update: co2

You might need to play with delays here, pmsx is streaming type if I understand well.
But why your uart is named softuart?

Hm, the value “never” is only valid for mhz19. pmsx003 only accepts units of time for update_interval.

How would the manually scheduled intervals work with component initialization?

UART is using nonstandard pins, so I have this config block:

uart:
  tx_pin: GPIO01
  rx_pin: GPIO39
  baud_rate: 9600
  id: softuart

I’m not sure if it’s actually using a software implementation, or just routing the UART peripheral to those pins.

Put some long interval there, like 24h.
I think you get better suggestions here if you post your complete yaml.
Why you have chosen those uart pins?

Ran into another issue with component.update for the pmsx003:

ID ‘pmsx003a’ of type pmsx003::PMSX003Component doesn’t inherit from PollingComponent.

These devices are from an older project that originally ran custom firmware, so we just have to work with the existing hardware design wrt pin assignments. I’ve attached the full (redacted) config yaml below. You’ll notice there’s a slight difference to how I originally described it. The bus switch is controlled by two GPIO lines, one for enabling each UART sensor connection.

esphome:
  name: test1
  friendly_name: test1
  on_boot:
    - priority: 600
      then:
        - output.turn_off: gpio_en_pms5003
        - output.turn_off: gpio_en_mhz19

interval:
  - interval: 60s
    then:
      # Select PMS sensor
      - output.turn_on: gpio_en_pms5003
      - delay: 100ms
      - component.update: pmsx003a
      - delay: 2s
      - output.turn_off: gpio_en_pms5003

      # Switch to MH-Z19
      - output.turn_on: gpio_en_mhz19
      - delay: 100ms
      - component.update: mhz19a
      - delay: 500ms
      - output.turn_off: gpio_en_mhz19

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  baud_rate: 0

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

ota:
  platform: esphome
  password: "redacted"

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

sensor:
  - platform: dht
    model: DHT22
    pin: 14
    temperature:
      name: "Temperature"
      filters:
        - offset: -2.0
    humidity:
      name: "Humidity"
    update_interval: 60s
  - platform: mhz19
    id: mhz19a
    co2:
      name: CO2 PPM
    temperature:
      name: MH-Z19 Temperature
    update_interval: never
    uart_id: softuart
  - platform: pmsx003
    id: pmsx003a
    type: PMSX003
    pm_1_0:
      name: "Particulate Matter <1.0µm Concentration"
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
    update_interval: 24h
    uart_id: softuart

uart:
  tx_pin: GPIO01
  rx_pin: GPIO39
  baud_rate: 9600
  id: softuart

output:
  - platform: gpio
    pin: GPIO26
    id: gpio_en_pms5003
  - platform: gpio
    pin: GPIO27
    id: gpio_en_mhz19

If it’s not polling component, manual update doesn’t work.

So try without component.update: pmsx003a line and use 3s delay.
Set the default 0s update_interval for pmsx003.