Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejeffreystone/03707f2a8ce0d1eceb3023c8c3109bc0 to your computer and use it in GitHub Desktop.
Save thejeffreystone/03707f2a8ce0d1eceb3023c8c3109bc0 to your computer and use it in GitHub Desktop.
Useful Jinja Filters
# For more on these and more visit: https://ttl255.com/jinja2-tutorial-part-4-template-filters/
# Covert Previous value to integter
| int
# Convert previous value to a decimal number,
# Replace 0 with number of decimals to include
| float(0)
# Round value to a specific decimal
| round(1)
# Set a default value
| default(0)
#OR include with round
| round(0, default=0)
# Count the number of distinct entities in previous value
| count
# List all the entities in the prvious value
| list
# pick a previous value by random
| random
# Replace some in the previous value
| replace(":", "")
# Filter to just a specific attribute
| map(attribute='entity_id')
# select entities with a specitifc attribute value
| selectattr('state', 'eq', 'unavailable')
# select entities with a specitifc attribute value
| rejectattr('state', 'eq', 'unavailable')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment