Skip to content

Conversation

b3nn0
Copy link

@b3nn0 b3nn0 commented Sep 28, 2025

Hi,
this is a simple PR that adds an "await" around the filter function calling.

Motivation:

This allows especially the fn filter to define an async function.
This can be very useful, e.g. if you want to plot the result of a service call directly, without having to create intermediate template sensors just to deliver data to the frontend.
intermediate template sensors are sometimes not great when you want to display a lot of data, since the amount of bytes a state or state attributes can have is very limited (state 255 bytes AFAIK, and state attributes 16kb).
This limitation is there for a good reason: home-assistant/core#149316 (comment)

Also, they fill up your recorder with information that might not be desirable to be stored long term.

With this PR, it is now possible to do this:

    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)
            }
          }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant