Download image from variable url to local dir

Hi,

I want to download a image to the media dir in home assistant.
The thing is that the url is variable, the url is a attribute in a binary sensor.

image_url: >-
  https://zoneminder.XXX.nl/zm/index.php?view=image&eid=499&fid=objdetect&username=XXX&password=XXX

What is the best way to trigger a download to media folder with filename 1.jpg?

I think is should use a commandline something like this but how do is use it with a variable url from a sensor attribute or is there a better way?

wget "https://zoneminder.XXX.nl/zm/index.php?view=image&eid=499&fid=objdetect&username=XXX&password=XXX" -O media/1.jpg
wget "{{image_url}}" -O media/1.jpg

Hi, how did you solve?
Thanks