Skip to content

flatten not consistently working for template sensor #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DarthSonic opened this issue May 12, 2024 · 5 comments
Open

flatten not consistently working for template sensor #762

DarthSonic opened this issue May 12, 2024 · 5 comments

Comments

@DarthSonic
Copy link

What version of Spook are you using?

3.0.1

What version of Home Assistant are you using?

2024.5.3

The problem

I created a template sensor in configuration. yaml. I am using flatten within the state template. When loading the yaml in developer tools, everything works. When restarting HA, the sensor gets unavailable and error log shows that flatten function is unknown.

Is there a way to overcome that issue?

Anything in the logs? Paste it here!

No response

@caphm
Copy link

caphm commented Aug 8, 2024

I've got the same issue. I'm using flatten filter in a template within a script. Home assistant disables that script because it claims it could not be validated:
„invalid template (TemplateAssertionError: No filter named 'flatten'.) for dictionary value @ data['sequence'][1]['variables']['result']. Got '{{ { "entity_id": (entities + areas|map("area_entities")|flatten + labels|map("label_entities")|flatten)|unique|list } }}'“.

@Phileep
Copy link

Phileep commented Jan 17, 2025

I have the same issue with the shuffle helper being used in scripts.

After restart, the script is disabled as invalid due to shuffle being used.

relevant log excerpts:

2025-01-17 08:32:43.613 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration spook which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2025-01-17 08:32:43.615 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration spook_inverse which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2025-01-17 08:34:24.252 ERROR (MainThread) [homeassistant.components.script] Script with alias 'dont stop the music' could not be validated and has been disabled: invalid template (TemplateAssertionError: No filter named 'shuffle'.) for dictionary value @ data['sequence'][0]['variables']['artist_list']. Got '{{ (( state_attr("input_select.music_artists_favourite","options")  |  shuffle | list )[:(number_of_artists - random_artists_tracks )]  + ( state_attr("input_select.music_artists","options")  | shuffle | list )[:(random_artists_tracks )] | shuffle) }}\n'

Running spook v 3.1.0 installed via HACS.
Home assistant core 20251.2

To get it working again I need to touch the script and then it usually will validate ok and work again.

@jeverley
Copy link

jeverley commented Feb 13, 2025

I'm also encountering this issue when trying to flatten the list returned from device_trackers.
It works perfectly fine, but is flagged by Spook on startup with (TemplateAssertionError: No filter named 'flatten'.)

I've found that the following filter works as an alternative in my use case (to flatten a list of lists):

| reject("none") | sum(start=[])

@frenck
Copy link
Owner

frenck commented Mar 6, 2025

Unfortunately, not something I think I can fix.

The problem is timing in how Spook hooks into Home Assistant.
At this point, I have come to the conclusion that offering templating methods this way is not feasible. I'm looking into seeing if we can move some of these methods directly into the Home Assistant project and removing them from Spook.

../Frenck

@SLaks
Copy link

SLaks commented Mar 17, 2025

home-assistant/core#140157 fixes this

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

No branches or pull requests

6 participants