Send daily Azure IoT Hub fleet health reports with OpenAI and Gmail

Go to Workflow
0 views
Built by Saravanan Ganesan Saravanan Ganesan
Created on August 18, 2026

Description

Quick overview
This workflow runs daily at 9:00 AM to query your Azure IoT Hub device registry, classify fleet health (online, offline, stale, disabled), generate an HTML executive summary with OpenAI, and email the report through Gmail.

How it works
Runs every day at 9:00 AM on a schedule.
Builds a short-lived Azure IoT Hub SAS token from the provided IoT Hub connection string.
Calls the Azure IoT Hub device query REST API to retrieve device status, connection state, last activity time, and reported properties for the full fleet.
Classifies devices into online, offline, stale (inactive for over 24 hours), and disabled, and produces fleet totals plus a per-device snapshot.
Sends the fleet summary JSON to OpenAI to generate a concise HTML report with risks, top problem devices, and recommendations.
Emails the AI-generated HTML report to the configured recipients using Gmail.

Setup
Create or choose an Azure IoT Hub shared access policy with registry read permissions (for example, registryRead) and paste its connection string into the workflow’s IoT Hub connection string placeholder.
Add an OpenAI API credential for the OpenAI step and select the model you want to use.
Add a Gmail OAuth2 credential and set the report recipient email address(es) in the email step.

Nodes Used (4)

Code
n8n-nodes-base.code
Gmail
n8n-nodes-base.gmail
HTTP Request
n8n-nodes-base.httpRequest
OpenAI
@n8n/n8n-nodes-langchain.openAi