Battery percentage for ESP Muse Luxe (ESP32)?

Today I got my ESP Muse Luxe speaker and now that it’s set up I’d love to have a battery level sensor. The thing is that this is my first time using ESPHome and I have no idea about the electronics stuff either :smiley:

What I found is the following config but I’m not sure how to convert this value to a battery level (or if this value is even correct). I found it in the forum for the ESP Muse Luxe and right now it reads about 4 V:

sensor:
 - platform: adc
   pin: GPIO33
   name: ${name} Battery
   icon: "mdi:battery-outline"
   update_interval: 15s
   accuracy_decimals: 3
   attenuation: 11db
   raw: true
   filters:
    - multiply: 0.00173913 # 2300 -> 4, for attenuation 11db, based on Olivier's code
    - exponential_moving_average:
        alpha: 0.2
        send_every: 2
    - delta: 0.002

@andarotajo you can convert any reading and below is a example from V to %. I just used your multiply but not sure if your correct. Then look in calibrate_linear. 4.0V = 100% and I just put in 1.5V = 0%… you will need to adjust these value when you know them. The lambda is just so you only get 0% to 100% and not -5% and 110% as set in your calibrate_linear. You could remove median as it just slows / averages you readings. Example: update_interval: 10s x 30 = 300 seconds or 5 min for every update reading into HA averaging 30 readings.

I don’t know if your starting value is correct that something you will need to test.

sensor:
 - platform: adc
   pin: GPIO33
   name: ${name} Battery
   icon: "mdi:battery-outline"
   update_interval: 15s
   accuracy_decimals: 3
   attenuation: 11db
   raw: true
   filters:
    - multiply: 0.00173913 # 2300 -> 4, for attenuation 11db, based on Olivier's code
    - exponential_moving_average:
        alpha: 0.2
        send_every: 2
    - delta: 0.002

  - platform: adc
    pin: GPIO33
    name: "Battery Percentage"
    update_interval: 10s
    unit_of_measurement: "%"
    icon: "mdi:battery"
    accuracy_decimals: 0
    attenuation: 11db
    filters:
    - multiply: 0.00173913 # 2300 -> 4, for attenuation 11db, based on Olivier's code
    - median:
        window_size: 30
        send_every: 30
        send_first_at: 3
    - calibrate_linear: 
          - 1.50 -> 0.0 
          - 4.00 -> 100.0
    - lambda: |
        if (x < 0.0) return 0.0;
        else if (x > 100.0) return 100.0;
        else return (x);

Thanks! I’ll just try it out at some point as I’m currently testing another firmware for the speaker but that’s helpful nevertheless!