cd74hc4067 Analog Multiplexer

The cd74hc4067 Analog Multiplexer component allows you to attach up to 16 analog input sensors to a single ADC pin. The component is used to activate the right multiplexer pin for each of the defined cd74hc4067 sensors.

For further information about the cd74hc4067 chip see the spec sheet and there are also some guides around like the one from Adam Meyer.

Actually, the chip is bidirectional and could also be used as output, but this is not supported by the component yet.

First, you need to configure the component with the digital pins that control the multiplexer. Then you need to set up a voltage sensor source (e.g. ADC sensor) and pass it to the cd74hc4067 sensors with the sensor option. Each cd74hc4067 sensor is configured for one of the 16 input pins of the multiplexer.

# Example configuration entry
cd74hc4067:
  - id: cd74hc4067_1
    pin_s0: D0
    pin_s1: D1
    pin_s2: D2
    pin_s3: D3

sensor:
  - platform: adc
    id: adc_sensor
    pin: A0
  - platform: cd74hc4067
    id: adc_0
    number: 0
    sensor: adc_sensor
  - platform: cd74hc4067
    id: adc_1
    number: 1
    sensor: adc_sensor

Component/Hub

Configuration Variables:

  • pin_s0 to pin_s3 (Required, Pin): The I/O pins connected to the S0 to S3 channel selection pins

  • delay (Optional, Time): A small delay duration needed for the chip to switch inputs, defaults to 2ms.

Sensor

Configuration Variables:

  • sensor (Required, ID): The source sensor to measure voltage values from, e.g. ADC sensor.

  • cd74hc4067_id (Required, ID): The id of the cd74hc4067 component to use for this sensor.

  • number (Required, int): The number of the cd74hc4067 input pin (0-15)

  • All other options from Sensor.

Application Example

In this example, the component is used to measure the AC power output of two solar inverters to integrate them as energy sources in Home Assistant.

For this purpose, CT clamp sensors are attached on each of the sensors. Filters are needed to calibrate the output and cut off the noise of near-zero values. The adc and cd74hc4067 sensors updates are triggered by the ct_clamp sensors and have a very high internal update frequency.

cd74hc4067:
  - id: cd74hc4067_1
    pin_s0: D0
    pin_s1: D1
    pin_s2: D2
    pin_s3: D3

sensor:
  - platform: adc
    id: adc_sensor
    pin: A0
    update_interval: 3600s
  - platform: cd74hc4067
    id: solar_1_raw
    number: 0
    sensor: adc_sensor
    update_interval: 3600s
  - platform: cd74hc4067
    id: solar_2_raw
    number: 1
    sensor: adc_sensor
    update_interval: 3600s
  - platform: ct_clamp
    name: "SolarPower1"
    sensor: solar_1_raw
    update_interval: 5s
    unit_of_measurement: "W"
    device_class: "power"
    filters:
      - lambda: "return x > 0.001 ? x * 56221 : 0;"
  - platform: ct_clamp
    name: "SolarPower2"
    sensor: solar_2_raw
    update_interval: 5s
    unit_of_measurement: "W"
    device_class: "power"
    filters:
      - lambda: "return x > 0.001 ? x * 57519 : 0;"

See Also