Skip to content

Add documentation on conditions#2885

Draft
joostlek wants to merge 4 commits into
home-assistant:masterfrom
joostlek:conditions
Draft

Add documentation on conditions#2885
joostlek wants to merge 4 commits into
home-assistant:masterfrom
joostlek:conditions

Conversation

@joostlek

@joostlek joostlek commented Dec 2, 2025

Copy link
Copy Markdown
Member

Proposed change

Add documentation on conditions

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features for which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Changes to the backend of this documentation
  • Remove stale or deprecated documentation

Checklist

  • I have read and followed the documentation guidelines.
  • I have verified that my changes render correctly in the documentation.

Additional information

  • This PR fixes or closes issue: fixes #
  • Link to relevant existing code or pull request:

Summary by CodeRabbit

  • Documentation
    • Added a comprehensive Conditions section with guidance and practical examples for implementing and registering conditions.
    • Included schema validation and frontend configuration guidance for condition declarations.
    • Refined trigger wording for improved clarity.

@coderabbitai

coderabbitai Bot commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb1638a1-51eb-4d53-bdf6-ec8bfbacd3b5

📥 Commits

Reviewing files that changed from the base of the PR and between 04a8901 and 23a6754.

📒 Files selected for processing (1)
  • docs/automations.md
✅ Files skipped from review due to trivial changes (1)
  • docs/automations.md

📝 Walkthrough

Walkthrough

Documentation-only update to docs/automations.md that revises trigger wording and adds a new "Conditions" section with examples and guidance for implementing, validating, registering, and integrating condition classes and schemas.

Changes

Documentation

Layer / File(s) Summary
Conditions documentation
docs/automations.md
Adds a "Conditions" section describing async_validate_config and async_get_checker, example Condition classes (including DoorStateConditionBase), async_get_conditions registration example, and a frontend conditions.yaml-style schema snippet.
Trigger wording tweak
docs/automations.md
Updates trigger wording from "the example above" to "the following example."

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding documentation on conditions, which directly matches the primary purpose of this documentation-only pull request.
Description check ✅ Passed The description follows the template structure with 'Proposed change' and 'Type of change' sections completed, but the 'Checklist' and 'Additional information' sections are incomplete with unchecked items and placeholder values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
docs/automations.md (2)

168-172: Strengthen instructional phrasing by fronting the goal.

Line 170 uses passive voice and defers the goal. Restructure to front the action for clarity and directness, consistent with documentation guidelines.

Apply this diff to improve the instructional phrasing:

-To register the conditions `async_get_conditions` should be implemented in the `condition` platform for that integration.
+Implement `async_get_conditions` in the `condition` platform to register conditions.

181-187: Optional: Make schema explanation more direct.

While clear, line 183 could be more authoritative by fronting the goal rather than describing frontend behavior.

Apply this diff for a more direct tone:

-The frontend uses the `conditions.yaml` file to know the structure of the conditions.
-This file is similar to `triggers.yaml` and `services.yaml`.
+Define the condition structure in `conditions.yaml` for the frontend, similar to `triggers.yaml` and `services.yaml`.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 40fdc6a and 6e41ad9.

📒 Files selected for processing (1)
  • docs/automations.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
*/**(html|markdown|md)

⚙️ CodeRabbit configuration file

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

  • Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • Use sentence-style capitalization also in headings.

do not comment on HTML used for icons

Avoid flagging inline HTML for embedding videos in future reviews for this repository.

Files:

  • docs/automations.md
🔇 Additional comments (3)
docs/automations.md (3)

88-88: Good phrasing adjustment.

The change from "example above" to "the following example" correctly describes the position of the code that immediately follows.


99-107: Clear and well-structured introduction to conditions.

The section frontloads the implementation goal and correctly references the trigger class pattern for consistency.


188-198: YAML example is well-structured and accurate.

The schema correctly represents the Python condition implementation and follows the expected structure for condition definitions.

Comment thread docs/automations.md
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
docs/automations.md (1)

127-131: Voluptuous schema syntax is correct.

The vol.In() validator now correctly accepts a single iterable argument. This resolves the prior critical issue flagged in previous reviews.

🧹 Nitpick comments (1)
docs/automations.md (1)

168-171: Align condition registration wording with trigger registration for consistency.

The conditions section should use the same direct imperative style as the parallel triggers section. Currently, line 170 uses passive construction ("should be implemented") while the triggers section uses active voice ("Implement").

Apply this diff to match the triggers section pattern:

-To register the conditions `async_get_conditions` should be implemented in the `condition` platform for that integration.
+Implement `async_get_conditions` in the `condition` platform to register all the integration's conditions.

As per coding guidelines, documentation should use a direct and authoritative tone with frontloaded goals.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 6e41ad9 and 04a8901.

📒 Files selected for processing (1)
  • docs/automations.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
*/**(html|markdown|md)

⚙️ CodeRabbit configuration file

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

  • Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • Use sentence-style capitalization also in headings.

do not comment on HTML used for icons

Avoid flagging inline HTML for embedding videos in future reviews for this repository.

Files:

  • docs/automations.md
🔇 Additional comments (2)
docs/automations.md (2)

111-166: Condition class example is well-structured.

The code implementation properly demonstrates the required methods (async_validate_config and async_get_checker), includes appropriate type hints, and provides clear comments explaining the logic. The schema definition is correct.


181-198: Condition schema documentation and example are clear.

The explanation of conditions.yaml and its relationship to related files provides helpful context. The YAML example correctly demonstrates the door_state condition schema structure with appropriate field definitions and selectors.

Comment thread docs/automations.md Outdated

## Conditions

Conditions are checks that must be met in order for an automation to trigger. Implement them in the `condition` platform (`condition.py`) of your integration by creating and registering condition classes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would be more specific with the language here. The automation triggers when its trigger is triggered, then the automation checks any conditions, and if they are met or if there are no conditions, the automation action will be done.

@MartinHjelmare MartinHjelmare marked this pull request as draft December 7, 2025 10:38
Comment thread docs/automations.md Outdated
Comment thread docs/automations.md Outdated
Comment thread docs/automations.md Outdated
Comment thread docs/automations.md Outdated
Comment thread docs/automations.md Outdated
Comment thread docs/automations.md Outdated
Comment thread docs/automations.md Outdated
@joostlek joostlek marked this pull request as ready for review June 8, 2026 13:40
Comment thread docs/automations.md
## Conditions

When an automation is triggered, it may have conditions that have to be met for the action to be executed.
Conditions are created in the `condition` platform (`condition.py`) of your integration by creating and registering condition classes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Conditions are created in the `condition` platform (`condition.py`) of your integration by creating and registering condition classes.
Conditions are defined in the `condition` platform (`condition.py`) of your integration by creating and registering condition classes.

Comment thread docs/automations.md
self._state = config.options[CONF_STATE]

@override
async def async_get_checker(self) -> ConditionChecker:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is stale since home-assistant/core#168815

Comment thread docs/automations.md
Comment on lines +162 to +165
# In reality this would be more configurable
# but for the sake of example it's simplified.
return self._hass.states.get("binary_sensor.front_door") == self._state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# In reality this would be more configurable
# but for the sake of example it's simplified.
return self._hass.states.get("binary_sensor.front_door") == self._state
# Do your condition checks here
return get_example_state() == self._state

Comment thread docs/automations.md
)
from homeassistant.helpers.typing import ConfigType, TemplateVarsType

STATE_CONDITION_SCHEMA = vol.Schema(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

condition-specific fields should be in the CONF_OPTIONS object, right?

Comment thread docs/automations.md
ConditionChecker,
ConditionCheckParams,
ConditionConfig,
trace_condition_function,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
trace_condition_function,

Comment thread docs/automations.md

### Condition schema

The frontend uses the `conditions.yaml` file to know the structure of the conditions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it is also used by core, not just for frontend

@home-assistant home-assistant Bot marked this pull request as draft June 19, 2026 19:03
@home-assistant

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

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.

4 participants