Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "at_least" and "at_most" actions to the Timer integration #139049

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

kevinbackhouse
Copy link

@kevinbackhouse kevinbackhouse commented Feb 22, 2025

Breaking change

Proposed change

Add two new actions to the Timer integration: "at_least" and "at_most". These features were suggested here (not by me, but I also think they would be very useful).

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

  • 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.

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:

@kevinbackhouse
Copy link
Author

Thanks @StaleLoafOfBread. I've added a commit that renames the methods as you suggested.

@kevinbackhouse kevinbackhouse changed the title Add "atleast" and "atmost" actions to the Timer integration Add "at_least" and "at_most" actions to the Timer integration Feb 28, 2025
@NoRi2909
Copy link
Contributor

NoRi2909 commented Feb 28, 2025

Following the conventions for actions in Home Assistants they should begin with a verb like all existing timer actions do.

So you should name them as

  • Set minimum
  • Set maximum

The "Duration" fields of both actions should then also become

  • Minimum
  • Maximum

as calling them "duration" is quite misleading: The actual timer duration may not change at all with these actions if it's either above or below the value given by the respective action.

This results in these action descriptions:

  • Increases the remaining timer duration if it's less than the given minimum.
  • Decreases the remaining timer duration if it's more than the given maximum.

@kevinbackhouse
Copy link
Author

@NoRi2909: thanks for the feedback. I'm happy to change the name so that it starts with a verb, but I worry that "set minimum" would be misleading because there isn't a field named "minimum" that's getting set. What do you think of these suggestions instead:

  • increase duration
  • change duration to at least
  • change with minimum
  • postpone/delay, expedite/accelerate

@NoRi2909
Copy link
Contributor

Perhaps we find the best name for the actions themselves if you go through my suggestions from the bottom up.

Then the fields "Minimum" and "Maximum" are given in the action (instead of the current "duration" in both) and their respective purpose is explained in the action descriptions.

@frenck
Copy link
Member

frenck commented Mar 2, 2025

Hi there @kevinbackhouse 👋

Thanks for opening a pull request. I don't know if this is something I would introduce to this component. To be sure this is not just limited to my opinion, I've scheduled this pull request for discussion in the next Core architectural meeting.

I will get back to you on the results of this in the upcoming week.

I'm marking this PR as a draft in the meantime.

../Frenck

@frenck frenck marked this pull request as draft March 2, 2025 19:26
@kevinbackhouse
Copy link
Author

@frenck: Thanks for taking a look! To give you an example of why I think this feature would be useful, my house has a short corridor with a door on each end:

 -------------
\             \
 ------------- 

If the door on the left opens, I want to switch on a light in the corridor for the next 5 minutes. And if the door on the right opens, I want to switch on the light for the next 2 minutes. Timers are a very useful intermediary for this kind of thing because they let me check how much time is left on the clock. But the logic for doing so in YAML is quite cumbersome:

  - if:
      - condition: template
        value_template: >-
          {{ as_datetime(state_attr('timer.mytimer','finishes_at')) < now() +
          timedelta(120) }}
    then:
      - action: timer.start
        metadata: {}
        data:
          duration: "120"
        target:
          entity_id: timer.mytimer

And that snippet doesn't even include the logic for handling idle or paused timers. But besides the yaml solution being clunky, this feels to me like an operation that should be atomic. I'm not sure if home assistant is multi-threaded and able to run two automations in parallel, but in that scenario the yaml above would have a race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants