Track personal bottle refills on the health dashboard

master
Carlo Costanzo 1 day ago
parent 511b83fc71
commit 66a98d065d

@ -0,0 +1,74 @@
######################################################################
# @CCOSTAN - Follow Me on X
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Hydration - Attribute a shared cooler tag or manual refill to its owner.
# Related Issue: 2033
######################################################################
blueprint:
name: Personal water bottle refill
description: Count one full bottle from the registered phone or the owner's dashboard button. Repeated entries within 30 seconds count once per person.
domain: automation
source_url: https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/config/blueprints/automation/bearstone/water_bottle_refill.yaml
input:
tag_id:
name: Cooler tag ID
selector:
text:
scanner:
name: Phone registered with the Companion App
selector:
entity:
filter:
- domain: device_tracker
integration: mobile_app
person:
name: Person linked to the dashboard account
selector:
entity:
filter:
- domain: person
manual_button:
name: Manual refill button
selector:
entity:
filter:
- domain: input_button
counter:
name: Lifetime refill counter
selector:
entity:
filter:
- domain: counter
variables:
scanner: !input scanner
person: !input person
triggers:
- trigger: tag
id: sticker
tag_id: !input tag_id
- trigger: state
id: manual
entity_id: !input manual_button
to: null
conditions:
- condition: template
value_template: >-
{% if trigger.id == 'sticker' %}
{% set phone = device_id(scanner) %}
{{ phone is string and trigger.event.data.get('device_id') == phone }}
{% else %}
{% set account = state_attr(person, 'user_id') %}
{{ account is string and trigger.from_state is not none and trigger.to_state is not none
and trigger.to_state.context.user_id == account }}
{% endif %}
- condition: template
value_template: >-
{{ as_timestamp(now()) - as_timestamp(this.attributes.get('last_triggered'), 0) >= 30 }}
actions:
- action: counter.increment
target:
entity_id: !input counter
mode: single

@ -4,6 +4,7 @@
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Overview Partial - Health
# Related Issue: 2033
# Current SleepIQ state, Joanna achievements and steps, paired nightly trends, and native bed controls.
# -------------------------------------------------------------------
# Notes: Daily maximum statistics suppress SleepIQ's between-session zero states.
@ -25,87 +26,145 @@
columns: full
layout_type: custom:grid-layout
layout:
grid-template-columns: repeat(6, minmax(0, 1fr))
grid-template-columns: repeat(2, minmax(0, 1fr))
grid-auto-flow: row
grid-auto-rows: min-content
grid-gap: 12px
margin: 0
mediaquery:
"(max-width: 900px)":
grid-template-columns: repeat(2, minmax(0, 1fr))
grid-template-columns: minmax(0, 1fr)
cards:
- type: custom:button-card
template: bearstone_health_kpi
entity: binary_sensor.sleepnumber_carlo_carlo_is_in_bed
name: Carlo
icon: mdi:bed
state_display: >
[[[
return entity?.state === 'on' ? 'IN BED' : 'OUT OF BED';
]]]
- type: grid
columns: 3
square: false
cards:
- type: custom:button-card
template: bearstone_health_kpi
entity: binary_sensor.sleepnumber_carlo_carlo_is_in_bed
name: Carlo
icon: mdi:bed
state_display: >
[[[
return entity?.state === 'on' ? 'IN BED' : 'OUT OF BED';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: number.sleepnumber_carlo_carlo_firmness
name: Carlo Firmness
icon: mdi:bed-outline
state_display: >
[[[
const value = Number(entity?.state);
return Number.isFinite(value) ? value.toFixed(0) : 'NO DATA';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: number.sleepnumber_carlo_carlo_firmness
name: Carlo Firmness
icon: mdi:bed-outline
state_display: >
[[[
const value = Number(entity?.state);
return Number.isFinite(value) ? value.toFixed(0) : 'NO DATA';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.sleepnumber_carlo_carlo_sleep_duration
name: Carlo Slept
icon: mdi:timer-sand
state_display: >
[[[
const value = Number(entity?.state);
const inBed = states['binary_sensor.sleepnumber_carlo_carlo_is_in_bed']?.state === 'on';
if (inBed && (!Number.isFinite(value) || value <= 0)) return 'IN PROGRESS';
if (!Number.isFinite(value)) return 'NO DATA';
return `${Math.floor(value)}h ${Math.round((value % 1) * 60)}m`;
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.sleepnumber_carlo_carlo_sleep_duration
name: Carlo Slept
icon: mdi:timer-sand
state_display: >
[[[
const value = Number(entity?.state);
const inBed = states['binary_sensor.sleepnumber_carlo_carlo_is_in_bed']?.state === 'on';
if (inBed && (!Number.isFinite(value) || value <= 0)) return 'IN PROGRESS';
if (!Number.isFinite(value)) return 'NO DATA';
return `${Math.floor(value)}h ${Math.round((value % 1) * 60)}m`;
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: binary_sensor.sleepnumber_carlo_stacey_is_in_bed
name: Stacey
icon: mdi:bed-double-outline
state_display: >
[[[
return entity?.state === 'on' ? 'IN BED' : 'OUT OF BED';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.carlo_water_refilled_total
name: Water Total
icon: mdi:cup-water
hold_action:
action: call-service
service: input_button.press
target:
entity_id: input_button.carlo_water_bottle_refill
confirmation:
text: Log a full 40 fl oz refill for Carlo?
- type: custom:button-card
template: bearstone_health_kpi
entity: number.sleepnumber_carlo_stacey_firmness
name: Stacey Firmness
icon: mdi:bed-outline
state_display: >
[[[
const value = Number(entity?.state);
return Number.isFinite(value) ? value.toFixed(0) : 'NO DATA';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.carlo_water_refilled_today
name: Water Today
icon: mdi:cup-water
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.sleepnumber_carlo_stacey_sleep_duration
name: Stacey Slept
icon: mdi:timer-sand
state_display: >
[[[
const value = Number(entity?.state);
const inBed = states['binary_sensor.sleepnumber_carlo_stacey_is_in_bed']?.state === 'on';
if (inBed && (!Number.isFinite(value) || value <= 0)) return 'IN PROGRESS';
if (!Number.isFinite(value)) return 'NO DATA';
return `${Math.floor(value)}h ${Math.round((value % 1) * 60)}m`;
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.carlo_water_refilled_this_week
name: Water This Week
icon: mdi:cup-water
- type: grid
columns: 3
square: false
cards:
- type: custom:button-card
template: bearstone_health_kpi
entity: binary_sensor.sleepnumber_carlo_stacey_is_in_bed
name: Stacey
icon: mdi:bed-double-outline
state_display: >
[[[
return entity?.state === 'on' ? 'IN BED' : 'OUT OF BED';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: number.sleepnumber_carlo_stacey_firmness
name: Stacey Firmness
icon: mdi:bed-outline
state_display: >
[[[
const value = Number(entity?.state);
return Number.isFinite(value) ? value.toFixed(0) : 'NO DATA';
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.sleepnumber_carlo_stacey_sleep_duration
name: Stacey Slept
icon: mdi:timer-sand
state_display: >
[[[
const value = Number(entity?.state);
const inBed = states['binary_sensor.sleepnumber_carlo_stacey_is_in_bed']?.state === 'on';
if (inBed && (!Number.isFinite(value) || value <= 0)) return 'IN PROGRESS';
if (!Number.isFinite(value)) return 'NO DATA';
return `${Math.floor(value)}h ${Math.round((value % 1) * 60)}m`;
]]]
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.stacey_water_refilled_total
name: Water Total
icon: mdi:cup-water
hold_action:
action: call-service
service: input_button.press
target:
entity_id: input_button.stacey_water_bottle_refill
confirmation:
text: Log a full 40 fl oz refill for Stacey?
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.stacey_water_refilled_today
name: Water Today
icon: mdi:cup-water
- type: custom:button-card
template: bearstone_health_kpi
entity: sensor.stacey_water_refilled_this_week
name: Water This Week
icon: mdi:cup-water
# -------------------------------------------------------------------
# HealthKit step trends
# Activity trends
# -------------------------------------------------------------------
- type: grid
column_span: 4
@ -180,7 +239,6 @@
return `28d ${value('prior_28d_average', 'prior_28d_samples', 28)} · 90d ${value('prior_90d_average', 'prior_90d_samples', 90)}`;
]]]
# -------------------------------------------------------------------
# Fourteen-night paired trends
# -------------------------------------------------------------------

@ -4,6 +4,7 @@
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Overview View - health
# Related Issue: 2033
# SleepIQ and Joanna health insights for Carlo and Stacey.
# -------------------------------------------------------------------
# Related Issue: 1584

@ -0,0 +1,105 @@
######################################################################
# @CCOSTAN - Follow Me on X
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Hydration - Record each person's full water bottles at refill time.
# Related Issue: 2033
# -------------------------------------------------------------------
# Each accepted scan represents one full 40 US fl oz bottle at refill time.
# Overview Health uses sensor.carlo_water_refilled_today, sensor.carlo_water_refilled_this_week,
# sensor.stacey_water_refilled_today and sensor.stacey_water_refilled_this_week.
######################################################################
counter:
carlo_water_bottle_refills:
name: Carlo Water Bottle Refills
icon: mdi:cup-water
restore: true
stacey_water_bottle_refills:
name: Stacey Water Bottle Refills
icon: mdi:cup-water
restore: true
input_button:
carlo_water_bottle_refill:
name: Log Carlo Water Bottle Refill
icon: mdi:cup-water
stacey_water_bottle_refill:
name: Log Stacey Water Bottle Refill
icon: mdi:cup-water
template:
- variables:
bottle_capacity_fl_oz: 40
sensor:
- name: Carlo Water Refilled Total
unique_id: carlo_water_refilled_total
unit_of_measurement: "fl oz"
state_class: total_increasing
icon: mdi:cup-water
availability: "{{ is_number(states('counter.carlo_water_bottle_refills')) }}"
state: "{{ states('counter.carlo_water_bottle_refills') | int(0) * bottle_capacity_fl_oz }}"
attributes:
bottle_capacity_fl_oz: "{{ bottle_capacity_fl_oz }}"
last_refill_at: "{{ state_attr('automation.carlo_count_water_bottle_refill', 'last_triggered') }}"
- name: Stacey Water Refilled Total
unique_id: stacey_water_refilled_total
unit_of_measurement: "fl oz"
state_class: total_increasing
icon: mdi:cup-water
availability: "{{ is_number(states('counter.stacey_water_bottle_refills')) }}"
state: "{{ states('counter.stacey_water_bottle_refills') | int(0) * bottle_capacity_fl_oz }}"
attributes:
bottle_capacity_fl_oz: "{{ bottle_capacity_fl_oz }}"
last_refill_at: "{{ state_attr('automation.stacey_count_water_bottle_refill', 'last_triggered') }}"
utility_meter:
carlo_water_refilled_today:
name: Carlo Water Refilled Today
unique_id: carlo_water_refilled_today
source: sensor.carlo_water_refilled_total
cycle: daily
periodically_resetting: false
carlo_water_refilled_this_week:
name: Carlo Water Refilled This Week
unique_id: carlo_water_refilled_this_week
source: sensor.carlo_water_refilled_total
cycle: weekly
periodically_resetting: false
stacey_water_refilled_today:
name: Stacey Water Refilled Today
unique_id: stacey_water_refilled_today
source: sensor.stacey_water_refilled_total
cycle: daily
periodically_resetting: false
stacey_water_refilled_this_week:
name: Stacey Water Refilled This Week
unique_id: stacey_water_refilled_this_week
source: sensor.stacey_water_refilled_total
cycle: weekly
periodically_resetting: false
automation:
- id: carlo_count_water_bottle_refill
alias: Carlo Count Water Bottle Refill
use_blueprint:
path: bearstone/water_bottle_refill.yaml
input:
tag_id: &cooler_tag 48c1e7b5-bd08-4629-b649-f4ba9f994971
scanner: device_tracker.carlo_maxpro
person: person.carlo
manual_button: input_button.carlo_water_bottle_refill
counter: counter.carlo_water_bottle_refills
- id: stacey_count_water_bottle_refill
alias: Stacey Count Water Bottle Refill
use_blueprint:
path: bearstone/water_bottle_refill.yaml
input:
tag_id: *cooler_tag
scanner: device_tracker.stacey_iphone11
person: person.stacey
manual_button: input_button.stacey_water_bottle_refill
counter: counter.stacey_water_bottle_refills
Loading…
Cancel
Save

Powered by TurnKey Linux.