diff --git a/docs/changelog.md b/docs/changelog.md index 125c0259..63e93d15 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,31 @@ docstring gives: it is a record, not a claim about now. ## 2026-11-18 +- **The wall's context card gets its sources.** The third of the wall's + five steps. Five new packages, each a `sensor.wall_*` behind its own + `/api/ha/` handle, fill the card by precedence: + - `wall_commute.yaml`: the live drive from home to the next event within + three hours whose location looks like a place, through + `waze_travel_time.get_travel_times`. It shows from an hour before it is + time to leave, with five minutes to get out of the door. There is no fixed + commute, so the calendar is the destination: only calendars labelled + `wall_commute`, and none until one is. This is the first time the wall + sends anything out of the house: that one location, to Waze. + - `wall_shabbat.yaml`: candles, havdalah, parsha and Hebrew date from the + Jewish Calendar integration, from six hours before candle lighting. + - `wall_trash.yaml`: the next pickup from three helpers, from 16:00 the + evening before. It needs no integration. + - `wall_deliveries.yaml`: 17TRACK packages delivered today, ready for + pickup or undelivered, by their labels, never their numbers. + - `wall_todo.yaml`: the open items of the lists labelled `wall_todo`, the + card's default before the Hebrew word. + + Each stays unavailable, and its card hidden, until its integration or + helper is set up in the UI; none of them is yet. `docs/security.md` had + said the wall shows two days of the schedule. It has shown seven since the + first step, and now says so. I previewed each card at 1920x1080 against + stubbed answers, alone and all at once. None of them has been run against + the real Home Assistant. - **`fenrir`'s leftover tool images are gone, and its runbook installs the weekly image prune.** "`fenrir`'s re-check with sudo finds nothing the audit could not see", below, left seven lint and validate images, about 928 MB, diff --git a/docs/security.md b/docs/security.md index 8ab1c689..d2405db0 100644 --- a/docs/security.md +++ b/docs/security.md @@ -1145,11 +1145,13 @@ from Home Assistant with *not enough permissions*. firing alerts, per-host CPU, SNMP reachability, WAN traffic and latency, the UPS and `heimdall`'s temperature. That is less than the Homelab page already shows, and the page and the Pi hold no credential. - **Its household half reads thirteen Home Assistant entities the same way.** + **Its household half reads eighteen Home Assistant entities the same way.** Each `/api/ha/NAME` is one `GET /api/states/` written in the Caddyfile: the weather, today's forecast, the alarm's mode, four door contacts, two window contacts, the office lights, the thermostat, the - Litter-Robot's summary, and `sensor.wall_today`, + Litter-Robot's summary, the next drive, the Shabbat times, the open to-do + items, the next trash pickup, the packages to collect by their own labels, + and `sensor.wall_today`, which holds the next seven days' calendar events. Caddy adds the token of HA's non-admin `wall` user. Home Assistant has no read-only role, so that token could call services, the alarm's included. It is read-only only because it lives in @@ -1157,10 +1159,17 @@ from Home Assistant with *not enough permissions*. residual is that whoever can read that container's environment holds a token that can operate the house. They would already be root on the host that runs Home Assistant. Anything that reaches `trinity:443` can read - whether the doors are open, whether the alarm is set, and the family's - schedule for two days: each event's title, time and location. That is the - same as the Home Assistant app shows to the household, without its login. - The calendars' names, descriptions and attendees are not passed on. + whether the doors are open, whether the alarm is set, the family's + schedule for the coming week (each event's title, time and location), the + open to-do items, and the labels of packages waiting to be collected. That + is the same as the Home Assistant app shows to the household, without its + login. The calendars' names, descriptions and attendees are not passed on, + nor are tracking numbers. One thing leaves the house for the wall: the + location of the next event with an address, which + `home-assistant/packages/wall_commute.yaml` sends to Waze to be routed from + the home zone. It reads only the calendars labelled `wall_commute`, and none + when no calendar carries that label, so a calendar is routed only once + someone chooses it. - `snmp-exporter` is never published to a host interface — it is reachable only on the compose network. - Alertmanager binds to `127.0.0.1` only. It is unauthenticated, and a silence diff --git a/stacks/sensitive/Caddyfile b/stacks/sensitive/Caddyfile index 21083169..3247283b 100644 --- a/stacks/sensitive/Caddyfile +++ b/stacks/sensitive/Caddyfile @@ -456,6 +456,39 @@ wall.matrix.elysium { import wall_ha } + # The context card's sources, each a template entity in its own + # home-assistant/packages/wall_*.yaml, each unavailable until its + # integration or helper is set up, which hides its card: + # commute the drive to the next event with an address (Waze) + # shabbat candles, havdalah, parsha (Jewish Calendar) + # todo the open items of the lists labelled wall_todo + # trash the next pickup, from three helpers + # deliveries packages to go and get (17TRACK) + handle /api/ha/commute { + rewrite * /api/states/sensor.wall_commute? + import wall_ha + } + + handle /api/ha/shabbat { + rewrite * /api/states/sensor.wall_shabbat? + import wall_ha + } + + handle /api/ha/todo { + rewrite * /api/states/sensor.wall_todo? + import wall_ha + } + + handle /api/ha/trash { + rewrite * /api/states/sensor.wall_trash? + import wall_ha + } + + handle /api/ha/deliveries { + rewrite * /api/states/sensor.wall_deliveries? + import wall_ha + } + # Today's high and low, the next rain and the next sunrise or sunset, # asked of weather.get_forecasts by # home-assistant/packages/wall_weather.yaml: since HA 2024.4 a forecast diff --git a/stacks/sensitive/README.md b/stacks/sensitive/README.md index 6a81ca59..2b5edea8 100644 --- a/stacks/sensitive/README.md +++ b/stacks/sensitive/README.md @@ -805,8 +805,21 @@ container of its own: Caddy serves `wall/` as static files. alerts, the rest of the week below them while there is room, and a countdown to the next timed event in the header. The cell beside Internet is a context card that shows one thing at a time, whichever matters now - (`CONTEXT` in `wall.js`); until other sources arrive that is a Hebrew word - of the day from a static list in the page. The UPS's mains or battery, + (`CONTEXT` in `wall.js`), in this order of precedence: the drive to the + next event with an address, from an hour before it is time to leave + (`/api/ha/commute`); Shabbat or Yom Tov, from six hours before candle + lighting to havdalah (`/api/ha/shabbat`); the bins, from 16:00 the evening + before pickup to noon on the day (`/api/ha/trash`); packages to go and + get (`/api/ha/deliveries`); the open to-do items (`/api/ha/todo`); and + otherwise a Hebrew word of the day from a static list in the page. The + others that also apply are named on the card's last line. Each source is a + `wall_*.yaml` package and stays unavailable, its card hidden, until what + it reads is set up in HA's UI: the Waze Travel Time integration (origin + `Home`, region US, any destination, its polling off) and the label + `wall_commute` on each calendar to route from, the Jewish Calendar + integration, a to-do list labelled `wall_todo`, the trash helpers' + pickup day, and the 17TRACK integration with the household's account. The + commute card sends the next labelled event's location to Waze. The UPS's mains or battery, charge and runtime are in its node tile, `mjolnir`. Booted on Home Assistant 2026.11.1 against its demo calendars on 2026-11-18: the sensor held both events, and with no calendar it read unavailable, which diff --git a/stacks/sensitive/home-assistant/packages/README.md b/stacks/sensitive/home-assistant/packages/README.md index 105f3411..f055a4de 100644 --- a/stacks/sensitive/home-assistant/packages/README.md +++ b/stacks/sensitive/home-assistant/packages/README.md @@ -30,6 +30,11 @@ and nothing else. This README is not YAML and Home Assistant ignores it. | `tv_room_evening.yaml` | At 19:00 the TV comes on with Prime Video open and the TV room at its Mood scene; at 21:00 a bedtime nudge on the living-room Echo and the TV. A pause switch skips both | | `wall_calendar.yaml` | `sensor.wall_today`: the next seven days' events, asked of `calendar.get_events` every five minutes, for the office wall's Today panel, its week below tomorrow and the header's *Up next* (ADR-0119). The calendars are those labelled `wall_calendar` in the UI, or all of them when none is labelled, so no calendar is named here. Unavailable, not empty, when a calendar cannot be read | | `wall_house.yaml` | `sensor.wall_alarm`, `binary_sensor.wall_office_lights` and `sensor.wall_litter` for the office wall (ADR-0119): the house's one alarm panel's mode, and whether any light whose id contains `office` is on. Their own ids name the city and a person, so the wall reads these instead. Unavailable when nothing matches. `sensor.wall_litter` is `ok` or `attention`, with what in `needs`: the drawer at 90%, the litter under 30% or a cat's weight dropping, `litter_robot.yaml`'s thresholds | +| `wall_commute.yaml` | `sensor.wall_commute` for the office wall's context card (ADR-0119): the minutes of the quickest live-traffic route from the home zone to the next timed event within three hours, on a calendar labelled `wall_commute` in the UI, whose location looks like a place (a digit or a comma, and not Teams, Zoom, Meet, Webex or a link), and when to leave, five minutes ahead. Asked of `waze_travel_time.get_travel_times` every five minutes, only while there is such an event; the Waze Travel Time integration has to be added once in the UI for the action to exist. Sends that location to Waze. `none` when there is nothing to drive to | +| `wall_deliveries.yaml` | `sensor.wall_deliveries` for the office wall's context card (ADR-0119): the 17TRACK packages delivered today, ready to be picked up or undelivered, by their own labels, and how many are in transit. Asked of `seventeentrack.get_packages` every fifteen minutes. Never the tracking numbers. Unavailable until the 17TRACK integration is added | +| `wall_shabbat.yaml` | `sensor.wall_shabbat` for the office wall's context card (ADR-0119): the upcoming candle lighting as its state, with havdalah, the parsha, the Hebrew date and any Yom Tov's name, from the Jewish Calendar integration's entities, found by what their ids end with. Unavailable until that integration is added | +| `wall_todo.yaml` | `sensor.wall_todo` for the office wall's context card (ADR-0119): the open items, title and due date, of the to-do lists labelled `wall_todo` in the UI, asked of `todo.get_items` every minute. Unavailable while no list carries the label | +| `wall_trash.yaml` | `sensor.wall_trash` for the office wall's context card (ADR-0119): the next pickup date and whether recycling goes with it, from three helpers set in the UI (`input_select.trash_pickup_day`, `input_select.recycling_schedule`, `input_datetime.recycling_reference_date`). No integration; a holiday that moves a pickup is not known. Unavailable until the pickup day is set | | `wall_weather.yaml` | `sensor.wall_weather` for the office wall's header (ADR-0119): today's high and low, the first of the next six hours with rain or snow, and `sun.sun`'s next sunrise and sunset. Asked of `weather.get_forecasts` on `weather.forecast_home` every fifteen minutes, because a forecast is an action's answer, not an attribute. Unavailable only when neither the daily nor the hourly forecast answers; with no daily entry for today, the state is `none` and the rain and sun still come through | Home Assistant reads these files only when it starts, and the directory is diff --git a/stacks/sensitive/home-assistant/packages/wall_commute.yaml b/stacks/sensitive/home-assistant/packages/wall_commute.yaml new file mode 100644 index 00000000..259a54e9 --- /dev/null +++ b/stacks/sensitive/home-assistant/packages/wall_commute.yaml @@ -0,0 +1,112 @@ +--- +# The drive to the next event that has an address, for the office wall +# (ADR-0119): how long it takes now and when to leave. The wall shows it in +# its context card from an hour before it is time to leave until the event +# starts. +# +# The household has no fixed commute, so the destination is the calendar's: +# the next timed event that starts within three hours and whose location looks +# like a place, with a digit or a comma in it. "Teams", "Zoom" or a meeting +# link are not driven to, and are skipped. Waze is asked only while there is +# such an event, every five minutes, through +# `waze_travel_time.get_travel_times` with live traffic. That action is loaded +# by the core `waze_travel_time` integration, which has to be added once in the +# UI (its own sensor's polling can be switched off; this does not read it). +# +# Which calendars: only those labelled `wall_commute` in the UI, and none when +# none is. This is its own label, not the wall's `wall_calendar`, because the +# wall falls back to every calendar when none is labelled, and sending a +# calendar's locations out of the house needs a choice, not a default. The +# events are asked of `calendar.get_events` here, not read from +# sensor.wall_today, so Waze gets the whole location rather than the wall's +# shortened one. +# +# What leaves the house: that event's location, sent to Waze to be routed from +# the home zone. Nothing from a calendar without the label. +# +# The state is the minutes of the quickest route, or `none` when there is +# nothing to drive to or Waze did not answer, which hides the card. + +template: + - triggers: + - trigger: time_pattern + minutes: /5 + - trigger: homeassistant + event: start + - trigger: event + event_type: event_template_reloaded + actions: + - variables: + wall_calendars: >- + {{ label_entities('wall_commute') | select('match', 'calendar\.') | sort | list }} + - if: "{{ wall_calendars | count > 0 }}" + then: + - action: calendar.get_events + target: + entity_id: "{{ wall_calendars }}" + data: + start_date_time: "{{ now() }}" + end_date_time: "{{ now() + timedelta(hours=3) }}" + response_variable: agenda + continue_on_error: true + - variables: + wall_next: >- + {% set ns = namespace(e=none) %} + {% if agenda is defined and agenda is mapping %} + {% for cal in wall_calendars %} + {% for e in agenda.get(cal, {}).get('events', []) %} + {% set place = (e.get('location') or '') | lower %} + {% if 'T' in e.start and place + and (place is search('[0-9]') or ',' in place) + and not (place is search('https?:|teams|zoom|meet\.google|webex')) %} + {% set start = as_datetime(e.start) %} + {% if start > now() and (ns.e is none or start < as_datetime(ns.e.start)) %} + {% set ns.e = { + 'title': (e.get('summary') or 'Busy')[:80], + 'start': as_local(start).isoformat(), + 'location': e.location, + } %} + {% endif %} + {% endif %} + {% endfor %} + {% endfor %} + {% endif %} + {{ ns.e if ns.e is not none else {} }} + - if: "{{ wall_next.location is defined }}" + then: + - action: waze_travel_time.get_travel_times + data: + origin: zone.home + destination: "{{ wall_next.location }}" + region: us + units: imperial + realtime: true + response_variable: wall_answer + continue_on_error: true + - variables: + wall_route: >- + {% if wall_next.location is defined and wall_answer is defined and wall_answer is mapping + and (wall_answer.routes | default([]) | count) > 0 %} + {{ wall_answer.routes | sort(attribute='duration') | first }} + {% else %} + {{ {} }} + {% endif %} + # A second block, so this can read wall_route above. + - variables: + # Five minutes to get out of the door. + wall_leave_by: >- + {% if wall_route.duration is defined %} + {{ (as_datetime(wall_next.start) - timedelta(minutes=(wall_route.duration | float(0)) + 5)).isoformat() }} + {% else %} + {{ '' }} + {% endif %} + sensor: + - name: Wall commute + unique_id: wall_commute + icon: mdi:car-clock + state: "{{ wall_route.duration | float(0) | round(0) | int if wall_route.duration is defined else 'none' }}" + attributes: + title: "{{ wall_next.title | default('') if wall_route.duration is defined else '' }}" + start: "{{ wall_next.start | default('') if wall_route.duration is defined else '' }}" + route: "{{ wall_route.name | default('') }}" + leave_by: "{{ wall_leave_by }}" diff --git a/stacks/sensitive/home-assistant/packages/wall_deliveries.yaml b/stacks/sensitive/home-assistant/packages/wall_deliveries.yaml new file mode 100644 index 00000000..618c26db --- /dev/null +++ b/stacks/sensitive/home-assistant/packages/wall_deliveries.yaml @@ -0,0 +1,93 @@ +--- +# Packages that want someone to go and get them, for the office wall +# (ADR-0119): delivered today, ready to be picked up, or undelivered, and how +# many are in transit. The wall shows them in its context card while any of +# the first three is non-zero. +# +# The source is the core `seventeentrack` integration, added in the UI with +# the household's 17TRACK account, whose sign-in stays in /config/.storage. +# Its packages are an action's answer (`seventeentrack.get_packages`), so this +# asks every fifteen minutes, which is about how often the integration +# refreshes. 17TRACK gives no expected delivery date, so "today" is a +# delivery scanned today. +# +# What reaches the wall: each package's own label in 17TRACK (or "a package"), +# never its tracking number, origin or location. Unavailable until the +# integration is added, and the card stays hidden. + +template: + - triggers: + - trigger: time_pattern + minutes: /15 + - trigger: homeassistant + event: start + - trigger: event + event_type: event_template_reloaded + actions: + - variables: + wall_entry: >- + {% set e = integration_entities('seventeentrack') | first | default('') %} + {{ config_entry_id(e) if e else '' }} + - if: "{{ wall_entry not in ['', none, 'None'] }}" + then: + - action: seventeentrack.get_packages + data: + config_entry_id: "{{ wall_entry }}" + response_variable: wall_answer + continue_on_error: true + - variables: + wall_ok: "{{ wall_answer is defined and wall_answer is mapping and 'packages' in wall_answer }}" + wall_packages: >- + {{ wall_answer.packages + if wall_answer is defined and wall_answer is mapping and 'packages' in wall_answer + else [] }} + # A second block, so these can read wall_packages above. + - variables: + # Each list is labels only, at most four, 40 characters each. + wall_delivered: >- + {% set ns = namespace(items=[]) %} + {% for p in wall_packages %} + {% if (p.status | slugify) == 'delivered' and p.timestamp is defined + and as_local(as_datetime(p.timestamp)).date() == now().date() %} + {% set ns.items = ns.items + [(p.friendly_name or 'a package')[:40]] %} + {% endif %} + {% endfor %} + {{ ns.items }} + wall_ready_names: >- + {% set ns = namespace(items=[]) %} + {% for p in wall_packages %} + {% if (p.status | slugify) == 'ready_to_be_picked_up' %} + {% set ns.items = ns.items + [(p.friendly_name or 'a package')[:40]] %} + {% endif %} + {% endfor %} + {{ ns.items }} + wall_undelivered: >- + {% set ns = namespace(items=[]) %} + {% for p in wall_packages %} + {% if (p.status | slugify) == 'undelivered' %} + {% set ns.items = ns.items + [(p.friendly_name or 'a package')[:40]] %} + {% endif %} + {% endfor %} + {{ ns.items }} + wall_in_transit: >- + {% set ns = namespace(n=0) %} + {% for p in wall_packages %} + {% if (p.status | slugify) == 'in_transit' %}{% set ns.n = ns.n + 1 %}{% endif %} + {% endfor %} + {{ ns.n }} + sensor: + - name: Wall deliveries + unique_id: wall_deliveries + icon: mdi:package-variant-closed + availability: "{{ wall_ok }}" + # How many packages want someone to go and get them. + state: "{{ wall_delivered | count + wall_ready_names | count + wall_undelivered | count }}" + # The labels, at most four of each; the counts, all of them. + attributes: + delivered_today: "{{ wall_delivered[:4] }}" + delivered_today_count: "{{ wall_delivered | count }}" + ready_for_pickup: "{{ wall_ready_names[:4] }}" + ready_for_pickup_count: "{{ wall_ready_names | count }}" + undelivered: "{{ wall_undelivered[:4] }}" + undelivered_count: "{{ wall_undelivered | count }}" + in_transit: "{{ wall_in_transit }}" diff --git a/stacks/sensitive/home-assistant/packages/wall_shabbat.yaml b/stacks/sensitive/home-assistant/packages/wall_shabbat.yaml new file mode 100644 index 00000000..fe9065fd --- /dev/null +++ b/stacks/sensitive/home-assistant/packages/wall_shabbat.yaml @@ -0,0 +1,52 @@ +--- +# Candle lighting, havdalah, the week's parsha and the Hebrew date, as one +# sensor the office wall can read (ADR-0119). The wall shows them in its +# context card from six hours before candle lighting until havdalah. +# +# The source is the core `jewish_calendar` integration, added in the UI +# (diaspora, candle-lighting minutes and havdalah set there). Its entities are +# found by what their ids end with, among that integration's own entities, +# so a different entry title or a rename does not break this: +# +# upcoming_candle_lighting the current or next Shabbat's or Yom Tov's +# upcoming_havdalah its end; both stay on the current one until it ends +# parshat_hashavua / weekly_torah_portion, date, holiday +# +# Unavailable until the integration is added, and the wall's card stays +# hidden. + +template: + - sensor: + - name: Wall Shabbat + unique_id: wall_shabbat + icon: mdi:candle + device_class: timestamp + # The state is the candle lighting, as the integration gives it. + state: >- + {% set e = integration_entities('jewish_calendar') + | select('search', 'upcoming_candle_lighting$') | first | default('') %} + {{ states(e) if e else none }} + availability: >- + {% set c = integration_entities('jewish_calendar') + | select('search', 'upcoming_candle_lighting$') | first | default('') %} + {% set h = integration_entities('jewish_calendar') + | select('search', 'upcoming_havdalah$') | first | default('') %} + {{ c != '' and h != '' and has_value(c) and has_value(h) }} + attributes: + havdalah: >- + {% set e = integration_entities('jewish_calendar') + | select('search', 'upcoming_havdalah$') | first | default('') %} + {{ states(e) if e else '' }} + parsha: >- + {% set e = integration_entities('jewish_calendar') + | select('search', '(parshat_hashavua|torah_portion)$') | first | default('') %} + {{ states(e) if e and has_value(e) else '' }} + hebrew_date: >- + {% set e = integration_entities('jewish_calendar') + | select('search', '_date$') | first | default('') %} + {{ states(e) if e and has_value(e) else '' }} + # A Yom Tov's name, or '' on a plain Shabbat. + holiday: >- + {% set e = integration_entities('jewish_calendar') + | select('search', '_holiday$') | first | default('') %} + {{ states(e) if e and has_value(e) else '' }} diff --git a/stacks/sensitive/home-assistant/packages/wall_todo.yaml b/stacks/sensitive/home-assistant/packages/wall_todo.yaml new file mode 100644 index 00000000..aef165a7 --- /dev/null +++ b/stacks/sensitive/home-assistant/packages/wall_todo.yaml @@ -0,0 +1,63 @@ +--- +# The open items of the to-do lists labelled `wall_todo`, as one sensor the +# office wall can read (ADR-0119). The wall shows them in its context card +# when nothing more pressing is. +# +# Like the calendar, a list's items are an action's answer +# (`todo.get_items`), not an attribute a fixed handle can read, so this asks +# every minute. Which lists: those labelled `wall_todo` in the UI, a Local +# To-do or a Google Tasks list alike; none is named here. The label is read at +# every run. Unavailable while no list carries it, which hides the card. +# +# What reaches the wall: each open item's title and due date, at most twelve. +# Not its description. + +template: + - triggers: + - trigger: time_pattern + minutes: /1 + - trigger: homeassistant + event: start + - trigger: event + event_type: event_template_reloaded + actions: + - variables: + wall_lists: >- + {{ label_entities('wall_todo') | select('match', 'todo\.') | sort | list }} + - if: "{{ wall_lists | count > 0 }}" + then: + - action: todo.get_items + target: + entity_id: "{{ wall_lists }}" + data: + status: needs_action + response_variable: wall_answer + continue_on_error: true + - variables: + wall_ok: "{{ wall_lists | count > 0 and wall_answer is defined and wall_answer is mapping }}" + wall_items: >- + {% set ns = namespace(items=[]) %} + {% if wall_lists | count > 0 and wall_answer is defined and wall_answer is mapping %} + {% for l in wall_lists %} + {% for i in wall_answer.get(l, {}).get('items', []) %} + {% set ns.items = ns.items + [{ + 'title': (i.get('summary') or '')[:60], + 'due': i.get('due') or '', + }] %} + {% endfor %} + {% endfor %} + {% endif %} + {{ ns.items }} + sensor: + - name: Wall to-do + unique_id: wall_todo + # The name alone would make sensor.wall_to_do; the wall's Caddy handle + # reads sensor.wall_todo. + default_entity_id: sensor.wall_todo + icon: mdi:checkbox-marked-outline + availability: "{{ wall_ok }}" + # How many items are open, all of them, so the history graph means + # something and the wall's "+N more" counts the ones not sent. + state: "{{ wall_items | count }}" + attributes: + items: "{{ wall_items[:12] }}" diff --git a/stacks/sensitive/home-assistant/packages/wall_trash.yaml b/stacks/sensitive/home-assistant/packages/wall_trash.yaml new file mode 100644 index 00000000..4186052f --- /dev/null +++ b/stacks/sensitive/home-assistant/packages/wall_trash.yaml @@ -0,0 +1,77 @@ +--- +# The next trash pickup, and whether recycling goes out with it, for the +# office wall (ADR-0119). The wall shows it in its context card from 16:00 the +# evening before until noon on the day. +# +# No integration and no third-party schedule: three helpers, set once in the +# UI. A holiday that moves a pickup is not known here. +# +# input_select.trash_pickup_day the weekday, or "not set" +# input_select.recycling_schedule every week, every other week, or +# not tracked +# input_datetime.recycling_reference_date any one past or future recycling +# day, for every other week +# +# None of them has an `initial`, so what is set survives a restart. + +input_select: + trash_pickup_day: + name: Trash pickup day + icon: mdi:trash-can-outline + options: + - not set + - Monday + - Tuesday + - Wednesday + - Thursday + - Friday + - Saturday + recycling_schedule: + name: Recycling schedule + icon: mdi:recycle + options: + - not tracked + - every week + - every other week + +input_datetime: + recycling_reference_date: + name: A recycling pickup date (for every other week) + has_date: true + has_time: false + +template: + - sensor: + - name: Wall trash + unique_id: wall_trash + icon: mdi:trash-can-outline + device_class: date + # The next pickup, today included. now() makes this re-evaluate each + # minute, so it rolls over at midnight on its own. + state: >- + {% set days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] %} + {% set day = states('input_select.trash_pickup_day') %} + {% if day in days %} + {{ (now().date() + timedelta(days=(days.index(day) - now().weekday()) % 7)).isoformat() }} + {% else %} + {{ none }} + {% endif %} + availability: >- + {{ states('input_select.trash_pickup_day') + in ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] }} + attributes: + recycling: >- + {% set days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] %} + {% set day = states('input_select.trash_pickup_day') %} + {% set sched = states('input_select.recycling_schedule') %} + {% if day not in days %} + {{ false }} + {% elif sched == 'every week' %} + {{ true }} + {% elif sched == 'every other week' and has_value('input_datetime.recycling_reference_date') %} + {% set next = now().date() + timedelta(days=(days.index(day) - now().weekday()) % 7) %} + {% set ref = (states('input_datetime.recycling_reference_date') | as_datetime).date() %} + {{ ((next - ref).days // 7) % 2 == 0 }} + {% else %} + {{ false }} + {% endif %} diff --git a/stacks/sensitive/wall/wall.css b/stacks/sensitive/wall/wall.css index 0b217e80..eb3086dd 100644 --- a/stacks/sensitive/wall/wall.css +++ b/stacks/sensitive/wall/wall.css @@ -244,6 +244,14 @@ html, body { .word { font: 600 72px/1.15 var(--sans); color: var(--purple); align-self: flex-start; } .word-sub { font: 400 28px/1.4 var(--sans); color: var(--fg-dim); margin-top: 10px; } .word-sub b { font-weight: 600; color: var(--fg); } +.ctx-hero { font: 600 56px/1.15 var(--sans); color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.ctx-hero.warn { color: var(--yellow); } +.ctx-hero.alert { color: var(--red); } +.ctx-sub { font: 400 28px/1.35 var(--sans); color: var(--fg-dim); margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +.todo-list { display: flex; flex-direction: column; gap: 10px; min-height: 0; max-height: 100%; overflow: hidden; align-self: stretch; } +.todo-item { display: flex; align-items: center; gap: 16px; font: 400 30px/1.25 var(--sans); color: var(--fg); } +.todo-item i { width: 20px; height: 20px; border: 2px solid var(--mute); border-radius: 5px; flex: none; } +.todo-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* ---------- weather, in the header ---------- */ .wx { display: flex; align-items: center; gap: 22px; margin-left: auto; margin-right: 36px; } diff --git a/stacks/sensitive/wall/wall.js b/stacks/sensitive/wall/wall.js index a10653ae..fcfd3e2c 100644 --- a/stacks/sensitive/wall/wall.js +++ b/stacks/sensitive/wall/wall.js @@ -49,7 +49,10 @@ ...DOORS.map((d) => d[0]), ...WINDOWS.map((w) => w[0])]; // "today" is sensor.wall_today: the calendars' events for the next seven // days, gathered by home-assistant/packages/wall_calendar.yaml. - const HA = [...HOUSE, "today"]; + // The context card's sources (wall_commute, wall_shabbat, wall_todo, + // wall_trash, wall_deliveries), each unavailable until it is set up. + const CARDS = ["commute", "shabbat", "todo", "trash", "deliveries"]; + const HA = [...HOUSE, "today", ...CARDS]; const states = {}; // HA name -> the entity's state object const answers = {}; // name -> data.result of the last good answer const lastOk = {}; // name -> Date.now() of the last good answer @@ -322,6 +325,7 @@ ["power", ["ups"]], ["house", HOUSE.map((n) => `ha:${n}`)], ["calendar", ["ha:today"]], + ["cards", CARDS.map((n) => `ha:${n}`)], ]; for (const [label, names] of groups) { const oldest = Math.min(...names.map((n) => lastOk[n] ?? 0)); @@ -597,7 +601,117 @@ // matters is hidden without a word. The last entry always applies, so the // card is never empty. Later cards (commute, Shabbat, trash, deliveries, // now playing) slot in above it as their sources arrive. + const MIN = 60_000; + const attrs = (name) => (haFresh(name) && states[name].attributes) || {}; + const until = (t) => { + const m = Math.round((t - Date.now()) / MIN); + return m < 60 ? `${m} min` : `${Math.floor(m / 60)} h ${m % 60} min`; + }; + const dayAt = (t) => { + const d = dayOf({ all_day: false, start: t.toISOString() }, new Date()); + return d === 0 ? hm(t) : d === 1 ? `tomorrow ${hm(t)}` : `${shortDays[t.getDay()]} ${hm(t)}`; + }; + function hero(box, text, cls) { box.append(el("div", `ctx-hero ${cls || ""}`, text)); } + function sub(box, text) { if (text) box.append(el("div", "ctx-sub", text)); } + + // Commute: from an hour before it is time to leave until the event starts. + function commuteLive() { + if (!haFresh("commute") || states.commute.state === "none") return false; + const a = attrs("commute"); + if (!a.leave_by || !a.start) return false; + const now = Date.now(); + return now >= new Date(a.leave_by) - 60 * MIN && now < new Date(a.start); + } + function renderCommute(box) { + const a = attrs("commute"); + const leave = new Date(a.leave_by); + const late = leave <= Date.now(); + hero(box, late ? "Leave now" : `Leave in ${until(leave)}`, + late ? "alert" : leave - Date.now() <= 10 * MIN ? "warn" : ""); + sub(box, `${String(a.title || "Next event")} · ${hm(new Date(a.start))}`); + sub(box, [`${states.commute.state} min drive`, a.route ? `via ${a.route}` : ""].filter(Boolean).join(" · ")); + } + + // Shabbat or Yom Tov: from six hours before candle lighting to havdalah. + function shabbatLive() { + if (!haFresh("shabbat")) return false; + const candles = new Date(states.shabbat.state); + const havdalah = new Date(attrs("shabbat").havdalah); + const now = Date.now(); + return !isNaN(candles) && !isNaN(havdalah) && now < havdalah && candles - now <= 6 * 60 * MIN; + } + function renderShabbat(box) { + const a = attrs("shabbat"); + const candles = new Date(states.shabbat.state); + const havdalah = new Date(a.havdalah); + if (candles > Date.now()) { + hero(box, `Candles ${hm(candles)}`, candles - Date.now() <= 60 * MIN ? "warn" : ""); + sub(box, `Havdalah ${dayAt(havdalah)}`); + } else { + hero(box, a.holiday ? "Chag sameach" : "Shabbat shalom"); + sub(box, `Havdalah ${dayAt(havdalah)}`); + } + sub(box, [a.parsha, a.hebrew_date].filter(Boolean).map(String).join(" · ")); + } + + // Trash: from 16:00 the evening before pickup until noon on the day. + function trashLive() { + if (!haFresh("trash")) return false; + const day = localDay(states.trash.state); + const now = new Date(); + const d = Math.round((day - midnight(now)) / 86_400_000); + return (d === 1 && now.getHours() >= 16) || (d === 0 && now.getHours() < 12); + } + function renderTrash(box) { + const today = Math.round((localDay(states.trash.state) - midnight(new Date())) / 86_400_000) === 0; + hero(box, today ? "Pickup today" : "Bins out tonight"); + sub(box, attrs("trash").recycling ? "Trash and recycling" : "Trash only, no recycling"); + } + + // Deliveries: while a package wants someone to go and get it. + function deliveriesLive() { + return haFresh("deliveries") && Number(states.deliveries.state) > 0; + } + function renderDeliveries(box) { + const a = attrs("deliveries"); + const lines = [ + ["Delivered", "delivered_today"], ["Ready for pickup", "ready_for_pickup"], ["Not delivered", "undelivered"], + ].map(([label, key]) => { + const names = Array.isArray(a[key]) ? a[key].map(String) : []; + return [label, names, Math.max(Number(a[`${key}_count`]) || 0, names.length)]; + }).filter(([, , n]) => n > 0); + if (!lines.length) return; + const [first, , count] = lines[0]; + hero(box, `${count} ${first.toLowerCase()}`, first === "Not delivered" ? "warn" : ""); + for (const [label, names, n] of lines) { + const rest = n - names.length; + sub(box, `${label} · ${names.join(", ")}${rest > 0 ? ` +${rest} more` : ""}`); + } + if (Number(a.in_transit) > 0) sub(box, `${a.in_transit} on the way`); + } + + // The to-do list, the default when it has anything on it. + function todoLive() { return haFresh("todo") && Number(states.todo.state) > 0; } + function renderTodo(box) { + const items = attrs("todo").items || []; + const list = el("div", "todo-list"); + for (const i of items) { + const row = el("div", "todo-item"); + row.append(el("i"), el("span", null, String(i.title || ""))); + list.append(row); + } + box.append(list); + // The sensor sends at most twelve; its state counts all of them. + fitList(list, "todo-item", Math.max(0, (Number(states.todo.state) || 0) - items.length)); + } + const CONTEXT = [ + { title: "Commute", short: "commute", when: commuteLive, render: renderCommute }, + { title: () => (attrs("shabbat").holiday ? String(attrs("shabbat").holiday) : "Shabbat"), + short: "shabbat", when: shabbatLive, render: renderShabbat }, + { title: "Trash", short: "trash", when: trashLive, render: renderTrash }, + { title: "Packages", short: "packages", when: deliveriesLive, render: renderDeliveries }, + { title: "To-do", short: "to-do", when: todoLive, render: renderTodo }, { title: "Word of the day", short: "word", when: () => true, render: renderWord }, ]; @@ -651,7 +765,7 @@ box.replaceChildren(); const live = CONTEXT.filter((c) => c.when()); const top = live[0]; - $("h-context").textContent = top.title; + $("h-context").textContent = typeof top.title === "function" ? top.title() : top.title; top.render(box); const rest = live.slice(1, -1).map((c) => c.short); $("context-also").textContent = rest.length ? `also: ${rest.join(" · ")}` : "";