Tutorial - Display Météo France alert maps

Hello,

I will show you here how to display Météo France weather alert maps in Gladys
The maps come from: https://public-api.meteofrance.fr

The usefulness is debatable but it can be nice to have an overview :wink:

The final result:

First you need to create an account and retrieve an API key on the site:

https://portail-api.meteofrance.fr/web/fr/

Next, you need to create the folders in Gladys for receiving the images and the script: (For this you need to connect via ssh to the Gladys host machine)

mkdir /var/lib/gladysassistant/img/meteofrance
mkdir /var/lib/gladysassistant/img/
mkdir /scripts

Then create the script

nano /scripts/meteofrancealertes.sh
#!/bin/bash

# Define the URL of the file to download
URL_TODAY="https://public-api.meteofrance.fr/public/DPVigilance/v1/vignettenationale-J/encours"
URL_TOMORROW="https://public-api.meteofrance.fr/public/DPVigilance/v1/vignettenationale-J1/encours"

# Define destination paths for files
DEST_TODAY="/var/lib/gladysassistant/img/meteofrance/today.png"
DEST_TOMORROW="/var/lib/gladysassistant/img/meteofrance/tomorrow.png"

# Maximum number of attempts
MAX_ATTEMPTS=5

# Function to download the file
download_file() {
    wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" -O "$1" "$2" --header="accept: */*" --header="apikey: apikey_aremplacer"
}

# Download the file for today
attempt=1
while [ $attempt -le $MAX_ATTEMPTS ]; do
    echo "Tentative de téléchargement du fichier pour aujourd'hui ($attempt/$MAX_ATTEMPTS)..."
    if download_file "$DEST_TODAY" "$URL_TODAY"; then
        echo "Téléchargement du fichier pour aujourd'hui réussi."
        break
    else
        echo "Échec du téléchargement du fichier pour aujourd'hui."
        attempt=$((attempt + 1))
        if [ $attempt -le $MAX_ATTEMPTS ]; then
            echo "Nouvelle tentative dans 5 secondes..."
            sleep 5
        else
            echo "Nombre maximal de tentatives atteint pour le fichier d'aujourd'hui. Arrêt du téléchargement."
        fi
    fi
done

# Download the file for tomorrow
attempt=1
while [ $attempt -le $MAX_ATTEMPTS ]; do
    echo "Tentative de téléchargement du fichier pour demain ($attempt/$MAX_ATTEMPTS)..."
    if download_file "$DEST_TOMORROW" "$URL_TOMORROW"; then
        echo "Téléchargement du fichier pour demain réussi."
        break
    else
        echo "Échec du téléchargement du fichier pour demain."
        attempt=$((attempt + 1))
        if [ $attempt -le $MAX_ATTEMPTS ]; then
            echo "Nouvelle tentative dans 5 secondes..."
            sleep 5
        else
            echo "Nombre maximal de tentatives atteint pour le fichier de demain. Arrêt du téléchargement."
        fi
    fi
done

Replace apikey_aremplacer with your API key that you obtained from the site https://public-api.meteofrance.fr

Create the crontab:

Values are retrieved every day at 16:10 and 06:10 because the Météo France site indicates:
image

crontab -e
10 16 * * * /scripts/meteofrancealertes.sh \u003e/dev/null 2\u003e\u00261
10 06 * * * /scripts/meteofrancealertes.sh \u003e/dev/null 2\u003e\u00261

Then create the 2 cameras like this:

You can then display them on the Gladys interface

I haven’t managed to get the white background but if you have a lead I’m open to suggestions :slight_smile:

If you have any questions/comments, feel free to let me know :slight_smile:

Changelog to come:

  • None (Your feedback welcome :slight_smile: )

Edit 13/05/2024 :

  • Modified the crontab to run it every hour past 5 minutes

Edit 14/05/2024 :

  • Fixed an issue when downloading the maps (Added headers in the Curl)

Edit 15/05/2024 :

  • Fixed an issue when downloading the maps (Replaced Curl with Wget)
  • Fixed the times in the crontab

Edit 16/05/2024 :

  • Modified the download script to handle retries on failure and added a user-agent to try to avoid being detected as a bot by the Météo France site
8 Likes

I really like all these tutorials. No matter how useful they are, they also show everything Gladys can do!!

Great initiative once again! :+1:

4 Likes

@prohand

At the same time @pierre-gilles needed ideas for future live coding sessions :+1: so between this tutorial and the pollen one the mission is accomplished! :wink: :rofl:

Awesome tutorials @prohand, that’s great — it really shows the possibilities of Gladys!

In my opinion, that’s exactly what we’re missing right now: content!

2 Likes

Hi @prohand

I can’t create folders in the terminal. Can you explain what to do first, please?

Thanks

To create the directories you need to have access either directly to the terminal on the machine that runs Gladys, or to connect to it via SSH.

Furthermore, depending on your installation you may need access with higher privileges; for that you must add sudo before each command.

That’s exactly it :slight_smile:
Thanks for the reply, I’ve added a clarification in the tutorial

Yes sorry I should have specified — for my part I am indeed connected via SSH but it tells me I don’t have the permissions. I tried sudo or chmod 777 but it doesn’t work.

I’m not a command-line expert, I must be doing something wrong but I don’t see where, here is what I have:

Quote

pi@gladys**:~ $ mkdir /var/lib/gladysassistant/img/meteofrance

mkdir /var/lib/gladysassistant/img/

mkdir /scripts

mkdir: cannot create directory ‘/var/lib/gladysassistant/img/meteofrance’: No such file or directory

mkdir: cannot create directory ‘/var/lib/gladysassistant/img/’: Permission denied

mkdir: cannot create directory ‘/scripts’: Permission denied

[quote=« jerome, post:8, topic:8858 »]
pi@gladys**:~ $ mkdir /var/lib/gladysassistant/img/meteofrance

mkdir /var/lib

Thanks @McFlyPartages — first step completed. I hadn’t added sudo to each line.

I reached the end but I have an error:

ffmpeg exited with code 254: Error opening input file /var/lib/gladysassistant/img/meteofrance/tomorrow.png. Error opening input files: No such file or directory

Any idea?

Try running:

ls /var/lib/gladysassistant/img/meteofrance

To see if the image is present

If not present, did you run the Node-RED flow?

1 Like

The Node-RED flow???

You don’t mention it, I don’t understand.

Sorry I mixed up the topic :frowning:
I meant to talk about the script :wink:

Tutorial update :slight_smile:
See the changelog in the first post.
Thanks :wink:

Tutorial update :slight_smile

1 Like

Tutorial

1 Like

Tutorial update :slight_smile:
See the changelog in the 1st post.
Thanks :wink:

2 Likes