Skip to content

Commit

Permalink
Add documentation, bump version for entity attribute configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rianadon committed Jun 25, 2021
1 parent e3bc3c2 commit b8f864c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,33 @@ You can find a subset of these attributes in the entity popup, and a full list b
#### 1. My entity has an attribute that looks like `duration` (for example, `timespan`). Supply the following configuration:

```yaml
duration: { attribute: "timespan" }
duration: { attribute: "timespan" } # If your your duration attribute looks like 0:10:00.
debug: true
```

The entity's start time will be computed using the `last_changed` property (when the entity state last changed).

#### 2. The time last changed doesn't approximate the start time well enough, and my entity has a duration-looking attribute and a start time attribute (called `start`).
#### 2. My `duration` isn't in the `0:10:00` format! I need to use different units!

Use the `units` property and specify `seconds`, `hours`, or `minutes`. The default value of `units` is `duration`, which expects colons in the duration.

```yaml
duration:
attribute: "timespan" # Should look like 10 or 10.0
units: minutes
debug: true
```


#### 3. The time last changed doesn't approximate the start time well enough, and my entity has a duration-looking attribute and a start time attribute (called `start`).

```yaml
duration: { attribute: "timespan" }
start_time: { attribute: "start" }
debug: true
```

#### 3. The entity has no duration attribute but it has start time and end time (`finishes_at`) attributes.
#### 4. The entity has no duration attribute but it has start time and end time (`finishes_at`) attributes.

```yaml
start_time: { attribute: "start" }
Expand All @@ -167,7 +179,7 @@ debug: true

Duration will be computed as the difference between these two times.

#### 4. My entity has no attributes!
#### 5. My entity has no attributes!

Imagine we have a **switch**, that, through an automation, will always turn off **five minutes** later after it's turned on. *Timer bar card, can we do it? Yes we can!* All it needs is a fixed duration and some love. Always love.

Expand All @@ -182,7 +194,21 @@ duration: { fixed: 0:05:00 } # 5 min

Like in step 1, there is no `start_time` configured so the card will use the time the switch was last toggled as the start time.

#### 5. If your entity doesn't meet these criteria...
#### 6. My duration actually comes from another entity

So far, `duration` has taken on type `attribute` and `fixed`. But there's a third type: `entity`! Assume there's a duration slider with id `input_number.slider1`.

```yaml
type: custom:timer-bar-card
debug: true
entities:
- switch.my_switch # ID of the switch, which provides the active/idle status
duration:
entity: input_number.slider1
units: minutes # Since the slider state is a number like 10.0
```

#### 7. If your entity doesn't meet these criteria...

🧡 please create an issue and tell me the entity so I can improve these instructions! ❤️️

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lovelace-timer-bar-card",
"version": "1.4.0",
"version": "1.6.0",
"description": "Progress bar display for Home Assistant timers",
"keywords": [
"home-assistant",
Expand Down
9 changes: 5 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ interface modsConfig extends styleConfig {
greater_than_eq?: number;
}

export type AttributeType = { attribute: string } | { entity: string } | { fixed: number };
type AttributeType = { attribute: string } | { entity: string } | { fixed: number };
export type AttributeConfig = AttributeType & { units?: 'duration'|'hours'|'minutes'|'seconds' };
export type Translations = { [phrase: string]: string };

export interface TimerBarEntityConfig extends styleConfig {
Expand All @@ -42,9 +43,9 @@ export interface TimerBarEntityConfig extends styleConfig {
active_state?: string | string[];
pause_state?: string | string[];
waiting_state?: string | string[];
duration?: AttributeType;
start_time?: AttributeType;
end_time?: AttributeType;
duration?: AttributeConfig;
start_time?: AttributeConfig;
end_time?: AttributeConfig;
debug?: boolean;

modifications?: modsConfig[];
Expand Down

0 comments on commit b8f864c

Please sign in to comment.