Getting InfluxDB-sensor with battery level of HASSIO-hostlaptop

Just finished my quest to get the battery-level of my HASSIO ubuntu-laptop available in HASSIO for automating the charging-cycle. The idea I have is to keep the battery-level between 80% and 20%, to minimize wear from charging/decharging. So I need the battery-level to get an automation switching power on when the level reaches 20% and of when the battery is charged to 80%.

Because the examples in the InfluxDB-sensor documentation where not all that clear te me, I spend the last few days struggling to get this working.
This is how I finally got it working:

Installed the Glances-addon

Installed the InfluxDB-addon

See the excellent youtube video where @franck explains how to do this.

Then make a sensor with platform influxdb:

platform: influxdb
host: a0d7b954-influxdb
port: 8086
username: homeassistant
password: homeassistant
queries:
  - name: hp_battery
    value_template: '{{ value | round(0) }}'
    group_function: last
    where: 'time >= now() - 30s'
    measurement: '"localhost.sensors"'
    field: Battery.value
    database: glances

And go, go, go!

1 Like

That was very helpful. Many thanks for sharing

Hello @jpduhen , I try your example, but I get no Battery.value in my glances database.
Have you done something special to get this ?
Are you running HAOS in a VM ?

I know this topic is very old but i try…

@jmcollin I’ll look at it when I get home.

@jmcollin

If I look at Glances, all the way down at Sensors you see the Battery %. InfluxDB sensor is called ‘Battery.value’ and it’s measurement is found at ‘localhost.sensors’.

I use no VM, I run Docker-containers in a Linux Debian 11 installation on my laptop, see:
Home Assistant supervised on Debian 11

Hope this helps…

1 Like

Thank you. The problem that i was running HAOS in a VM. Removes the VM and I see the battery percent also.

In my case your syntax don’t work out of the box. I should use this syntax:

    - name: last_ha_battery_level
      unit_of_measurement: "%"
      value_template: '{{ value | round(0) }}'
      group_function: last
      where: 'time >= now() - 15m AND "label"=''Battery'''
      measurement: '"localhost.sensors"'
      field: value
      database: glancesdb

Don’t know exactly why but I hope this will helps someone else.

JM.

@jmcollin Nice to share your solution, sure someone will be looking for this!