Create Automation that will pick a random entry from a json file

Hello everyone,

I wish to implement HA to pick a random entry from a JSON file. the quote will be afterward be spoken through TTS.
example of file:

[{
		"id": 1,
		"quote": "hello"
	},
	{
		"id": 2,
		"quote": "world"
	}
]

My question is, how can I configure my automation in order to select a random entry, and also to read a file?

Does it have to be a json file? can it just be in the automation itself?

action:
  service: tts_google_say
  data_template:
    entity_id: media_player.mp1
    message: |-
      {{ [
        'It is pretty dark outside. I will turn on the outside lights now.',
        'It is a little past Sunset. Time to turn on the outside lights. I am on it.',
        'I will switch on the outside lights. It is getting dark outside.',
        'Time to turn on the front lights. I will take care of it.',
        'Switching to night mode! '
      ]|random }}

if it’s something you wish to use in several automations, you could just move the action to a script and call the script in the automation

Hi @atomicpapa

It would make sense if the number of entries is low, however I got a lot of entries (around 1k) and I was thinking it would have make more sense to have the quote entries in a separate file. If there are no other possibility, then I would go with your solution. Thanks :slight_smile:

There is probably a way, unfortunately I only know the way above.