various tidyups

This commit is contained in:
zorruno
2026-08-30 15:35:24 +12:00
parent bce8abe48c
commit d81deae3be
5 changed files with 214 additions and 33 deletions
+84 -24
View File
@@ -1,8 +1,10 @@
#:########################################################################################:#
# PACKAGE: Fridge and Freezer Monitoring
# FILE: packages/fridge_freezer_monitoring.yaml
# VERSION: v1.10.0 2026-08-29
# - Adds Downstairs Freezer temperature, battery, door, humidity, and shared
# VERSION: v1.11.0 2026-08-30
# - Moves Main Kitchen Fridge temperature, humidity, and battery monitoring to
# X65TS and adds X64LS illuminance-based door monitoring.
# - v1.10.0 2026-08-29: Adds Downstairs Freezer temperature, battery, door, humidity, and shared
# Downstairs Fridge/Freezer plug monitoring.
# - Uses a four-hour sustained low-draw power-loss rule for all monitored
# fridges and freezers, including the shared Drinks Fridge/Freezer plug.
@@ -38,7 +40,7 @@
# - Measures the temperature change rate over a smoothed 30-minute window.
# - Requires an issue condition to persist for one minute, except Main Kitchen
# Fridge low-power draw, which persists for five minutes.
# - Treats the Drinks and Downstairs Fridges as open at 10 lx or higher. An
# - Treats the Main Kitchen, Drinks, and Downstairs Fridges as open at 10 lx or higher. An
# open door is an issue after seven minutes, while temperature alerting
# stays deferred through a 15-minute post-close recovery window.
# - Exposes one issue binary sensor per appliance and one summary sensor.
@@ -51,8 +53,8 @@
# - Main Fridge power below 1 W is treated as loss only after five minutes to
# avoid normal compressor-off periods; unplugged or unavailable monitoring
# remains an issue after one minute.
# - Main Fridge temperature is adjusted by -0.84 C to match the reference
# thermometer.
# - Main Fridge X65TS temperature is adjusted by -0.84 C to match the
# reference thermometer.
# - Wine-fridge ESPHome telemetry is intentionally excluded.
#:########################################################################################:#
# DEPENDENCIES:
@@ -68,6 +70,7 @@
# - sensor.drinks_fridge_light_sensor_x35ls_illuminance
# - sensor.downstairs_fridge_light_sensor_x58ls_illuminance
# - sensor.downstairs_freezer_light_sensor_x61ls_illuminance
# - sensor.main_kitchen_fridge_light_sensor_x64ls_illuminance
#:########################################################################################:#
sensor:
@@ -293,6 +296,27 @@ template:
# DOOR DETECTION
#:######################################################################################:#
- binary_sensor:
- name: "Main Kitchen Fridge Door Open"
unique_id: main_kitchen_fridge_door_open
device_class: door
state: >-
{{
has_value('sensor.main_kitchen_fridge_light_sensor_x64ls_illuminance')
and (states('sensor.main_kitchen_fridge_light_sensor_x64ls_illuminance') | float(0)) >= 10
}}
# Retain the grace period after closure so the fridge can start cooling.
- name: "Main Kitchen Fridge Temperature Recovery Grace"
unique_id: main_kitchen_fridge_temperature_recovery_grace
delay_off: "00:15:00"
state: "{{ is_state('binary_sensor.main_kitchen_fridge_door_open', 'on') }}"
- name: "Main Kitchen Fridge Door Open Too Long"
unique_id: main_kitchen_fridge_door_open_too_long
device_class: problem
delay_on: "00:07:00"
state: "{{ is_state('binary_sensor.main_kitchen_fridge_door_open', 'on') }}"
- name: "Drinks Fridge Door Open"
unique_id: drinks_fridge_door_open
device_class: door
@@ -418,15 +442,21 @@ template:
delay_on: "00:01:00"
state: >-
{% set temperature_missing = not has_value('sensor.main_kitchen_fridge_temperature_calibrated') %}
{% set battery_missing = not has_value('sensor.unk_manufacturer_unk_model_battery') %}
{% set battery_missing = not has_value('sensor.main_kitchen_fridge_temperature_x65ts_battery') %}
{% set illuminance_missing = not has_value('sensor.main_kitchen_fridge_light_sensor_x64ls_illuminance') %}
{% set power_missing = not has_value('sensor.upstairs_fridge_power_x31pp_power') %}
{% set percentile = states('sensor.main_kitchen_fridge_temperature_95th_percentile_7_days') | float(none) %}
{% set threshold = [10, percentile + 0.5] | min if percentile is not none else 10 %}
{{
temperature_missing
or battery_missing
or (states('sensor.unk_manufacturer_unk_model_battery') | float(-1)) <= 20
or (not temperature_missing and (states('sensor.main_kitchen_fridge_temperature_calibrated') | float(0)) > threshold)
or illuminance_missing
or (states('sensor.main_kitchen_fridge_temperature_x65ts_battery') | float(-1)) <= 20
or is_state('binary_sensor.main_kitchen_fridge_door_open_too_long', 'on')
or (
not temperature_missing
and not is_state('binary_sensor.main_kitchen_fridge_temperature_recovery_grace', 'on')
and (states('sensor.main_kitchen_fridge_temperature_calibrated') | float(0)) > threshold
)
or states('switch.upstairs_fridge_power_x31pp') != 'on'
or power_missing
or is_state('binary_sensor.main_kitchen_fridge_power_draw_lost', 'on')
@@ -436,14 +466,18 @@ template:
issues: >-
{% set ns = namespace(items=[]) %}
{% set temperature_missing = not has_value('sensor.main_kitchen_fridge_temperature_calibrated') %}
{% set battery_missing = not has_value('sensor.unk_manufacturer_unk_model_battery') %}
{% set battery_missing = not has_value('sensor.main_kitchen_fridge_temperature_x65ts_battery') %}
{% set illuminance_missing = not has_value('sensor.main_kitchen_fridge_light_sensor_x64ls_illuminance') %}
{% set power_missing = not has_value('sensor.upstairs_fridge_power_x31pp_power') %}
{% set percentile = states('sensor.main_kitchen_fridge_temperature_95th_percentile_7_days') | float(none) %}
{% set threshold = [10, percentile + 0.5] | min if percentile is not none else 10 %}
{% if temperature_missing or battery_missing %}
{% set ns.items = ns.items + ['Monitor offline'] %}
{% if temperature_missing %}
{% set ns.items = ns.items + ['Temperature monitor unavailable'] %}
{% endif %}
{% if not battery_missing and (states('sensor.unk_manufacturer_unk_model_battery') | float(-1)) <= 20 %}
{% if illuminance_missing %}
{% set ns.items = ns.items + ['Door monitor unavailable'] %}
{% endif %}
{% if not battery_missing and (states('sensor.main_kitchen_fridge_temperature_x65ts_battery') | float(-1)) <= 20 %}
{% set ns.items = ns.items + ['Low monitor battery'] %}
{% endif %}
{% if states('switch.upstairs_fridge_power_x31pp') in ['unknown', 'unavailable'] or power_missing %}
@@ -453,7 +487,11 @@ template:
{% elif is_state('binary_sensor.main_kitchen_fridge_power_draw_lost', 'on') %}
{% set ns.items = ns.items + ['Power lost - no power draw'] %}
{% endif %}
{% if not temperature_missing and (states('sensor.main_kitchen_fridge_temperature_calibrated') | float(0)) > threshold %}
{% if is_state('binary_sensor.main_kitchen_fridge_door_open_too_long', 'on') %}
{% set ns.items = ns.items + ['Door open too long'] %}
{% elif not temperature_missing and is_state('binary_sensor.main_kitchen_fridge_temperature_recovery_grace', 'on') %}
{% set ns.items = ns.items + ['Temperature alert delayed - door recently open'] %}
{% elif not temperature_missing and (states('sensor.main_kitchen_fridge_temperature_calibrated') | float(0)) > threshold %}
{% if (states('sensor.main_kitchen_fridge_temperature_change_rate') | float(0)) >= 2 %}
{% set ns.items = ns.items + ['Warming rapidly - possible open door'] %}
{% else %}
@@ -467,8 +505,11 @@ template:
{% set percentile = states('sensor.main_kitchen_fridge_temperature_95th_percentile_7_days') | float(none) %}
{{ [10, percentile + 0.5] | min if percentile is not none else 10 }}
change_rate: "{{ states('sensor.main_kitchen_fridge_temperature_change_rate') }}"
battery: "{{ states('sensor.unk_manufacturer_unk_model_battery') }}"
humidity: "{{ states('sensor.main_kitchen_fridge_temperature_x65ts_humidity') }}"
battery: "{{ states('sensor.main_kitchen_fridge_temperature_x65ts_battery') }}"
power: "{{ states('sensor.upstairs_fridge_power_x31pp_power') }}"
door_open: "{{ is_state('binary_sensor.main_kitchen_fridge_door_open', 'on') }}"
illuminance: "{{ states('sensor.main_kitchen_fridge_light_sensor_x64ls_illuminance') }}"
- name: "Drinks Fridge Issue"
unique_id: drinks_fridge_issue
@@ -477,12 +518,13 @@ template:
state: >-
{% set temperature_missing = not has_value('sensor.drinks_fridge_environment_lcd_btt01_temperature') %}
{% set battery_missing = not has_value('sensor.drinks_fridge_environment_lcd_btt01_battery') %}
{% set illuminance_missing = not has_value('sensor.drinks_fridge_light_sensor_x35ls_illuminance') %}
{% set power_missing = not has_value('sensor.drinks_fridge_power_x59pm_power') %}
{% set percentile = states('sensor.drinks_fridge_temperature_95th_percentile_7_days') | float(none) %}
{% set threshold = [10, percentile + 3] | min if percentile is not none else 10 %}
{{
temperature_missing
or battery_missing
or illuminance_missing
or (states('sensor.drinks_fridge_environment_lcd_btt01_battery') | float(-1)) <= 20
or states('switch.drinks_fridge_power_x59pm') != 'on'
or power_missing
@@ -500,11 +542,15 @@ template:
{% set ns = namespace(items=[]) %}
{% set temperature_missing = not has_value('sensor.drinks_fridge_environment_lcd_btt01_temperature') %}
{% set battery_missing = not has_value('sensor.drinks_fridge_environment_lcd_btt01_battery') %}
{% set illuminance_missing = not has_value('sensor.drinks_fridge_light_sensor_x35ls_illuminance') %}
{% set power_missing = not has_value('sensor.drinks_fridge_power_x59pm_power') %}
{% set percentile = states('sensor.drinks_fridge_temperature_95th_percentile_7_days') | float(none) %}
{% set threshold = [10, percentile + 3] | min if percentile is not none else 10 %}
{% if temperature_missing or battery_missing %}
{% set ns.items = ns.items + ['Monitor offline'] %}
{% if temperature_missing %}
{% set ns.items = ns.items + ['Temperature monitor unavailable'] %}
{% endif %}
{% if illuminance_missing %}
{% set ns.items = ns.items + ['Door monitor unavailable'] %}
{% endif %}
{% if not battery_missing and (states('sensor.drinks_fridge_environment_lcd_btt01_battery') | float(-1)) <= 20 %}
{% set ns.items = ns.items + ['Low monitor battery'] %}
@@ -591,12 +637,13 @@ template:
state: >-
{% set temperature_missing = not has_value('sensor.downstairs_fridge_temperature_x43ts_temperature') %}
{% set battery_missing = not has_value('sensor.downstairs_fridge_temperature_x43ts_battery') %}
{% set illuminance_missing = not has_value('sensor.downstairs_fridge_light_sensor_x58ls_illuminance') %}
{% set power_missing = not has_value('sensor.downstairs_fridge_power_x41pp_power') %}
{% set percentile = states('sensor.downstairs_fridge_temperature_95th_percentile_7_days') | float(none) %}
{% set threshold = [10, percentile + 0.5] | min if percentile is not none else 10 %}
{{
temperature_missing
or battery_missing
or illuminance_missing
or (states('sensor.downstairs_fridge_temperature_x43ts_battery') | float(-1)) <= 20
or is_state('binary_sensor.downstairs_fridge_door_open_too_long', 'on')
or (
@@ -614,11 +661,15 @@ template:
{% set ns = namespace(items=[]) %}
{% set temperature_missing = not has_value('sensor.downstairs_fridge_temperature_x43ts_temperature') %}
{% set battery_missing = not has_value('sensor.downstairs_fridge_temperature_x43ts_battery') %}
{% set illuminance_missing = not has_value('sensor.downstairs_fridge_light_sensor_x58ls_illuminance') %}
{% set power_missing = not has_value('sensor.downstairs_fridge_power_x41pp_power') %}
{% set percentile = states('sensor.downstairs_fridge_temperature_95th_percentile_7_days') | float(none) %}
{% set threshold = [10, percentile + 0.5] | min if percentile is not none else 10 %}
{% if temperature_missing or battery_missing %}
{% set ns.items = ns.items + ['Monitor offline'] %}
{% if temperature_missing %}
{% set ns.items = ns.items + ['Temperature monitor unavailable'] %}
{% endif %}
{% if illuminance_missing %}
{% set ns.items = ns.items + ['Door monitor unavailable'] %}
{% endif %}
{% if not battery_missing and (states('sensor.downstairs_fridge_temperature_x43ts_battery') | float(-1)) <= 20 %}
{% set ns.items = ns.items + ['Low monitor battery'] %}
@@ -850,16 +901,21 @@ template:
state: >-
{{
'Issue'
if is_state('binary_sensor.drinks_fridge_door_open_too_long', 'on')
if is_state('binary_sensor.main_kitchen_fridge_door_open_too_long', 'on')
or is_state('binary_sensor.drinks_fridge_door_open_too_long', 'on')
or is_state('binary_sensor.downstairs_fridge_door_open_too_long', 'on')
or is_state('binary_sensor.downstairs_freezer_door_open_too_long', 'on')
else 'Open'
if is_state('binary_sensor.drinks_fridge_door_open', 'on')
if is_state('binary_sensor.main_kitchen_fridge_door_open', 'on')
or is_state('binary_sensor.drinks_fridge_door_open', 'on')
or is_state('binary_sensor.downstairs_fridge_door_open', 'on')
or is_state('binary_sensor.downstairs_freezer_door_open', 'on')
else 'Issue'
if expand(
'binary_sensor.main_kitchen_fridge_issue',
'binary_sensor.drinks_fridge_issue',
'binary_sensor.downstairs_fridge_issue',
'binary_sensor.downstairs_freezer_issue',
'binary_sensor.wine_fridge_issue',
'binary_sensor.drinks_freezer_issue',
'binary_sensor.vertical_freezer_issue'
@@ -876,6 +932,7 @@ template:
'binary_sensor.main_kitchen_fridge_issue',
'binary_sensor.drinks_fridge_issue',
'binary_sensor.downstairs_fridge_issue',
'binary_sensor.downstairs_freezer_issue',
'binary_sensor.wine_fridge_issue',
'binary_sensor.drinks_freezer_issue',
'binary_sensor.vertical_freezer_issue'
@@ -887,8 +944,10 @@ template:
open_count: >-
{{
[
is_state('binary_sensor.main_kitchen_fridge_door_open', 'on'),
is_state('binary_sensor.drinks_fridge_door_open', 'on'),
is_state('binary_sensor.downstairs_fridge_door_open', 'on')
is_state('binary_sensor.downstairs_fridge_door_open', 'on'),
is_state('binary_sensor.downstairs_freezer_door_open', 'on')
]
| select
| list
@@ -900,6 +959,7 @@ template:
'binary_sensor.main_kitchen_fridge_issue',
'binary_sensor.drinks_fridge_issue',
'binary_sensor.downstairs_fridge_issue',
'binary_sensor.downstairs_freezer_issue',
'binary_sensor.wine_fridge_issue',
'binary_sensor.drinks_freezer_issue',
'binary_sensor.vertical_freezer_issue'