Skip to content

Commit

Permalink
Add state attribute for computing end time
Browse files Browse the repository at this point in the history
  • Loading branch information
rianadon committed Sep 12, 2021
1 parent 6ba2c53 commit a1b44c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ duration:
units: minutes # Since the slider state is a number like 10.0
```

#### 7. If your entity doesn't meet these criteria...
#### 7. My end time comes from the entity's state

End times and durations can use any of the types `attribute`, `fixed`, `entity` (you've seen these 3 before) and `state`! The `state` type uses the entity's current state. Let's say we have a timer who's state is the time it will go off, like `2021-09-07T20:24:13+00:00`! Here's how to configure the card:

```yaml
end_time: { state: true }
```

#### 8. 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
1 change: 1 addition & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const attribute = (hass: HomeAssistant, stateObj: HassEntity, attrib: Att
if (!attrib) throw new Error('One of duration, start_time, or end_time was not fully specified. Make sure you set entity, fixed, or attribute');
if ('fixed' in attrib) return attrib.fixed;
if ('entity' in attrib) return hass.states[attrib.entity].state;
if ('state' in attrib) return stateObj.state;
return stateObj.attributes[attrib.attribute];
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface modsConfig extends styleConfig {
type AttributeType =
| { attribute: string }
| { entity: string }
| { state: any }
| { fixed: number };
export type AttributeConfig = AttributeType & {
units?: "duration" | "hours" | "minutes" | "seconds";
Expand Down

0 comments on commit a1b44c3

Please sign in to comment.