Custom HA integration (domain meshcore_agent) that lets MeshCore nodes manage a todo list over mesh messages: - todo / todo list, todo add, todo done, todo uncheck, todo remove - remind <n> <when> / remind off <n> (relative, clock, weekday, absolute) - replies via meshcore.send_message / send_channel_message - reminders scheduled with async_track_point_in_time and delivered to the sender who set them - todo list also exposed as a HA todo entity - config flow with sender allowlist, allow-all toggle, reply length cap - pure-Python core (core/) covered by pytest; adapter flow tested with stubbed hass
118 lines
4.6 KiB
Markdown
118 lines
4.6 KiB
Markdown
# MeshCore Agent for Home Assistant
|
|
|
|
A HACS custom integration that lets MeshCore nodes talk to Home Assistant over
|
|
the mesh. The first module is a **todo list with reminders**: any allowlisted
|
|
node can list, add, complete, remove todos and set per-todo reminders —
|
|
entirely from text messages.
|
|
|
|
Built on top of [meshcore-dev/meshcore-ha](https://github.com/meshcore-dev/meshcore-ha):
|
|
it listens for `meshcore_message` events and replies via the
|
|
`meshcore.send_message` / `meshcore.send_channel_message` services.
|
|
|
|
## Requirements
|
|
|
|
- Home Assistant 2025.6.0 or later
|
|
- The [MeshCore integration](https://github.com/meshcore-dev/meshcore-ha)
|
|
installed and configured (USB, BLE or TCP companion)
|
|
|
|
## Installation
|
|
|
|
1. In HACS → ⋮ → *Custom repositories*, add this repository with category
|
|
**Integration**.
|
|
2. Install **MeshCore Agent**.
|
|
3. Restart Home Assistant.
|
|
4. Settings → Devices & services → *Add Integration* → **MeshCore Agent**.
|
|
5. Fill in the allowlist of senders who may command the agent (public key
|
|
prefixes or contact names, comma separated). Leave "Allow all senders"
|
|
unchecked; anyone on the mesh could otherwise command your todo list.
|
|
|
|
## Mesh commands
|
|
|
|
Send a direct message to your companion (or a message to a channel, if that
|
|
channel's senders are allowlisted):
|
|
|
|
| Command | Example | Result |
|
|
| --- | --- | --- |
|
|
| `todo` | `todo` | List all todos (open first, then done) |
|
|
| `todo add <text>` | `todo add Buy milk` | Add a todo |
|
|
| `todo done <n>` | `todo done 2` | Check a todo off |
|
|
| `todo uncheck <n>` | `todo uncheck 2` | Reopen a todo |
|
|
| `todo remove <n>` | `todo remove 2` (alias `rm`) | Delete a todo |
|
|
| `remind <n> <when>` | `remind 1 in 30m` | Set a reminder for a todo |
|
|
| `remind off <n>` | `remind off 1` | Clear a todo's reminder |
|
|
| `help` | `help` | Command overview |
|
|
|
|
`<n>` is the number shown by `todo`, or a unique text prefix of the item
|
|
(`todo done buy m`). Messages may optionally start with a wake word:
|
|
`agent todo`, `bot done 2`.
|
|
|
|
### Reminder times
|
|
|
|
| Syntax | Example | Meaning |
|
|
| --- | --- | --- |
|
|
| `in <N><unit>` | `in 30m`, `in 1h30m`, `in 1d` | Relative offset (`s`/`m`/`h`/`d`) |
|
|
| `HH:MM` | `14:30` | Today at that time, or tomorrow if it passed |
|
|
| `today/tomorrow HH:MM` | `tomorrow 09:00` | Explicit day |
|
|
| `<weekday> HH:MM` | `monday 08:00` | Next occurrence of that weekday |
|
|
| `YYYY-MM-DD [HH:MM]` | `2026-12-24 14:30` | Absolute date |
|
|
|
|
Reminders are sent over the mesh ("Reminder: Buy milk") to the sender who set
|
|
them, using the same time zone as Home Assistant. They also show up as the
|
|
item's due date on the Home Assistant side.
|
|
|
|
### Reply flow
|
|
|
|
- Direct messages are answered as direct messages to the sender's
|
|
`pubkey_prefix`.
|
|
- Channel messages are answered back into the same channel; reminders set from
|
|
a channel are delivered back into that channel.
|
|
- Replies are truncated to the configured maximum length (default 200 chars).
|
|
|
|
## Home Assistant side
|
|
|
|
The todo list appears as a `todo` entity (`todo.<companion>_todos`), so the
|
|
same items can also be added, completed and deleted from the Home Assistant UI
|
|
— and changes made in the UI are visible to mesh users on the next `todo`.
|
|
|
|
## Security notes
|
|
|
|
- Only allowlisted senders' commands are executed; everything else is ignored.
|
|
- The allowlist matches direct-message senders on their 12-hex `pubkey_prefix`
|
|
and channel senders on their advertised name. Names on channels are
|
|
self-reported — prefer key prefixes when allowlisting channel users.
|
|
|
|
## Architecture
|
|
|
|
```
|
|
custom_components/meshcore_agent/
|
|
├── core/ # pure Python, no HA imports, fully unit-tested
|
|
│ ├── store.py # todo store: items, reminders, reference resolution
|
|
│ ├── timeparse.py # reminder time parser
|
|
│ └── commands.py # command registry + handlers
|
|
├── __init__.py # HA adapter: event listener, reply sender, reminder scheduler
|
|
├── config_flow.py # UI config: allowlist, allow-all, reply length cap
|
|
├── todo.py # todo platform entity
|
|
└── store.py # HA storage wrapper (JSON under .storage)
|
|
```
|
|
|
|
The core does all parsing/permission-sensitive work and is covered by pytest
|
|
(`tests/`); the HA layer is a thin event adapter. A crash in message handling
|
|
is caught and logged, and never takes down the event loop.
|
|
|
|
## Development
|
|
|
|
```bash
|
|
uv venv .venv
|
|
uv pip install pytest pytest-asyncio homeassistant
|
|
.venv/pytest
|
|
```
|
|
|
|
To run against a live instance, symlink or copy the integration into your HA
|
|
config directory:
|
|
|
|
```bash
|
|
ln -s "$(pwd)/custom_components/meshcore_agent" /path/to/config/custom_components/meshcore_agent
|
|
```
|
|
|
|
then restart Home Assistant or reload the integration.
|