Add support for this.entity_id. Fix #45, enable #54

This commit is contained in:
Thomas Lovén 2019-12-10 09:43:52 +01:00
parent 9a03e251fa
commit 161300d7e9
3 changed files with 47 additions and 2 deletions

View File

@ -170,6 +170,9 @@ sort:
- `attribute:` Attribute to sort by if `method: attribute`. Can be an *object attribute* as above (e.g. `attribute: rgb_color:2`)
- `first` and `count` can be used to only display `<count>` entities, starting with the `<first>` (starts with 0).
## Entity options
In the `options:` option of the filters, the string `this.entity_id` will be replaced with the matched entity_id. Useful for service calls - see below.
## Examples
Show all entities, except yahoo weather, groups and zones in a glance card:
@ -261,5 +264,37 @@ filter:
- device: /iPhone/
```
List the five last triggered motion sensors:
```yaml
type: custom:auto-entities
card:
type: entities
filter:
include:
- domain: binary_sensor
attributes:
device_class: motion
sort:
method: last_changed
count: 5
```
Turn on scenes by clicking them:
```yaml
type: custom:auto-entities
card:
type: glance
filter:
include:
- domain: scene
options:
tap_action:
action: call-service
service: scene.turn_on
service_data:
# Note the magic value this.entity_id here
entity_id: this.entity_id
```
---
<a href="https://www.buymeacoffee.com/uqD6KHCdJ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

File diff suppressed because one or more lines are too long

View File

@ -59,7 +59,17 @@ class AutoEntities extends LitElement {
}
let add = all_entities.filter(entity_filter(this.hass, f))
.map((e) => new Object({...e, ...f.options}));
.map((e) =>
JSON.parse(
JSON.stringify(
new Object({
...e,
...f.options
})
)
.replace(/this.entity_id/g, e.entity)
)
);
if(f.sort !== undefined) {
// Sort per filter