Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,20 @@ entities:
- map_y: parseFloat(y) * parseFloat(hass.states['sensor.cost'].state)
```

This can also be used to fetch data by calling a HA service. As this is a call that requires a network connection, the function needs to be defined `async`:
```yaml
filters:
- fn: |-
async ({xs, ys, meta, hass}) => {
const weather = await hass.callService("weather", "get_forecasts", {type: "hourly"}, {entity_id:"weather.home"}, true, true)
const home = weather.response["weather.home"].forecast
return {
xs: home.map(h => new Date(h.datetime)),
ys: home.map(h => h.temperature)
}
}
```

##### Using vars

Compute absolute humidity
Expand Down
6 changes: 3 additions & 3 deletions src/parse-config/parse-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ConfigParser {
value = parent[key];

if (path.match(/^entities\.\d+\.filters\.\d+$/)) {
this.evalFilter({ parent, path, key, value });
await this.evalFilter({ parent, path, key, value });
}
if (path.match(/^entities\.\d+$/)) {
if (!this.fnParam.xs) {
Expand Down Expand Up @@ -330,7 +330,7 @@ class ConfigParser {
}
return value;
}
private evalFilter(input: {
private async evalFilter(input: {
parent: object;
path: string;
key: string;
Expand All @@ -356,7 +356,7 @@ class ConfigParser {
}
const filterfn = config === null ? filter() : filter(config);
try {
const r = filterfn(this.fnParam);
const r = await filterfn(this.fnParam);
for (const key in r) {
this.fnParam[key] = r[key];
}
Expand Down