I have a list of knock knock jokes… a few hundred for now, and I want one to be picked at random as part of my son’s bedtime routine. I Could input them all into the template in the automation, but that feels wrong… I guess if it works, it works, but I’d prefer if the list lived somewhere else as a list or dictionary or whatever, then just pull that sensor |list|random in the bedtime script to keep things cleaner.
the thing is, I don’t really know how to get this list into home assistant as a dictionary or list or whatever? any good tips on doing this? or just a 6-halfdozen situation where it has to live somewhere and if I’m only calling it in this script I might as well just have the whole list in the script to randomly pull as a variable or something at the top?
If you’re only using it the one script, just define it as a variable:
variables:
jokes:
- this is joke 1
- this is joke 2
- this is joke 3
- this is joke 4
sequence:
- action: notify.example
data:
message: "{{ jokes | random }}"
If you really want it to be more globally accessible, you could store the list as an attribute in a template sensor:
template:
- sensor:
- name: All My Jokes
state: this is not important
attributes:
jokes:
- this is joke 1
- this is joke 2
- this is joke 3
- this is joke 4
btw, for topic starter, isnt it easier to store all your jokes in a JSON and pull from there a random one? Keeps your script clean and updating jokes would be easy seperated
thanks for the tips! I Was using dad jokes integration on hacs to pull from web automatically, but my 6y/o told me he likes knock knock jokes the best and I wasn’t able to limit to only knock-knocks, so I pivoted to the local list.
the evening briefing is LLM based, so originally I had it make up a relevant joke based on weather or calendar or whatever else it brought up in the briefing that night. That was awesome and I really liked the results, but with my child having a fairly steady schedule it ended up repeating jokes very quickly and I don’t know enough with the generate ai task if it’s possible to keep a running list or memory or something to minimize repeats. So i pivoted to feeding it a joke from the dadjoke integration and now pivoted again to the local list of knockers.