% Store the channel ID for the range sensor channel. channelID = *******; % Provide the ThingSpeak alerts API key. alertApiKey = 'TAK*****************'; % Set the address for the HTTTP call alertUrl="https://api.thingspeak.com/alerts/send"; % webwrite uses weboptions to add required headers. Alerts needs a ThingSpeak-Alerts-API-Key header. options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]); % Set the email subject. alertSubject = sprintf("Salt level status"); % Read the recent data. saltData = thingSpeakRead(channelID,'NumPoints',1,'Fields',1); % Get the most recent point in the array of salt data. lastValue = saltData(end); % Set the outgoing message when level greater than 400 if (lastValue>400) alertBody = ' I need salt! ' end try webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options); catch someException fprintf("Failed to send alert: %s\n", someException.message); end