Skip to content

Docs: state triggers only fire when a value changes (#864) - #914

Merged
craigbarratt merged 2 commits into
custom-components:masterfrom
HoneyBearTech:docs-state-trigger-changes-864
Nov 21, 2026
Merged

craigbarratt merged 2 commits into
custom-components:masterfrom
HoneyBearTech:docs-state-trigger-changes-864

Conversation

@HoneyBearTech

Copy link
Copy Markdown
Contributor

Refs #864

What was missing
@state_trigger and its watch= argument only evaluate when a watched value actually changes (ident_any_values_changed compares the old and new values). So a sensor that reports the same value again, for example with force_update: true, never fires them. The docs didn't say so.

What I changed
A short note in the watch description in docs/reference.rst. It shows watching the last_updated attribute to trigger on every update, as found in the issue:

@state_trigger("True", watch=["sensor.my_sensor.last_updated"])

This covers option 1 of the issue (document the behaviour). It doesn't add a new argument.

Testing
sphinx-build -W builds the docs with no warnings, and codespell is clean.

@state_trigger and its watch= argument only evaluate when a watched value
or attribute changes, so a sensor that repeats the same value (for example
with force_update) never fires them. The docs read as if every update did.
Say so, and show watching the last_updated attribute to trigger on every
update. Refs custom-components#864.

Signed-off-by: Sean Stoube <[email protected]>

@craigbarratt craigbarratt left a comment

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.

Thanks @HoneyBearTech, this is accurate.

One small wording suggestion: "to trigger on every update" works for force_update: true sensors, since HA then fires state_changed with a new last_updated. A sensor without force_update that repeats the same state and attributes only changes last_reported. HA then fires state_reported, which pyscript doesn't listen to, so nothing triggers. Maybe "to trigger on every forced update"? Fine to merge either way.

@HoneyBearTech

Copy link
Copy Markdown
Contributor Author

@craigbarratt thanks! Changed it to "every forced update".

@craigbarratt
craigbarratt merged commit e1ff103 into custom-components:master Nov 21, 2026
6 checks passed
@craigbarratt

Copy link
Copy Markdown
Member

Thanks!

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