How to calculate data with price rate for water consumption.

2 views (last 30 days)
I am looking for a code for matlab analysis of my data, I want to calculate water bill for every 100 litre=1USD, for 1 month. So that the user can get total water consumption bill at the end of the month. Please help.
  7 Comments
Aman Kumar
Aman Kumar on 18 May 2020
Thanks it worked, but i didn't got the requided notification message. I needed the data of total water used and bill amount. Here is the code, please check if i did something wrong.
% Enter your MATLAB Code below
% Read Output Water Quantity over the past month from a ThingSpeak channel and write
% the average to another ThingSpeak channel.
% Channel 1035265 contains data from the MathWorks water supply station, located
% in Natick, Massachusetts. The data is collected once every day. Field
% 3 contains output liquid quantity data.
% Channel ID to read data from
readChannelID = 1035265;
% Output Liquid Quantity Field ID
outputliquidqantityFieldID = 3;
% Channel Read API Key
% If your channel is private, then enter the read API Key between the '' below:
readAPIKey = '';
% Get Output Liquid Quantity data for the last 30 days from the MathWorks water supply
% station channel. Learn more about the THINGSPEAKREAD function by going to
% the Documentation tab on the right side pane of this page.
meter_reading = thingSpeakRead(readChannelID,'Fields', outputliquidqantityFieldID,'NumDays',1,'ReadKey',readAPIKey);
% Calculate the Cost
Billing_cost = 5* (meter_reading/1000);
display(Billing_cost,'Total Billing Cost (INR)');
% Start by setting the channel ID and Alert key. All alert key start with TAK.
data = thingSpeakRead(1035265,"NumDays", 1);
Water = sum(data(:, 2));
apiKey = 'TAK1S83KIQN0BBLNS';
alertURL = "https://api.thingspeak.com/alerts/send";
options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", apiKey ]);
alertBody = sprintf("The Water consumption bill is", 5* (meter_reading/1000));
alertSubject = sprintf(" Water consumption exceeded 100 kl!");
if Water >= 100
webwrite(alertURL, "body", alertBody, "subject", alertSubject, options);
end
Aman Kumar
Aman Kumar on 18 May 2020
I need the message as (The water consumption bill is, 5usd" for 1200kl or any amount value that the user consumed. Please Help

Sign in to comment.

Accepted Answer

Christopher Stapels
Christopher Stapels on 18 May 2020
This sounds like a very interesting project. I wonder what sensor you are using to track the water consumption.
It sounds like you need help with the sprintf function. This line seems to be missing a format specifier.
alertBody = sprintf("The Water consumption bill is", 5* (meter_reading/1000));
Have a look at the documentation for sprintf.

More Answers (0)

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Prepare and Analyze Data in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!