Showing more than 1 calculated value from same output ESP8266

Can I show 2 different calculated value in the dashboard from the same Output from a D1 Mini ESP8266?

I am measuring battery level through the A0 pin on the D1 mini.
Calculating VOLTAGE through voltage divider etc. then using calibrate_linear to get a BATTERY CHARGE LEVEL.

I would love to be able to see both VOLTAGE and BATTERY CHARGE (%) on my dashboard but dont know how to do this.

Thanks

here the code

- platform: adc
    pin: A0
    name: "Battery Charge" 
    unit_of_measurement: "%"
    #update_interval: 200s
    filters:
    - multiply: 4.208
    - calibrate_linear:
          - 4.2 -> 100
          - 4.16 -> 95
          - 4.12 -> 90
          - 4.07 -> 85
          - 4.03 -> 80
          - 3.99 -> 75
          - 3.95 -> 70
          - 3.91 -> 65
          - 3.87 -> 60
          - 3.82 -> 55
          - 3.78 -> 50
          - 3.74 -> 45
          - 3.70 -> 40
          - 3.66 -> 35
          - 3.62 -> 30
          - 3.57 -> 25
          - 3.53 -> 20
          - 3.49 -> 15
          - 3.45 -> 10
          - 3.41 -> 5
          - 3.3 -> 0
  
#  - platform: adc
#    pin: A0
#    name: "Battery Voltage"
#    unit_of_measurement: "V"
#    update_interval: 60s
#    filters:
#    - multiply: 4.208

When I do this code (without #'s in the last section) then I only get the Battery Voltage instead of both Voltage and Charge (%) Also HA only ever recongnises one of them not both at same time.

Please please post your code properly. see How to help us help you - or How to ask a good question

Apologies and thanks i couldnt figure it out but now its proper. Cheers

Hi.

You could use a template sensor that read from the last value from the adc. You could check this page out if you want to do more fancy stuff https://esphome.io/guides/automations.html#automatio.
I used this below to calibrate my levers on the soil moisture sensor (“Jordfuktighet” in Swedish)


sensor:
  - platform: template
    name: "Jordfuktighet"
    lambda: |-
          if (id(jordfukt_raw).state > 0.8) {
            return 0;
          } else if (id(jordfukt_raw).state < 0.36) {
            return 100;
          } else {
            return (0.8-id(jordfukt_raw).state) / (0.8-0.36) * 100.0;
          }
    update_interval: 60s

  - platform: adc
    pin: A0
    id: jordfukt_raw
    name: "Jordfuktighet raw"
    update_interval: 6s
    filters:
      - exponential_moving_average:
          alpha: 0.1
          send_every: 10

I hope it helps.
/Mattias

1 Like

Thanks a million Mattias. Sorry for late reply. I will try this, looks like exactly what I was looking for! :slight_smile:

I’m glad I could help.
/Matttias

Thanks again Mattias, finally got to it and it works perfectly! :slight_smile: