Hi,

I am trying to analyse the heating in my house, in which I have 12 thermostats. I am keen to understand better the relationship of heating in each room between the set point and how often and how long the thermostat has to call for heat to get the room to a specific temperature, or heat the room by 1 degree

To start off, I was hoping to be able to plot the temperature of a thermostat in degrees as a line, vs the setpoint of the thermostats as a step line, vs whether the stat is calling for heat, as a bar chart of either zero or one.

My first issue is getting the temp and set point on the same graph with the set point being a stepped line, ie not a sloping line between points. Is this possible, or do I need to generate the missing values, as the channel only records values when it changes.

Then, how would I change the "On" or "Off" values on the heating field to a 0 or 1 to then plot, and can I do line vs column on the same chart?

I am hoping this would be a useful example for others once I can get this working, and then I keen to learn from others what they do. ie I would love to calculate the number of hours per day that each room is calling for heat (and the total) and plot vs outside temperature / humidity / wind etc.

Thanks,

siclark,

"I was hoping to be able to plot the temperature of a thermostat in degrees as a line, vs the setpoint of the thermostats as a step line"

Yes it is possible to create a step line type visualization using the MATLAB Visualizations app and the MATLAB visualization function 'stairs'. For more information and examples, please see the following documentation page: http://www.mathworks.com/help/matlab/ref/stairs.html

"how would I change the "On" or "Off" values on the heating field to a 0 or 1"

One method of achieving this task is writing to the Channel's "status" field ('on' or 'off') or to one of the other 7 channel fields (0 or 1). For more information on how to update a Channel feed, see the following documentation page: https://thingspeak.com/docs/channels#update_feed

"can I do line vs column on the same chart"

Yes it is possible to overlay different forms of visualizations on the same plot or figure. Again, using the MATLAB Visualization app, the following MATLAB Code will produce a bar chart with a line chart overlaid on top.

bar(1:10);

% Retain current plot when adding new plots.

hold;

plot(10:-1:1) ;

Note that the '%' symbol is used to add comments to MATLAB code (http://www.mathworks.com/help/matlab/matlab_prog/comments.html)

Documentation:

1. bar: http://www.mathworks.com/help/matlab/ref/bar.html

2. hold: http://www.mathworks.com/help/matlab/ref/hold.html

3. plot: http://www.mathworks.com/help/matlab/ref/plot.html

Hi,

Thanks for all this. It took me a while to realise I could just enter the matlab code as I would the thingspeak functions, as thats not clear in the documentation.

However I get an error when using the stairs function of Input arguments must be numeric. I guess it doesnt like the date values?

This is the code.

readChannelID = 64586;

fieldID1 = 1;

fieldID2 = 2;

[data1, time1] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumDays',5);

[data2, time2] = thingSpeakRead(readChannelID, 'Field', fieldID2, 'NumDays',5);

plot(time1, data1);

hold;

stairs(time2, data2);

Also, if I use thingSpeakPlot(time2, data2) I get a proper chart, but it doesnt plot the values if I use plot(time2, data2). Is there a known reason for this, do the functions behave differently??

Thanks

siclark,

"However I get an error when using the stairs function of Input arguments must be numeric. I guess it doesnt like the date values?"

Yes, that is correct. According to the 'stairs' documentation, the X and Y input arguments must be numeric values of type "Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical" (http://www.mathworks.com/help/matlab/ref/stairs.html?searchHighlight=stairs#inputarg_X)

With additional MATLAB Code, it is possible to convert the MATLAB DateTime object returned by the MATLAB function 'thingSpeakRead' to a numeric value, and have the X or Y Axes label formatted to display a date string.

It is possible to convert a DateTime object to a numeric value using the MATLAB Function 'datenum'

http://www.mathworks.com/help/matlab/ref/datenum.html

Once the figure is plotted, it is possible to change the formatting of the X or Y Axes label using the MATLAB Function 'datetick'

http://www.mathworks.com/help/matlab/ref/datetick.htm

Note that the MATLAB function accepts a 'dateformat' string as the second argument. Please refer to the the documentation section for more information:

http://www.mathworks.com/help/matlab/ref/datetick.html?searchHighlight=stairs%20xtick#inputarg_dateFormat

For example:

[data, time] = thingSpeakRead(id, 'Field', field, 'NumPoints', 5);

stairs(datenum(time), data);

datetick('x', 'mm/dd/yy');

"I use thingSpeakPlot(time2, data2) I get a proper chart, but it doesnt plot the values if I use plot(time2, data2)"

The interactive ThingSpeak plotting functions such as 'thingSpeakPlot' are incompatible with the static MATLAB plots such as 'plot' or 'stairs' and cannot be combined. Please refer to the 'Troubleshooting' section of the documentation: https://thingspeak.com/docs/troubleshooting

Thanks. Its taken a while, as using datenum on the time argument for my first data set worked, but it was the second I wanted to plot as stairs and this still didnt work.

The first has many more data points than the second, hence wanting to plot the second as stairs, and I assumed that this would work.

However in the end I had to read the original 2nd series, use the matlab analysis to clean up and remove all the nulls from that series and write to a new channel. Reading that channel in to the visualisation for the step line on top of the line plot from the original channel works well.

Now to work out how to do the On/Off conversion which I think I will also have to clean up and then write to a new channel as well as converting to 0,1

Most Users Ever Online: 114

Currently Online:

21 Guest(s)

Currently Browsing this Page:

1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

yeseniara11

RomanFug

JamesPes

RobertBak

ScottSmiva

Amourhotte

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee