-
-
Notifications
You must be signed in to change notification settings - Fork 35k
Add slugify as a template filter #58724
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
Conversation
Thank you! It's a long-standing Feature Request: |
@ZephireNZ A wild merge conflict appeared out of nowhere! 🙈 |
Just out of curiosity, how is this intended to be used? |
Fixed merge conflict, did it in the GitHub UI so here's hoping I've not messed up the formatting checks 😅 |
My use case: I want to create an automation that changes my lights to a scene I created previously, based on the TV show playing. Now, I could create a buuuunch of case statements in that automation, each with their own service call for specific lights/scenes, but that's very tedious to say the least. As far as I could tell, there's no simple way to find an entity based on its name - so my idea is to do the same slugification of the show name, and check if a I am sure there are other use cases too, but that's my own. |
@frenck all good to merge now 😊 |
States have a name attribute: {{ states.light.desk_lamp.name }} |
@ZephireNZ The use case you describe has the problem I mentioned: There's no guarantee that an entity's
Edit: Your example use case should be solved by looping over the available scene states, finding the scene with the right name. |
I agree that the use case is incorrect and probably not the best example for advertising/adding a feature. |
@tdejneka what was your use case? |
d9c5408
to
76e4b7d
Compare
Rebased the PR to deal with a merge conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so the use-case described is wrong. You should not use the slugify method to "guess" entity IDs (there are many other method for that as shown above).
Nevertheless, we have discussed this on Discord and there are some cases where this can be useful. E.g., when needing an action key based on a title in an actional notification; working with REST APIs.
The use cases for these are fairly limited, but this addition is fairly clean as well.
Therefore accepting this addition. Thanks @ZephireNZ 👍
Thanks! I knew it was a useful addition, just couldn't come up with a good example use case 😅 |
Proposed change
This adds a
slugify
filter for templates. This is useful, for example, if you have a string and want to translate it to aentity_id
.Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: