renemarc/home-assistant-config

View on GitHub
sensors/power.yaml

Summary

Maintainability
Test Coverage
#
# AcuRite battery monitoring
#
# This device only has two power state: `OK` (0) and `low` (1). If no signal is
# received we assume that the battery is dead.
#
# @see /rtl4332mqtt/rtl2mqtt.sh
#
# @link https://www.acurite.com/indoor-temperature-sensor-and-humidity-gauge.html
# @link https://www.home-assistant.io/integrations/sensor.mqtt/
#
- platform: mqtt
  name: "Humidor Multisensor Battery Level"
  unit_of_measurement: '%'
  device_class: battery
  json_attributes_topic: "home/Acurite_tower_sensor/11846"
  json_attributes_template: >-
    {
      "battery_low": "{{ value_json.battery_low }}"
    }
  state_topic: "home/Acurite_tower_sensor/11846"
  value_template: >-
    {% set stale_hours = 12 %}
    {% set last_update = as_timestamp(value_json.time) %}
    {% set battery_low = value_json.battery_low | int %}

    {% if as_timestamp(now()) - last_update > stale_hours*60*60 %}
      0
    {% elif battery_low %}
      10
    {% else %}
      100
    {% endif %}


#
# Blink XT2 cameras battery monitoring
#
# This device only has both a voltage indicator and a battery status. Since I
# do not know the minimum operating voltage, let's simply rely on the 'ok'
# status.
#
# @link https://support.blinkforhome.com/en_us/blink-technical-specifications-By2VzxmUB
# @link https://www.home-assistant.io/integrations/blink/
#
- platform: template
  sensors:
    front_camera_battery_level:
      friendly_name: "Front Camera Battery Level"
      unit_of_measurement: '%'
      device_class: battery
      value_template: >-
        {% set battery = state_attr('camera.front', 'battery') %}

        {% if battery == 'ok' %}
          100
        {% else %}
          10
        {% endif %}


#
# Fully Browser kiosk battery monitoring
#
# Licensed application running in kiosk mode on an Acer B3-A40 Android tablet.
#
# @link https://github.com/daemondazz/homeassistant-displays
#
- platform: template
  sensors:
    kiosk_battery_level:
      friendly_name: "Kiosk Battery Level"
      unit_of_measurement: '%'
      device_class: battery
      value_template: >-
        {% set battery_level = state_attr('display.kiosk', 'battery_level') %}
        {% set kiosk = is_state('binary_sensor.kiosk_status', 'on') %}

        {% if battery_level != None and kiosk %}
          {{ battery_level | round }}
        {% else %}
          unknown
        {% endif %}


#
# Raspberry Pi undervoltage monitoring
#
# @link https://github.com/custom-components/sensor.rpi_power
# @link https://community.home-assistant.io/t/raspberry-pi-power-sensor-updated-2018-07-25/58155/
#
- platform: rpi_power
  text_state: false


#
# ZWave battery monitoring
#
# @link https://aeotec.com/z-wave-door-window-sensor
# @link https://aeotec.com/z-wave-sensor
#
- platform: template
  sensors:
    washroom_multisensor_battery_level:
      friendly_name: "Washroom Multisensor Battery Level"
      unit_of_measurement: '%'
      device_class: battery
      value_template: >-
        {% set batteries_installed = 1 %}
        {% set batteries_max = 2 %}
        {% set battery_level = state_attr('zwave.washroom_multisensor', 'battery_level') %}

        {% if battery_level != None %}
          {% set min = 100 - batteries_installed/batteries_max * 100 %}
          {% if min %}
            {% set battery_level = (battery_level - min) * batteries_max %}
          {% endif %}
          {{ battery_level | round }}
        {% else %}
          unknown
        {% endif %}