Two sensors from single pin

Hello
I have an esp8266 connected (pin A0) to a soil moisture sensor. i want to expose two sensors from same ADC pin. my code is

sensor:
  - platform: adc
    pin: A0
    id: moisture_sensor
    name: "Soil Moisture"
    unit_of_measurement: "%"
    update_interval: 30s
    filters:
      - calibrate_linear:
        - 1 -> 0.0
        - 0.49 -> 100.0

  - platform: adc
    pin: A0
    id: moisture_sensor_v
    name: "Soil Moisture V"
    unit_of_measurement: "v"
    update_interval: 30s

If i log in the web server i can see two of these sensors.
image

But when i add to HA, i get only one sensor. Also notice the friendly name is from the missing sensor :-/

How can i solve this?

Use a template sensor for the moisture sensor and ADC A0 for the voltage.

how do i write lambda here? this code gave me error while compiling.

sensor:
  - platform: adc
    pin: A0
    id: moisture_sensor_v
    name: "Soil Moisture V"
    unit_of_measurement: "v"
    update_interval: 30s
    
    
  - platform: template
    name: "Soil Moisture"
    unit_of_measurement: "%"
    lambda: return sensor.moisture_sensor_v
    filters:
      - calibrate_linear:
        - 1 -> 0.0
        - 0.49 -> 100.0
    lambda: return id(moisture_sensor_v).state

[docs]

2 Likes