Okay, this isn’t exactly a topic related to home automation or home management… but it uses some of the technologies and products we’ve already seen for a different purpose and that’s still related to how technology can simplify our daily lives and save us precious time. So, if you also have this need, here’s an idea to save a good chunk of time that you can reinvest in other activities while simultaneously maintaining your presence on social media.

Personally, I have no interest or aspiration to create viral content or to climb the ranks of Facebook, Instagram, TikTok, or other algorithmic platforms through constant posting. However, I do enjoy sharing my photos with friends and those who appreciate my way of seeing the world through the lens of a camera. The problem is: I have very little time to do it… and definitely not the consistency to post daily or at regular intervals.

With this trick, you can prepare more than 30 days’ worth of content - or even more - in just a couple of minutes, and let this automation handle the rest for you. In this example, I’ll use Instagram, but the same approach works for Facebook, LinkedIn, Slack, and many other social media or sharing tools, making the process easily adaptable to other use cases.

Let’s see how!

How It Works:



Step 1: Install and configure n8n

For this process, again, I used n8n: n8n is an open-source workflow automation tool that allows you to connect various applications and services to automate repetitive tasks without manual intervention. It provides a visual interface where you can design workflows by linking different nodes that represent actions, triggers, or data processing steps.

I installed it in a Proxmox LXC by using the helper script provided by Community-Scripts: this is a very useful Community with many script that will help you many times: if you like them, consider donating to support Angie, tteckster’s wife - the founder and best supporter of the community - too early passed away.

The installation and configuration are very simple; once completed, I mounted a network share from the NAS on the local path /nas/Instagram, which I will use as an exchange directory.



Step 2: Prepare a support spreadsheet

I used a Google Sheets file to support the process. This allows me to easily access the content for review before it gets published.

The file, which I named Instagram posts, has the following structure:

spreadsheet structure

Description:

function onEdit(e) {
  var range = e.range;
  var sheet = range.getSheet();
  var row = range.getRow();
  if (range.getColumn() === 1) {
   //Today
    var formula = `=A${row} = TODAY()`;
    sheet.getRange(row, 5).setFormula(formula);
  }
  else if (range.getColumn() === 4) {
   //Hashtag count
    var formula = `=LEN(D${row})-LEN(SUBSTITUTE(D${row};"#";""))`;
    sheet.getRange(row, 7).setFormula(formula);
  }
}


Step 3: Setup and configure Instagram API

To automatically post on Instagram, it is necessary to use the Facebook Graph API, which must be configured by defining an Application and setting up its behavior and permissions. This step is specific to Instagram (and Facebook with slight modifications), but it is likely that similar steps will be required for other social platforms. Check the developer guides for specific social networks to learn how to configure the APIs for integrating custom apps.

Prerequisite

Make sure you have a business account for Instagram; otherwise, log in to Instagram and select Switch to a Business Account.

1. Create a Facebook page

2. Create a Facebook App

3. Configure App

4. Get Page Access Token

5. Extend the lifespan of the Access Token



Step 4: Define the process of preparing the post

This n8n workflow automates the definition of the description and hashtags and prepare the posts. It uses AI to analyze the pictures in the shared folder to determine the best description and hashtag based on the defined prompt and populate the just defined spreadsheet.

Here’s a step-by-step breakdown:

Workflow Description

  1. Trigger:

    • A Local File Trigger monitors the folder /nas/Instagram/ for changes (specifically, when files are added or deleted).
    • Since we are talking about a network folder, with some possible delays, check both Await Write Finish and Use Polling
    • Events like add or unlink (file addition or deletion) initiate the workflow.
  2. Debounce:

    • A Wait Node delays the workflow for 1 second to ensure all file operations are stable before proceeding.
  3. Extract Filename:

    • A Set Node extracts the filename from the file path, in order to reuse within the next nodes without appliyng always the same Javascript function.
  4. Determine Action:

    • An If Node checks whether the file was added (add) or deleted (unlink).

File Added:

  1. Load Image:

    • The workflow reads the binary added image file from disk.
  2. Analyze Image:

    • The image is analyzed using OpenAI’s GPT model to generate:
      • A quote or caption relevant to the image.
      • 15–30 hashtags for Instagram posts.

    Here is the used prompt:

    Analyze the image and select a quote, aphorism, poem excerpt, 
    or a statement by a famous person, in Italian or English, 
    that best represents it. Preferably, the quote should relate specifically 
    to the subject of the photo. Indicate the author and provide only the quote, 
    without explanation. Additionally, identify 15 to 30 hashtags 
    (preferably in English or Italian) for an Instagram post.
    

    ! Image analysis is a rather resource-intensive activity in terms of tokens: processing a photo with the specified dimensions using this prompt and GPT-4O as the model costs approximately 1300-1500 tokens per call, which translates to about €0.01 per photo. To save costs, you can set detail = low to process a photo at just 512x512 pixels, though this comes with the risk of reduced detail and lower output quality.

  3. Prepare Content:

    • The analysis results are split into:
      • Description (quote/caption).
      • Hashtags.
  4. Append to Google Sheet:

    • The image filename, description, and hashtags are appended to the previously defined Google Sheet. The Date column is not set: since It’s the trigger for the publishing flows, the image and content will not be published until you will review it and define a publishing date.

File Deleted:

  1. Locate Row:

    • The workflow searches the Google Sheet for the row corresponding to the deleted file’s filename.
  2. Check Completion:

    • It verifies whether the file has already been handled or marked as completed.
  3. Delete Row:

    • If that image has never been posted, the corresponding row in the Google Sheet is deleted.


Step 5: Define the automatic posting process

This n8n workflow automates the process of creating and publishing daily Instagram posts. It uses image analyzer to handle both portrait and landscape images without cropping and at the end it ensures unnecessary files are deleted from both the local disk cloud ones.

Here’s a detailed breakdown:

Workflow Description

  1. Schedule Trigger:

    • Activates the workflow daily at 9 AM.
  2. Get Today Post (Google Sheets)

    • Fetches the row marked as “Today” (Today column = TRUE) from the previously defined Google sheet.
    • It returns only first row since making two simultaneous posts don’t give you any benefit.
  3. Open Image from Disk

    • Reads the image file associated with today’s post from the NAS shared folder mounted in n8n server.
  4. Get Image Info, Check if Portrait or Landscape

    • Analyzes the image dimensions to check its orientation (portrait or landscape).
    • If portrait, proceeds to add borders to make it square.
  5. Add Border to Portrait Images

    • Adds borders to portrait images to make them square for Instagram and avoid cropping of 3:2 or 4:3 format pictures.
  6. Upload Image to Google Drive, Create Image Link

    • Facebook Graph API doesn’t allow binary image data, but only urls, so we need to:
      • Upload the processed image to Google Drive for hosting.
      • Generate a publicly accessible link for the image hosted on Google Drive, by using the Unique ID of the just published file.
  7. Create Instagram Media Container (HTTP Request)

  1. Wait 30s

    • Ensures the media container is ready before publishing.
  2. Publish Instagram Media (HTTP Request)

    • ublishes the media container created in the previous step.
    • Requires the creation_id from the media container.
  3. Delete Image, Remove Image from Disk

    • Deletes the image from Google Drive after publishing.
    • Removes the image file from the local disk to clean up.
  4. Mark Row as Done (Google Sheets)

    • Updates the Google Sheet to mark the post as completed, by flagging the Status column with Done plus the timestamp of the operation for providing a complete information.


Step 6: Let’s try it!

Now let’s try the entire process:

1. Select the photos

I usually edit photos in Lightroom, and the ones I want to publish are exported to the network share configured earlier and accessible by n8n. Following my usual workflow for Instagram, I export the photos in JPEG format, maximum quality, with a short side resolution of 1080px, 240 dpi, and sharpening set for screen.

2. The post definition process prepare the content

This is handled “under the hood” by the first defined workflow and triggered by the export on the defined folder, so you actually don’t need to do anything.

3. Review post content

4. Wait for it!

At the scheduled time of the set day, the second process will automatically publish the post on Instagram, remove the useless picture both from local drive and Google Drive, and update the spreadsheet.



Step 7: Enjoy