Skip to content

Fix time trigger crash when using entity_id dict format without offset#171006

Merged
balloob merged 3 commits into
devfrom
frenck-2026-0574
May 17, 2026
Merged

Fix time trigger crash when using entity_id dict format without offset#171006
balloob merged 3 commits into
devfrom
frenck-2026-0574

Conversation

@frenck
Copy link
Copy Markdown
Member

@frenck frenck commented May 17, 2026

Proposed change

When a time trigger uses the dict format with entity_id but without offset:

trigger:
  - trigger: time
    at:
      - entity_id: sensor.next_alarm

The trigger crashes with AttributeError: 'NodeDictClass' object has no attribute 'hour'. This happens because the runtime code only handles dicts when offset is present (isinstance(at_time, dict) and CONF_OFFSET in at_time), even though the schema correctly declares offset as optional. When offset is missing, the dict falls through to the datetime.time branch which tries to access .hour on it.

The fix removes the CONF_OFFSET in at_time guard so all entity_id dicts are handled correctly. The offset already defaults to timedelta(0) via .get().

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings May 17, 2026 17:38
@frenck frenck requested a review from a team as a code owner May 17, 2026 17:38
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (homeassistant) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of homeassistant can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign homeassistant Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@frenck frenck added this to the 2026.5.3 milestone May 17, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a crash in the time trigger when at is configured using the dict/entity_id form without an offset, ensuring dict entries are handled consistently with the schema (where offset is optional).

Changes:

  • Treat all dict-form at entries as entity-based triggers (offset defaults to timedelta(0)).
  • Add a regression test covering dict-form at without an offset.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/homeassistant/triggers/time.py Fix dict handling in the runtime trigger setup to avoid falling through to the datetime.time branch.
tests/components/homeassistant/triggers/test_time.py Add regression coverage for at: { entity_id: ... } without offset.
Comments suppressed due to low confidence (1)

homeassistant/components/homeassistant/triggers/time.py:275

  • Use direct key access for CONF_ENTITY_ID since the schema requires it, so invalid dict entries fail fast instead of silently defaulting to an empty entity_id.
            # entity with offset
            entity_id: str = at_time.get(CONF_ENTITY_ID, "")
            offset: timedelta = at_time.get(CONF_OFFSET, timedelta(0))
            update_entity_trigger(

Comment thread homeassistant/components/homeassistant/triggers/time.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 17, 2026 17:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread homeassistant/components/homeassistant/triggers/time.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 17, 2026 20:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@balloob balloob merged commit f7cf279 into dev May 17, 2026
45 checks passed
@balloob balloob deleted the frenck-2026-0574 branch May 17, 2026 21:13
@github-actions github-actions Bot locked and limited conversation to collaborators May 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Time trigger creates an exception when using a dictionary without an offset

3 participants