Skip to content

Conversation

@emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Dec 1, 2025

Proposed change

Add occupancy binary sensor triggers

Tagged for 2025.12.0 to have a binary sensor show case in the December 2025 release

Note: Language is aligned with the changes in #157643

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Dec 1, 2025

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

Code owner commands

Code owners of automation can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign automation Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

home-assistant bot commented Dec 1, 2025

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

Code owner commands

Code owners of binary_sensor can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign binary_sensor Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jlpouffier Please check the text and also the trigger keys (binary_sensor.started_detecting_presence, binary_sensor.stopped_detecting_presence) are as you expect

Copy link
Member

@jlpouffier jlpouffier Dec 1, 2025

Choose a reason for hiding this comment

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

For the cover one, we used that convention: cover.shutter_opened
So let's try to use the same... meaning binary_sensor.presence_something_something

When it comes to the something something 😅 we can either be generic or find something that suits each device class best.
I would vote for the latter, and in that case, I would do

  • binary_sensor.presence_detected
  • binary_sensor.presence_cleared

It's both past tense, so it fits our model, and it's simpler to understand.

When it comes to the strings, I would align all of them to this.

Title: Presence Detected
Description: Triggers after one or several presence sensors start detecting presence

Title: Presence Cleared
Description: Triggers after one or several presence sensors stop detecting presence

(I struggled a bit to write something with the word "Cleared".
I think it's fine to have a different wording in the description than the title).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jlpouffier can you check again please?

Copy link
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 adds experimental presence detection triggers for binary sensors, enabling automations to fire when presence sensors start or stop detecting presence. The feature is gated behind the "New triggers and conditions" experimental flag.

Key changes:

  • Adds two new binary sensor triggers: started_detecting_presence and stopped_detecting_presence
  • Implements trigger filtering by presence device class
  • Provides comprehensive test coverage for trigger behaviors (any, first, last)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
homeassistant/components/binary_sensor/trigger.py Implements the presence binary sensor triggers with state change detection (has bugs: missing entity_filter override and incorrect docstrings)
homeassistant/components/binary_sensor/triggers.yaml Defines trigger configuration with behavior field and device_class filtering
homeassistant/components/binary_sensor/strings.json Adds user-facing translations for trigger names, descriptions, and behavior options
homeassistant/components/binary_sensor/icons.json Defines icons for the triggers (icons appear to be reversed)
homeassistant/components/automation/init.py Registers binary_sensor as an experimental trigger platform
tests/components/binary_sensor/test_trigger.py Provides comprehensive test coverage for trigger behaviors (missing device class filtering tests)

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

"title": "Binary sensor",
"triggers": {
"started_detecting_presence": {
"description": "Triggers after one ore more presence sensors start detecting presence.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the change from "Triggers when …" to "Triggers after …" intentional here?

It's making these inconsistent with all existing triggers and the "When" headline in the automation editor.

Copy link
Contributor

Choose a reason for hiding this comment

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

We currently use "Occupancy" for these sensors, for example in the Activity.

"Presence" is for people or device trackers with regard to zones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We currently use "Occupancy" for these sensors, for example in the Activity.

Can you clarify what activity you refer to?
Anyhow, I think you're right that the trigger should be for device class BinarySensorDeviceClass.OCCUPANCY instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, for the so-called "presence sensors" the device class in HA is BinarySensorDeviceClass.OCCUPANCY

@emontnemery
Copy link
Contributor Author

@NoRi2909 the language in this PR is aligned with the changes in #157643

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Code looks good. There are some open conversations above.

Copy link
Contributor

@NoRi2909 NoRi2909 left a comment

Choose a reason for hiding this comment

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

We need to change those two from "Presence" to "Occupancy" as well.

Otherwise this is highly inconsistent and will be indistinguishable from "Presence detected / cleared" for that other device class.

If we want to keep "presence sensors" in the wording, then this could be in the description using:
"Triggers after one ore more presence sensors start detecting occupancy."

@emontnemery emontnemery changed the title Add presence binary sensor triggers Add occupancy binary sensor triggers Dec 2, 2025
},
"excluded": {
"state": state[0],
"attributes": state[1],
Copy link
Member

@MartinHjelmare MartinHjelmare Dec 2, 2025

Choose a reason for hiding this comment

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

There doesn't seem to be much difference between included and excluded states. It's not clear to me why we need the separation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The excluded state in the binary_sensor case don't have the wanted device class. For other domains it will be states without some capability attribute etc. The purpose is to check the filtering of entities which are not supported by the trigger is working.

@emontnemery emontnemery merged commit e63242e into dev Dec 2, 2025
60 checks passed
@emontnemery emontnemery deleted the add_presence_binary_sensor_trigger branch December 2, 2025 15:37
frenck pushed a commit that referenced this pull request Dec 2, 2025
"name": "Occupancy cleared"
},
"occupancy_detected": {
"description": "Triggers after one ore more occupancy sensors start detecting occupancy.",
Copy link
Contributor

Choose a reason for hiding this comment

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

We missed the typo "ore" instead of "or".

Copy link
Member

Choose a reason for hiding this comment

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

Fixing that in #157791

@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
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.

7 participants