Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejeffreystone/54df3dec788df5170998416ac9a1ed47 to your computer and use it in GitHub Desktop.
Save thejeffreystone/54df3dec788df5170998416ac9a1ed47 to your computer and use it in GitHub Desktop.
Jinja Template Examples
# Get State of entity
{{ states('light.desk_backlight')}}
# Get Attribute Value
{{ state_attr('light.desk_backlight','energy')}}
# Do Mathy stuff - remeber PEMDAS
{{ ((states('sensor.basement_air_device_temperature') | int - 32) / 1.8) | round }}
# Get list of cameras, remove unavailable ones, list them and count them
{{ states.camera | rejectattr('state', 'eq', 'unavailable') | list | count }}
# Get list of sensors:
{{ states.sensor | rejectattr('state', 'eq', 'unavailable') | list | count }}
# Pick a random string for a notification
{{ [
'Maison Des Lunes Emergency Alert!',
'Maison Des Lunes, We have a problem!',
'You might not like this.',
'There is something that needs your attention.'
] | random }}
# Pick a random music track to play
{{["http://192.168.7.40/Liberty_square_audio.mp3",
"http://192.168.7.40/adventureland_loop.mp3",
"http://192.168.7.40/be_our_guest.mp3",
"http://192.168.7.40/epcot_entrance_loop.mp3",
"http://192.168.7.40/frontierland_loop.mp3",
"http://192.168.7.40/tomorrowland_loop.mp3",
"https://www.youtube.com/watch?v=IyWlxq2kOvw",
"https://www.youtube.com/watch?v=ngRdzcvr0rg",
"https://youtu.be/UW9WKIvF9y4",
"https://www.youtube.com/watch?v=31YJPz7gZ4c",
"https://www.youtube.com/watch?v=EPO3S649TNs",
"https://www.youtube.com/watch?v=jOfcg9WYkGw",
"https://www.youtube.com/watch?v=tBm73YjJB0o",
"https://www.youtube.com/watch?v=Jmyspnk8DZ8",
"https://www.youtube.com/watch?v=joOLgTNMuVU",
"https://www.youtube.com/watch?v=19-ooWL5R8w"] | random }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment