sensors/devices.yaml
#
# Blink XT2 cameras signal strength monitoring
#
# This device/bridge reports its RSSI in dBm. The conversion here to percentage
# is highly approximative.
#
# @link https://www.metageek.com/training/resources/wifi-signal-strength-basics.html
# @link https://www.speedguide.net/faq/how-does-rssi-dbm-relate-to-signal-quality-percent-439
# @link https://www.home-assistant.io/integrations/blink/
#
- platform: template
sensors:
front_camera_signal_strength:
friendly_name: "Front Camera Signal Strength"
unit_of_measurement: '%'
icon_template: >-
{% set dbm = state_attr('camera.front', 'wifi_strength') %}
{% if dbm >= -55 %}
mdi:signal-cellular-3
{% elif dbm >= -75 %}
mdi:signal-cellular-2
{% elif dbm >= -85 %}
mdi:signal-cellular-1
{% else %}
mdi:signal-cellular-outline
{% endif %}
value_template: >-
{% set dbm = state_attr('camera.front', 'wifi_strength') %}
{% set scale = (2 * (dbm + 100)) | round %}
{% if scale > 100 %}
{% set scale = 100 %}
{% elif scale < 0 %}
{% set scale = 0 %}
{% endif %}
{{ scale }}
front_camera_wifi_strength:
friendly_name: "Front Camera Wifi Strength"
unit_of_measurement: 'dBm'
device_class: signal_strength
value_template: >-
{{ state_attr('camera.front', 'wifi_strength') }}
#
# UniFi Security Gateway
#
# @see `secrets-dummy.yaml`
#
# @link https://github.com/custom-components/sensor.unifigateway
#
- platform: unifigateway
host: !secret unifi_host
port: !secret unifi_port
username: !secret unifi_username
password: !secret unifi_password
monitored_conditions:
- alerts
- lan
- wan
- wlan
- platform: template
sensors:
unifi_gateway_lan_clients:
friendly_name: "Ethernet Clients"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'icon') }}
value_template: >-
{% set guest = state_attr('sensor.unifi_gateway_lan', 'num_guest') | int %}
{% set iot = state_attr('sensor.unifi_gateway_lan', 'num_iot') | int %}
{% set user = state_attr('sensor.unifi_gateway_lan', 'num_user') | int %}
{{ guest + iot + user }}
unifi_gateway_lan_guests:
friendly_name: "Ethernet Guests"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'icon') }}
value_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'num_guest') }}
unifi_gateway_lan_iots:
friendly_name: "Ethernet IoT"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'icon') }}
value_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'num_iot') }}
unifi_gateway_lan_users:
friendly_name: "Ethernet Users"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'icon') }}
value_template: >-
{{ state_attr('sensor.unifi_gateway_lan', 'num_user') }}
unifi_gateway_wlan_clients:
friendly_name: "Wireless Clients"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'icon') }}
value_template: >-
{% set guest = state_attr('sensor.unifi_gateway_wlan', 'num_guest') | int %}
{% set iot = state_attr('sensor.unifi_gateway_wlan', 'num_iot') | int %}
{% set user = state_attr('sensor.unifi_gateway_wlan', 'num_user') | int %}
{{ guest + iot + user }}
unifi_gateway_wlan_guests:
friendly_name: "Wireless Guests"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'icon') }}
value_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'num_guest') }}
unifi_gateway_wlan_iots:
friendly_name: "Wireless IoT"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'icon') }}
value_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'num_iot') }}
unifi_gateway_wlan_users:
friendly_name: "Wireless Users"
icon_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'icon') }}
value_template: >-
{{ state_attr('sensor.unifi_gateway_wlan', 'num_user') }}
unifi_gateway_processor_use:
friendly_name: "UniFi Gateway Processor Use"
unit_of_measurement: '%'
icon_template: "mdi:chip"
value_template: >-
{{ state_attr('sensor.unifi_gateway_wan', 'gw_system-stats').cpu | int }}
unifi_gateway_memory_use:
friendly_name: "UniFi Gateway Memory Use"
unit_of_measurement: '%'
icon_template: "mdi:memory"
value_template: >-
{{ state_attr('sensor.unifi_gateway_wan', 'gw_system-stats').mem | int }}
wan_ip_address:
friendly_name: "WAN IP Address"
icon_template: "mdi:wan"
value_template: >-
{{ state_attr('sensor.unifi_gateway_wan', 'wan_ip') }}
unifi_uptime:
friendly_name: "UniFi Gateway Uptime"
icon_template: "mdi:av-timer"
value_template: >-
{% set seconds = state_attr('sensor.unifi_gateway_wan', 'gw_system-stats').uptime %}
{% if seconds != 'unknown' %}
{% set seconds = seconds|int %}
{% set days = (seconds / 86400)|int %}
{% set seconds = seconds % 86400 %}
{% set hours = (seconds / 3600)|int %}
{% set seconds = seconds % 3600 %}
{% set minutes = (seconds / 60)|int %}
{% set seconds = seconds % 60 %}
{% if hours == 0 and minutes == 0 %}
{{ seconds }} seconds
{% else %}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{%- endif -%}
{%- if hours > 0 and days < 7 -%}
{%- if days > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if hours == 1 -%}
1 hour
{%- else -%}
{{ hours }} hours
{%- endif -%}
{%- endif -%}
{%- if days == 0 and minutes > 0 -%}
{%- if hours > 0 -%}
{{ ', ' }}{{ minutes }} min
{%- else -%}
{%- if minutes == 1 -%}
1 minute
{%- else -%}
{{ minutes }} minutes
{%- endif -%}
{%- endif -%}
{%- endif -%}
{% endif %}
{% else %}
unknown
{% endif %}
#
# Brother laser printer
#
# Actual integration is performed via the UI (YAML not supported).
#
# The drum reports on its remaining percentage, while the toner also returns
# its print count, allowing for more accurate calculations.
#
# In order to keep configuration and logic separate, values for
# `printer_drum_capacity` and `printer_toner_capacity` are integers set in the
# secrets file.
#
# @see `secrets-dummy.yaml`
#
# @link https://www.home-assistant.io/integrations/brother/
#
- platform: template
sensors:
printer_drum_remaining:
friendly_name: "Drum Remaining"
icon_template: "mdi:printer"
unit_of_measurement: 'pages'
value_template: >-
{% set value = state_attr('sensor.printer_drum', 'remaining_pages') | int(-1) %}
{% if value >= 0 %}
{{ value }}
{% else %}
unknown
{% endif %}
printer_drum_use:
friendly_name: "Drum Use"
icon_template: "mdi:printer"
unit_of_measurement: 'pages'
value_template: >-
{% set value = state_attr('sensor.printer_drum', 'counter') | int(-1) %}
{% if value >= 0 %}
{{ value }}
{% else %}
unknown
{% endif %}
printer_toner_yield:
friendly_name: "Toner Yield"
icon_template: "mdi:printer"
unit_of_measurement: 'pages'
value_template: !secret printer_toner_yield
printer_toner_remaining:
friendly_name: "Toner Remaining"
icon_template: "mdi:printer"
unit_of_measurement: 'pages'
value_template: >-
{% set yield = states('sensor.printer_toner_yield') | int(-1) %}
{% set toner = states('sensor.printer_toner') | int(-1) %}
{% if yield > 0 and toner >= 0 %}
{{ yield - toner }}
{% else %}
unknown
{% endif %}
printer_toner_use:
friendly_name: "Toner Use"
icon_template: "mdi:printer"
unit_of_measurement: 'pages'
value_template: >-
{% set yield = states('sensor.printer_toner_yield') | int(-1) %}
{% set toner = states('sensor.printer_toner') | int(-1) %}
{% if yield > 0 and toner >= 0 %}
{{ (yield * toner / 100) | int }}
{% else %}
unknown
{% endif %}
#
# Toaster oven
#
- platform: template
sensors:
toaster_oven_uptime:
friendly_name: "Toaster Oven Uptime"
icon_template: "mdi:av-timer"
entity_id:
- sensor.time
- switch.toaster_oven
value_template: >-
{% if is_state('switch.toaster_oven', 'on') %}
{% set last_changed = as_timestamp(states.switch.toaster_oven.last_changed) %}
{% set seconds = as_timestamp(now()) - last_changed %}
{% set seconds = seconds|int %}
{% set days = (seconds / 86400)|int %}
{% set seconds = seconds % 86400 %}
{% set hours = (seconds / 3600)|int %}
{% set seconds = seconds % 3600 %}
{% set minutes = (seconds / 60)|int %}
{% set seconds = seconds % 60 %}
{% if hours == 0 and minutes == 0 %}
{{ seconds }} seconds
{% else %}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{%- endif -%}
{%- if hours > 0 and days < 7 -%}
{%- if days > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if hours == 1 -%}
1 hour
{%- else -%}
{{ hours }} hours
{%- endif -%}
{%- endif -%}
{%- if days == 0 and minutes > 0 -%}
{%- if hours > 0 -%}
{{ ', ' }}{{ minutes }} min
{%- else -%}
{%- if minutes == 1 -%}
1 minute
{%- else -%}
{{ minutes }} minutes
{%- endif -%}
{%- endif -%}
{%- endif -%}
{% endif %}
{% endif %}