Skip to content

Always emit triggering room context for HA scene/script activations#375

Open
jamesmulcahy wants to merge 3 commits intoNSPManager:develfrom
jamesmulcahy:ha-scene-triggering-room
Open

Always emit triggering room context for HA scene/script activations#375
jamesmulcahy wants to merge 3 commits intoNSPManager:develfrom
jamesmulcahy:ha-scene-triggering-room

Conversation

@jamesmulcahy
Copy link
Copy Markdown
Contributor

@jamesmulcahy jamesmulcahy commented May 3, 2026

Summary

  • When activating a Home Assistant script., always include scene_name, scene_id, triggering_room_id, triggering_room_name, scene_room_id, and scene_room_name in the nspanelmanager variables context
  • Previously, room context was only sent for room-specific scenes; global scenes received no room information
  • Global scenes now receive the room of the panel that triggered them, allowing HA scripts to take room-specific actions while remaining globally defined
  • Panels browsing another room's scene page correctly report the panel's own room as the triggering room

Implementation

  • Added activate(std::optional<int32_t> triggering_room_id) to the Scene base class; all scene subclasses updated to match
  • EntityManager resolves the triggering room from the nspanel_id in the command via a new get_room_id_for_panel_id() helper
  • NSPanel hardware button presses pass the panel's own room directly
  • Scene::toggle() (no-arg) is retained to satisfy MqttManagerEntity's pure virtual, but all real activations now go through activate() directly

Test plan

  • Global scene triggered from home panel — triggering_room_id matches panel's room
  • Room-specific scene triggered from its own room — both triggering_room_* and scene_room_* populated
  • Room-specific scene triggered from a panel in a different room — triggering_room_* reflects the triggering panel's room, scene_room_* reflects the scene's own room
  • scene. entity type (non-script) — unaffected, no context sent

🤖 Generated with Claude Code

When activating a Home Assistant script, always include scene_name, scene_id,
and (where available) triggering_room_id/name and scene_room_id/name in the
nspanelmanager variables context. Previously room context was only sent for
room-specific scenes. Global scenes now also receive the room of the panel
that triggered them, allowing HA scripts to take room-specific actions while
remaining globally defined.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jamesmulcahy
Copy link
Copy Markdown
Contributor Author

Example contexts:

Triggering a room scene, from a panel in a different room

{
  "scene_id": 50,
  "scene_name": "Source Vol Up",
  "scene_room_id": 3,
  "scene_room_name": "Kitchen",
  "triggering_room_id": 1,
  "triggering_room_name": "Master Bedroom"
}

Triggering a room scene, from a panels own room scenes

{
  "scene_id": 59,
  "scene_name": "Room Vol Up",
  "scene_room_id": 1,
  "scene_room_name": "Master Bedroom",
  "triggering_room_id": 1,
  "triggering_room_name": "Master Bedroom"
}

Triggering a global scene

{
  "scene_id": 63,
  "scene_name": "Src Vol Down",
  "triggering_room_id": 1,
  "triggering_room_name": "Master Bedroom"
}

@jamesmulcahy
Copy link
Copy Markdown
Contributor Author

@tpanajott As I started to integrate the room name into my HA scripts, I realized that I needed the triggering room name -- not just the room the scene was associated with. This is especially important for global scenes, which weren't otherwise emitting any room context.

This new approach covers all three scenarios, as outlined with the examples above.

return std::unexpected(EntityManager::EntityError::NOT_FOUND);
}

std::optional<int32_t> EntityManager::get_room_id_for_panel_id(uint32_t nspanel_id) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using std::optional here a better use would be std::expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: std:expected -- that didn't exist last time I wrote C++ :)

I pushed a commit on top to move to std::expected -- PTAL!

jamesmulcahy and others added 2 commits May 3, 2026 14:39
Aligns with the existing pattern used by all other EntityManager lookups.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants