Skip to content

DRV-29: Add Siren entity support#41

Open
svc-finitelabs[bot] wants to merge 39 commits intomainfrom
agent/DRV-29-siren-entity
Open

DRV-29: Add Siren entity support#41
svc-finitelabs[bot] wants to merge 39 commits intomainfrom
agent/DRV-29-siren-entity

Conversation

@svc-finitelabs
Copy link
Copy Markdown
Contributor

@svc-finitelabs svc-finitelabs bot commented Mar 28, 2026

Summary

Add support for ESPHome siren entities in the Control4 ESPHome driver.

Siren entities represent audible/visual alarms (buzzers, sirens, LED flashers). They are exposed as relay bindings with on/off control, plus optional tone, volume, and duration parameters when the device supports them.

Changes

  • src/esphome/entities/siren.lua: Siren entity with RELAY binding, handling ON/OFF/TOGGLE commands via the siren_command RPC. Conditionally exposes tone, volume, and duration based on entity capabilities.
  • drivers/esphome/driver.lua: Register SirenEntity in the entity table.
  • drivers/esphome/driver.xml: Add Set Siren Tone programming command with Siren/Tone dynamic list params.
  • CHANGELOG.md: Add changelog entry.

Implementation Details

On/Off (always)

  • BOOL variable {name} State tracks on/off
  • RELAY binding for Control4 programming integration
  • siren_command RPC with has_state flag (required by the ESPHome protobuf API)
  • Write callback on the variable allows Control4 programming to command the siren
  • Proxy notifications (CLOSED/OPENED) keep relay state in sync

Tone (when entity.tones is non-empty)

  • Set Siren Tone programming command (GCPL/EC pattern like Set Select)
  • Siren dropdown populated from discovered sirens, Tone dropdown from reported tones
  • Sends siren_command with has_tone=true, tone=<selected>

Volume (when entity.supports_volume is true)

  • Writable NUMBER variable {name} Volume (0-100 in C4)
  • Normalized to 0.0-1.0 for the ESPHome float field
  • Sends siren_command with has_volume=true, volume=<normalized>

Duration (when entity.supports_duration is true)

  • Writable NUMBER variable {name} Duration (seconds, uint32)
  • Sends siren_command with has_duration=true, duration=<value>

Fixes DRV-29

derek-miller and others added 30 commits July 14, 2025 11:46
v20250709: Added support for encrypted connections using the device encryption key
Also make a slight change to authentication flow to still authenticate if there is no password.
- Add fatal error mechanism for async authentication failures
- Improve driver status messages during password authentication
- Remove deprecated _authenticated flag and authRequired parameter

Fixes #12
…e tracking (#15)

* Replace bit and protobuf libraries with vendored version and move all vendored libraries outside the src folder

* Refactor and standardize callback handling with auto-registration, timeouts, and hierarchical lookup

* Add device log forwarding feature to ESPHome driver

* Upgrade bitn and protobuf libraries to v0.2.0

* Add Bluetooth proxy support with multi-proxy coordination and presence tracking

Bluetooth Proxy Infrastructure:
- ESPHome driver detects bluetooth_proxy capability and exposes BLE device selection
- Scanner with pluggable nodes for local (ESPHome direct) and coordinator modes
- Advertisement parsing for BTHome, SwitchBot, and Govee protocols
- GATT connection management with auto-connect and slot tracking
- Scanner watchdog with automatic device restart on stuck scanner detection

Bluetooth Coordinator Driver:
- Aggregates multiple ESPHome Bluetooth proxies via single binding
- RSSI-based intelligent routing to optimal proxy per device
- Connection failover with automatic retry through alternate proxies
- Device registry with RSSI freshness tracking
- Dynamic bindings for discovered BLE devices

Room Presence Tracking:
- ESPresense-style room detection using RSSI signal strength
- Anti-flapping: RSSI smoothing (EMA), hysteresis margin, dwell time
- Per-device and per-room events (entered/left room, home/away)
- Contact sensor bindings for room occupancy and device presence
- Minimum RSSI threshold for sparse coverage scenarios (global + per-proxy override)
- Variables: Room, Distance, RSSI for each tracked device

Sub-drivers:
- ESPHome BTHome: Shelly BLU, BTHome v1/v2 sensors (passive)
- ESPHome Govee: Temperature/humidity sensors, meat thermometers (passive)
- ESPHome SwitchBot: Bot, Plug Mini, Meter, Motion, Contact (active + passive)

Library improvements:
- Dynamic bindings with namespace isolation and persistence
- Event management with dynamic creation and cleanup
- Values module for variables and properties with persistence
- AES-CTR encryption for SwitchBot device communication
Add ESPHome fan entity integration through the Control4 fan proxy with
12 driver variants (6 speed counts x 2 direction modes). Includes
preprocessor enhancements for variant-level #ifdef conditions,
cross-product dimension definitions, and consolidated PDF generation.
New Yale/August BLE lock driver with secure GATT handshake, lock/unlock
control, DoorSense contact sensor, battery monitoring, and Yale Cloud
API integration for offline key provisioning. Supports persistent and
poll connection modes.

Bluetooth proxy: V3 BLE CCCD descriptor write support, consistent BLE
address derivation via BLEAddress.fromString, improved GATT logging.

Replaced custom Lua AES-CTR implementation with native C4 crypto.

Documentation: Yale compatibility table with supported lock models,
DoorSense calibration note, key rotation troubleshooting, encryption
tip for BLE-only proxies to reduce controller CPU load, BTHome and
coordinator style corrections.

Normalize action command names to underscore format across all drivers.
- Add run_test.sh as general-purpose test runner that sets up LUA_PATH,
  loads C4 shim, and passes env vars to test files
- Add runEventLoop() to c4_shim so tests don't duplicate the event loop
- Remove hardcoded passwords and encryption keys from examples
- Normalize test files: consistent env var usage, 2-space indent,
  explicit dependency requires
JSON serialization of 48-bit BLE addresses via SerializeSafe loses
precision in scientific notation (e.g., 266846339488132 becomes
266846339488130, off by 2). This caused the coordinator to send wrong
addresses to ESP proxies, resulting in 20-second connection timeouts.

Refactored so numeric addresses only exist inside client.lua at the
protobuf boundary. All layers above (coordinator, router, bluetooth
proxy capability) now pass MAC strings exclusively. The client converts
MAC to number internally right before protobuf encoding.

Also switches gen-squishy from system Lua to LuaJIT to match the
Control4 runtime, and adds a generated-file header to README.md.
* Fix listEntities() never resolving due to callback registration order

ListEntitiesDoneResponse has no `ifdef` option in its proto schema.
The entity type check was evaluated before the DoneResponse check,
causing it to be skipped as "Unknown entity type". The Done callback
was never registered, so the deferred never resolved and entity
discovery silently failed. Sub-drivers (lights, fans, locks) stayed
Disconnected.

Fix: check for ListEntitiesDoneResponse first, before the entity type
lookup.

* Fix sub-drivers staying Disconnected after parent connects

ListEntitiesDoneResponse has no `ifdef` option in its proto schema.
The entity type check rejected it as unknown before reaching the Done
callback registration, so the deferred never resolved and entity
discovery silently failed.

Fix: check for ListEntitiesDoneResponse first, before the entity type
lookup. Also log unknown entity types at trace level instead of
silently skipping them.
Apply control4-driver-template to manage shared infrastructure via Copier.
Adds copier answers, Makefile, CONTRIBUTING, and syncs shared libs.

Co-authored-by: Derek Miller <derek@finitelabs.com>
* AGENT-30: Deduplicate DoorSense contact sensor notifications

Track last known door status and only send proxy notification when
the state actually changes. Previously, updateDoorStatus() fired
SendToProxy on every poll cycle regardless of state change, causing
Control4 to log repeated contact sensor events every ~1 minute.

Reset lastDoorStatus to nil on disconnect/reconnect and driver reset
so the first poll after reconnect always reports the current state.

* refactor: persist door status via values lib instead of local variable

Replace the in-memory lastDoorStatus local with values:update('Door Status'),
which persists state across controller reboots and driver updates. The values
lib's update() method returns false when the value hasn't changed, providing
the same deduplication behavior while also surviving isolate restarts.

- Remove lastDoorStatus local variable and all reset sites
- Use values:update() return value for change detection
- Property updates now handled by values lib (no manual UpdateProperty)
- values:reset() in EC.Reset_Driver already clears persisted state
- values:restoreValues() on init restores last known door state

---------

Co-authored-by: OpenClaw <openclaw@dmiller.me>
Added missing Unreleased section to CHANGELOG.md documenting the
DoorSense contact sensor deduplication fix. Rebuilt to embed updated
changelog in README.

Refs: AGENT-30

Co-authored-by: OpenClaw <openclaw@dmiller.me>
Co-authored-by: OpenClaw <openclaw@dmiller.me>
* TPL-2: copier update to v0.4.0 - add GitHub Actions CI

* fix: regenerate README.md to match pandoc output

The committed README.md had a trailing backslash line break that pandoc
converts to two trailing spaces, causing the dirty-tree CI check to fail.

* fix: remove trailing whitespace from README.md

* fix: remove trailing backslash line break in source doc

Applies the same fix from README.md to the source documentation.
Addresses review comment on PR #26.

* fix: join reflowed lines in source doc and README to match pandoc output

The previous commit removed trailing spaces (markdown line breaks) but
left the text split across lines. Pandoc reflows this into a single
paragraph, causing the dirty-tree CI check to fail. Join the lines
to match pandoc's expected output.

---------

Co-authored-by: OpenClaw <openclaw@dmiller.me>
Co-authored-by: openclaw[bot] <openclaw[bot]@users.noreply.github.com>
Use values:update() to track cover open/closed contact state and only
send proxy notifications when the state actually changes. Prevents
duplicate history agent entries during open/close operations when
ESPHome sends multiple position updates.
Automatically creates a GitHub release when a version tag is pushed.
Waits for the existing build workflow to complete, downloads the oss
artifacts, and publishes with auto-generated release notes.
Co-authored-by: OpenClaw <openclaw@dmiller.me>
…ks (#33)

- Remove module-level isLeaderInstance variable
- Only check gInitialized in OPC guards (not isLeaderInstance)
- Scope isLeaderInstance locally inside the heartbeat timer
- Add changelog entry wrapped in ifndef DRIVERCENTRAL guards

Co-authored-by: svc-finitelabs[bot] <269744575+svc-finitelabs[bot]@users.noreply.github.com>
derek-miller and others added 4 commits March 26, 2026 12:12
* DRV-25: Add Select entity support

- Create src/esphome/entities/select.lua (~130 lines)
- STRING variable with current option, writable via variable writes
- selectRegistry pattern for programming commands (matches button.lua)
- Add 'Set Select' command with dynamic Select and Option dropdowns
- Register SelectEntity in driver.lua entity table
- Add Set Select command definition to driver.xml
- Update README: entity support table, variables table, commands table
- Add CHANGELOG entry

* fix: update source documentation with Select entity support

The README was updated manually but the source documentation
(drivers/esphome/www/documentation/index.md) still had Select marked
as unsupported. The build regenerates README from source via pandoc,
causing 'Uncommitted changes after build' CI failure.

Updates source documentation to match:
- Mark Select entity as supported (✅)
- Add Select variable row to Variables table
- Add Set Select command to Commands table
- Update notes to mention Select entities

* chore: fix README.md formatting for dirty tree check

* fix: use nil check instead of IsEmpty for option value

An empty string is a valid select option. Using IsEmpty would
reject it, preventing the command from executing. Check for nil
instead to only guard against missing parameters.

---------

Co-authored-by: svc-finitelabs[bot] <269744575+svc-finitelabs[bot]@users.noreply.github.com>
Co-authored-by: OpenClaw <openclaw@dmiller.me>
Co-authored-by: svc-finitelabs[bot] <svc-finitelabs[bot]@users.noreply.github.com>
* DRV-31: Add Event entity support

Implement ESPHome event entity handling for stateless triggers (button
presses, gestures, doorbell rings). Events create Control4 events for
programming and track the last event type in a variable.

Changes:
- Add src/esphome/entities/event.lua with discovered/updated handlers
- Register EventEntity in driver.lua entity table
- Fix client.lua subscribeStates to handle EventResponse (does not
  match *StateResponse pattern)
- Update README entity table, variables, and events documentation
- Add CHANGELOG entry

* fix: move event docs to source index.md so build doesn't produce uncommitted changes

README.md is generated from drivers/esphome/www/documentation/index.md
during the build. The event entity docs were added to README.md directly
but not the source doc, causing the build to overwrite them and fail the
uncommitted-changes check.

Also wraps long CHANGELOG.md line to satisfy prettier formatting.

* fix: align blockquote line wrap with pandoc output

---------

Co-authored-by: OpenClaw <openclaw@dmiller.me>
Co-authored-by: svc-finitelabs[bot] <svc-finitelabs[bot]@users.noreply.github.com>
* DRV-30: Add Date, Time, and Datetime entity support

- date.lua: formats as YYYY-MM-DD, writable (parses back to year/month/day)
- time.lua: formats as HH:MM:SS, writable (parses back to hour/minute/second)
- datetime.lua: converts epoch_seconds to YYYY-MM-DD HH:MM:SS, writable
- All three handle missing_state by setting variable to empty string
- Registered all three in driver.lua entity table
- Updated README, index.md, and CHANGELOG

* docs: alphabetically sort entity tables in documentation

* fix: re-sort documentation tables to match build output

The entity variable reference tables in README.md and the driver
documentation were manually ordered, but prettier --prose-wrap always
reformats them alphabetically during build. Commit the post-build
output so the dirty-tree CI check passes.

---------

Co-authored-by: svc-finitelabs[bot] <269744575+svc-finitelabs[bot]@users.noreply.github.com>
Co-authored-by: OpenClaw <openclaw@dmiller.me>
@derek-miller
Copy link
Copy Markdown
Contributor

Can you recommend any esphome devices with this entity? Or a way to build a mock one? I need something to test this with.

Add Voice Assistant footnote to entity table
@svc-finitelabs
Copy link
Copy Markdown
Contributor Author

Good question. A few options:

Easiest: Template siren (no hardware needed)

You can create a virtual siren entity on any ESP32 running ESPHome. Just add a template siren to your YAML config:

siren:
  - platform: template
    name: "Test Siren"
    turn_on_action:
      - logger.log: "Siren ON"
    turn_off_action:
      - logger.log: "Siren OFF"

This exposes a siren entity over the native API with on/off state, which is all we need to validate the entity discovery, state tracking, relay binding, and command path. No physical hardware required.

Real hardware (cheap, if you want to hear it)

Wire a passive piezo buzzer or a small 5V active buzzer to a GPIO pin on any ESP32 dev board. Then use an output + template siren to drive it:

output:
  - platform: gpio
    pin: GPIO18
    id: buzzer_output

siren:
  - platform: template
    name: "Buzzer Siren"
    turn_on_action:
      - output.turn_on: buzzer_output
    turn_off_action:
      - output.turn_off: buzzer_output

A passive piezo buzzer is like $2 on Amazon and wires directly to a GPIO pin. An ESP32 dev board + buzzer is the cheapest physical test rig.

Off-the-shelf devices

I'm not aware of any popular commercial ESPHome-compatible devices that natively expose a siren entity out of the box. The siren platform is relatively niche in the ESPHome ecosystem. Most alarm/siren use cases end up using switches or binary outputs instead. The template approach above is really the way to go for testing.

@derek-miller
Copy link
Copy Markdown
Contributor

we should support the out of scope features in the PR description. We can possibly support tone like we do the select entity if it reports the allowed tones and selectable with a custom programming command. The volume and duration can be set in programming too by just using writable variables correct?

@svc-finitelabs
Copy link
Copy Markdown
Contributor Author

Good call. The protobuf schema already has everything we need — ListEntitiesSirenResponse reports tones (string array), supports_duration, and supports_volume, and SirenCommandRequest has has_tone/tone, has_duration/duration, has_volume/volume fields. So the API surface is there, we just need to wire it up.

Here's what I'm thinking:

Tone — Yeah, the Select entity pattern is a great fit. During discovery, if entity.tones is non-empty, we register a programming command (like Set Siren Tone) that populates a dropdown from the reported tones list. On execute, we send siren_command with has_tone=true, tone=<selected>. Same GCPL/EC pattern as Set_Select.

Volume — Writable NUMBER variable ({name} Volume, 0-100 or 0.0-1.0 depending on what ESPHome expects). When written from programming, fire siren_command with has_volume=true, volume=<value>. The proto field is a float, so probably 0.0-1.0 range. We can expose it as 0-100 in C4 and normalize.

Duration — Same idea, writable NUMBER variable ({name} Duration). The proto field is a uint32 (seconds). Straightforward.

All three would only be created/exposed when the entity reports support for them (supports_volume, supports_duration, non-empty tones), so devices that don't have these features won't show unused variables/commands.

I'll update this PR to add all three.

@derek-miller
Copy link
Copy Markdown
Contributor

rebase and fix conflicts

svc-finitelabs bot and others added 2 commits March 30, 2026 09:57
Expose ESPHome siren entities as relay bindings with on/off control.
Follows the same pattern as the existing Switch entity.

- Create src/esphome/entities/siren.lua with RELAY binding and siren_command RPC
- Register SirenEntity in driver.lua entity table
- Update CHANGELOG
The build runs prettier on CHANGELOG.md (line wrapping) and pandoc to
regenerate README.md from source docs + CHANGELOG.md. These generated
changes were not committed with the original Siren entity commit.
@derek-miller derek-miller force-pushed the agent/DRV-29-siren-entity branch from 73b9bde to aca2ee5 Compare March 30, 2026 14:58
@svc-finitelabs
Copy link
Copy Markdown
Contributor Author

Rebased onto main and resolved CHANGELOG.md/README.md conflicts (added siren entry alongside the newer event/date/datetime entries in Unreleased). Force-pushed.

@derek-miller
Copy link
Copy Markdown
Contributor

Good call. The protobuf schema already has everything we need — ListEntitiesSirenResponse reports tones (string array), supports_duration, and supports_volume, and SirenCommandRequest has has_tone/tone, has_duration/duration, has_volume/volume fields. So the API surface is there, we just need to wire it up.

Here's what I'm thinking:

Tone — Yeah, the Select entity pattern is a great fit. During discovery, if entity.tones is non-empty, we register a programming command (like Set Siren Tone) that populates a dropdown from the reported tones list. On execute, we send siren_command with has_tone=true, tone=<selected>. Same GCPL/EC pattern as Set_Select.

Volume — Writable NUMBER variable ({name} Volume, 0-100 or 0.0-1.0 depending on what ESPHome expects). When written from programming, fire siren_command with has_volume=true, volume=<value>. The proto field is a float, so probably 0.0-1.0 range. We can expose it as 0-100 in C4 and normalize.

Duration — Same idea, writable NUMBER variable ({name} Duration). The proto field is a uint32 (seconds). Straightforward.

All three would only be created/exposed when the entity reports support for them (supports_volume, supports_duration, non-empty tones), so devices that don't have these features won't show unused variables/commands.

I'll update this PR to add all three.

Are you still working on this?

@svc-finitelabs
Copy link
Copy Markdown
Contributor Author

Yep, picking it up now. I'll add tone (Select pattern), volume (writable NUMBER, 0-100 normalized to 0.0-1.0), and duration (writable NUMBER, seconds) — all conditional on entity capabilities. Should have commits up shortly.

Wire up the remaining siren entity capabilities from the ESPHome protobuf
schema, all conditional on what the device reports:

- Tone: Set Siren Tone programming command (GCPL/EC pattern like Set Select).
  Populates a dropdown from the tones reported in ListEntitiesSirenResponse.
  Sends siren_command with has_tone=true.

- Volume: Writable NUMBER variable ({name} Volume, 0-100 in C4, normalized
  to 0.0-1.0 for ESPHome float field). Only created when supports_volume is
  true. Sends siren_command with has_volume=true.

- Duration: Writable NUMBER variable ({name} Duration, seconds as uint32).
  Only created when supports_duration is true. Sends siren_command with
  has_duration=true.

Also adds the Set Siren Tone command definition to driver.xml and updates
the changelog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant