A new action finds the threshold that fits a yes/no sensor, from its recorded history - #25
Merged
Merged
Conversation
A test window with the door open for two minutes returned hours_true 0.0 beside times_true 1, which read as the never-true refusal failing to fire. Both hour counts now keep two places, so the same window reads 0.03.
# Conflicts: # tests/test_services.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A new action,
jev.calibrate, finds a threshold for a noul sensor from what happened in the house.It reads the recorder for two entities over the last
days(default 7):entity_idis a probability sensor, such as a Jev noul sensor.truth_entity_idshows what was really true, such as a door contact or a plug that reports when a machine runs.truth_state(defaulton) is the state that means yes.The action cuts the window at every change of either entity. For each threshold from 0.01 to 0.99 it measures, weighted by time:
It returns the threshold with the highest F1. When several thresholds tie, it returns the middle one. The response also has
hours,hours_true,times_true,probability_changes, and a table at 0.1 steps, so the caller can see how much evidence the result has.The action does not call TypeSafe, so it costs no tokens. The test asserts that
askis not awaited.The default of 7 days is inside the recorder's default
purge_keep_daysof 10. The action has no upper limit, because a longer window only reads further back.Errors, with text in strings.json and all 13 translations:
calibrate_needs_recorder: the recorder is not running.calibrate_no_history: no time in the window has both a number and a truth state.calibrate_never_trueandcalibrate_always_true: with only one side, every threshold gives the same score.recorderis added toafter_dependencies.Gate (
ruff,mypy --strict,pytest,mkdocs --strict,hassfest): exit 0. 418 passed, 12 skipped, coverage 97.03%.calibrate.pyis at 100%, andconfig_flow.pyis at 100%.