-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Enhance timer.markdown with attributes and examples #41580
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
Draft
mik-laj
wants to merge
10
commits into
home-assistant:current
Choose a base branch
from
mik-laj:patch-8
base: current
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f090cf
Enhance timer.markdown with attributes and examples
mik-laj 31e36a2
Change note syntax for timer documentation
mik-laj a36c0e9
Update source/_integrations/timer.markdown
mik-laj e2b712f
Update source/_integrations/timer.markdown
mik-laj 9a24940
Update source/_integrations/timer.markdown
mik-laj 6dbcef4
Update source/_integrations/timer.markdown
mik-laj 28ea247
Update source/_integrations/timer.markdown
mik-laj 8cec833
Fixup
mik-laj 9e4e054
Fix formatting issues in timer attributes section
mik-laj 0bef3c6
Add description for 'editable' timer attribute
mik-laj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,20 @@ Pick an icon from [Material Design Icons](https://pictogrammers.com/library/mdi/ | |
| | `timer.restarted` | Fired when a timer has been restarted | | ||
| | `timer.paused` | Fired when a timer has been paused | | ||
|
|
||
| ## Attributes | ||
|
|
||
| Each `timer` entity provides a few useful attributes that describe its current configuration and runtime. | ||
|
|
||
| - `duration`: Total configured length of the timer, in seconds or `HH:MM:SS` | ||
| - `remaining`: How much time is left when the timer is active or paused; updates only when paused, restarted, or canceled | ||
| - `finishes_at`: The timestamp when the timer will finish; available only when running | ||
| - `restore`: Whether the timer will resume after a Home Assistant restart | ||
| - 'editable': Whether the timer are manageable by UI | ||
|
|
||
| {% note %} | ||
| The `remaining` value does not count down in real time. For dynamic countdowns or dashboards, rely on the `finishes_at` attribute. | ||
| {% endnote %} | ||
|
|
||
| ## Actions | ||
|
|
||
| ### Action `timer.start` | ||
|
|
@@ -135,6 +149,51 @@ Reload `timer`'s configuration without restarting Home Assistant itself. This ac | |
|
|
||
| Navigate to **Developer Tools** > **Actions** and select the `timer.start` action, then click the **Fill Example Data** button. Now change the `entity_id` and `duration` and select **Perform action** button. | ||
|
|
||
| ## Templates | ||
|
|
||
| Timers can be combined with templates to show remaining time or end time dynamically. | ||
|
|
||
| ### Remaining time | ||
|
|
||
| Create a template sensor that calculates how long the timer has left. | ||
| It uses the `finishes_at` timestamp to compute the difference between now and the expected end. | ||
|
|
||
| {% raw %} | ||
|
|
||
| ```yaml | ||
| template: | ||
| - sensor: | ||
| - name: "Laundry Timer - Remaining" | ||
| state: > | ||
| {% set fin = state_attr('timer.laundry', 'finishes_at') %} | ||
| {% if fin %} | ||
| {% set s = (as_datetime(fin) - now()).total_seconds() | int %} | ||
| {{ (s if s > 0 else 0) | timestamp_custom('%H:%M:%S', false) }} | ||
| {% else %} | ||
| 00:00:00 | ||
| {% endif %} | ||
| ``` | ||
| {% endraw %} | ||
|
|
||
| ### End time | ||
|
|
||
| A simpler version that shows when the timer will finish. | ||
| With `device_class: timestamp`, it displays as a proper time value in the dashboard. | ||
|
|
||
| {% raw %} | ||
|
|
||
| ```yaml | ||
| template: | ||
| - sensor: | ||
| - name: "Laundry Timer - Ends at" | ||
| state: > | ||
| {% set fin = state_attr('timer.laundry', 'finishes_at') %} | ||
| {{ as_datetime(fin) if fin else none }} | ||
| device_class: timestamp | ||
| ``` | ||
|
|
||
| {% endraw %} | ||
|
|
||
| ## Examples | ||
|
|
||
| Set a timer called `test` to a duration of 30 seconds. | ||
|
|
@@ -207,3 +266,47 @@ script: | |
| target: | ||
| entity_id: timer.test | ||
| ``` | ||
|
|
||
| ### Motion light with auto-off | ||
|
|
||
| The light turns on when motion is detected and stays on while movement continues. | ||
| When motion stops and the timer finishes, the light turns off. | ||
|
|
||
| ```yaml | ||
| alias: Motion-Activated Hall Light | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I specifically used trigger_id to have an example of how to handle two events in one automation, which is useful when you manages automations in the UI. |
||
| description: >- | ||
| Turn on hall light when motion is detected and turn it off after 2 minutes of | ||
| inactivity. | ||
| triggers: | ||
| - trigger: state | ||
| entity_id: binary_sensor.motion_hall | ||
| to: "on" | ||
| id: motion_on | ||
| - trigger: event | ||
| event_type: timer.finished | ||
| event_data: | ||
| entity_id: timer.hall_light | ||
| id: timer_done | ||
| actions: | ||
| - choose: | ||
| - conditions: | ||
| - condition: trigger | ||
| id: motion_on | ||
| sequence: | ||
| - action: light.turn_on | ||
| target: | ||
| entity_id: light.hall | ||
| - action: timer.start | ||
| target: | ||
| entity_id: timer.hall_light | ||
| data: | ||
| duration: "00:02:00" | ||
| - conditions: | ||
| - condition: trigger | ||
| id: timer_done | ||
| sequence: | ||
| - action: light.turn_off | ||
| target: | ||
| entity_id: light.hall | ||
| ``` | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related code: https://github.com/home-assistant/core/blob/42e01362a5b204dd5cd3961ef45399dd626cce12/homeassistant/components/timer/__init__.py#L249-L262