RuuviTag battery level and integration to alerts problem

I have several RuuviTag sensors that are at the moment integrated to Home Assistant via hass-ruuvitag.
The sensors are visible having entities for

  • battery voltage
  • humidity
  • temperature

Lately I added battery warnings for other devices via blueprint Low battery level detection & notification for all battery sensors

My problem with the RuuviTag’s is two-fold

  1. Sensor information for battery is milliVolts, not percentage value
  2. As the sensor is an entity instead of a device, there is no device_class (battery) for these sensors

Where I need some assistance is
a) How to create an entity that converts the mV value to %-value. The sensor works, to my understanding, until somewhere 1800 mV and the CR2477 battery has max mV around 3000 mV. So I need some kind of encoding of the mV to % in the ballpark of 1800 mV: 0% - 3000 mV: 100%
b) How to create a device and link it to the sensor so that I’d have the %-value from a) defined as ‘device_class: battery’ enabling the blueprint to work with these sensors too

1 Like

I managed to sort out 2nd problem by inserting these into configuration.yaml

template:
  - sensor:
      - name: "ruuvikitchen.battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: >
          {{ ((sensor.kitchen_battery - 1200) / 20) | round(0, default='none') }}
      - name: "ruuvibedroom.battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: >
          value_template: "{{ ((states('sensor.bedroom_battery') - 1200) / 20) | int }}"

so now I can see entities sensor.ruuvibedroom_battery and sensor.ruuvikitchen_battery both having ‘device_class: battery’

Neither of the state assignations I’ve inserted works as the State (in Developer Tools) is ‘unavailable’. The state setting format is too cryptic for me at least at the moment.

For example current sensor.kitchen_battery is 2985, unit_of_measurement: mV

Got it

template:
  - sensor:
      - name: "ruuvikitchen.battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: "{{ (((states('sensor.kitchen_battery'))|int - 1200) / 20) | round() }}"

CR2477 battery is theoretically 3000 mV but all I’ve seen provide ~3200 mV as full. RuuviTag seems to run all the way until 1200 mV so using that as 0% value.

1 Like

For me, Home Assistant reported voltage in V.
Might be since I’m using esp32 bt as a kind of ble proxy with configuration:

  - platform: ruuvitag
    mac_address: FB:F7:C8:06:XX:XX
    humidity:
      name: "SaunaRuuvi Humidity"
    temperature:
      name: "SaunaRuuvi Temperature"
    pressure:
      name: "SaunaRuuvi Pressure"
    battery_voltage:
      name: "SaunaRuuvi Battery Voltage"

And the percentage works perfectly with:

template:
  - sensor:
      - name: "saunaruuvi.battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: "{{ (((states('sensor.saunaruuvi_battery_voltage'))|int - 1.2) / 0.02) | round() }}"

Kiitos vinkistä ja selvitystyöstä!

this is great, especially with the new Ruuvi integration released today! no more need to do platform: ruuvitag in the esphome yaml. this is what I used so that I could have the names consistent with the other ruuvi entities, while providing another sensor…

template:
  - sensor:
      - name: "Ruuvi 1 - Dining Room Battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: "{{ (((states('sensor.ruuvi_1_dining_room_voltage'))|int - 1200) / 20) | round() }}"
      - name: "Ruuvi 2 - Bedroom Battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: "{{ (((states('sensor.ruuvi_2_bedroom_voltage'))|int - 1200) / 20) | round() }}"
      - name: "Ruuvi 3 - Kitchen Battery"
        unit_of_measurement: "%"
        device_class: battery
        icon: "mdi:battery"
        state: "{{ (((states('sensor.ruuvi_3_kitchen_voltage'))|int - 1200) / 20) | round() }}"

then laid a card out like this…

type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: none
        type: sensor
        entity: sensor.ruuvi_1_dining_room_temperature
        name: Ruuvi 1 Temp
        detail: 1
      - hours_to_show: 24
        graph: none
        type: sensor
        entity: sensor.ruuvi_2_bedroom_humidity
        name: Ruuvi 1 Humidity
        detail: 1
  - type: horizontal-stack
    cards:
      - hours_to_show: 24
        graph: none
        type: sensor
        entity: sensor.ruuvi_1_dining_room_battery
        name: Ruuvi 1 Battery
        detail: 1
        icon: mdi:battery
      - hours_to_show: 24
        graph: none
        type: sensor
        entity: sensor.ruuvi_1_dining_room_signal_strength
        name: Ruuvi 1 Signal
        detail: 1
  - type: history-graph
    title: Dining Room 24 Hour History
    entities:
      - entity: sensor.ruuvi_1_dining_room_temperature
      - entity: sensor.ruuvitag_dining_room_humidity
      - entity: sensor.ruuvi_1_dining_room_voltage
      - entity: sensor.ruuvi_1_dining_room_signal_strength
      - entity: sensor.ruuvi_1_dining_room_pressure
    hours_to_show: 24
    refresh_interval: 0

Looks like one of my Ruuvi’s is showing battery replacement notifcation in Ruuvi Station Android app at 2.25 Volts. Might be worth tuning the formula a bit…

Switching my own values to 1800 and 14.

Also checked that newly installed Varta CR2477 shows 3.20 V on Ruuvi Station app.

Going to run the ‘Keittiö’ unit until it stops to see how low voltage it really works with.

1 Like

Can anyone figure out how this could be configured for HA via templates or blueprints or whatevers so that the values could be dynamically changed in the Home Assistant UI?

Still running on 1.79 mV