<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/monitoring-electricity-use/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://scottishsnow.wordpress.com/2018/10/10/monitoring-electricity-use/"> R – scottishsnow</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>My partner and I are considering installing photo voltaic (PV) solar panels. We had solar thermal (hot water) panels in our old house, but our new property has a very different heating system. The air source heatpump which heats our home is excellent and means we have no use for gas, but our electricity use is much higher now it is our only energy source!</p>
<p>To help understand our electricity use, and hence how we might specify a PV system, I got an electricity monitor from the <a rel="nofollow" href="https://openenergymonitor.org/" target="_blank">Open Energy Monitor project</a>. The hardware and software they use are all open source, which appeals greatly. One worry I had with all the commercial energy monitoring products I’d seen was how easily I could access my data. This isn’t a worry when it’s sitting in an <a rel="nofollow" href="https://en.wikipedia.org/wiki/Open_Database_Connectivity" target="_blank">ODBC</a> compliant database on a <a rel="nofollow" href="https://www.raspberrypi.org/" target="_blank">Raspberry Pi</a> server!</p>
<p>Today I made my first download from the server. It wasn’t automated, but a few clicks through a web interface. Data are hosted in a component called EmonCMS, which is a suite of tools build around a MySQL database. I <em>could</em> extract data directly from this database into R, but EmonCMS also has the functionality to build dashboard apps for data visualisation. This will be more useful in the long term, as I will then be viewing live data with no additional effort.</p>
<p>Back to the problem at hand, I wanted to visualise our electricity use. I wanted to do this by day and also by hour. The latter is particularly important for solar, as I need to understand how much of our electricity use is during daylight hours. So with a bit of <a rel="nofollow" href="https://dplyr.tidyverse.org/" target="_blank">dplyr</a> and <a rel="nofollow" href="https://ggplot2.tidyverse.org/reference/" target="_blank">ggplot</a> magic, I created these two plots:</p>
<p><a rel="nofollow" href="https://scottishsnow.files.wordpress.com/2018/10/electric_use.png" target="_blank"><img data-orig-file="https://scottishsnow.files.wordpress.com/2018/10/electric_use.png?w=456" data-orig-size="1400,500" data-medium-file="https://scottishsnow.files.wordpress.com/2018/10/electric_use.png?w=456?w=300" data-attachment-id="1584" data-image-meta="{" data-image-description="" src="https://scottishsnow.files.wordpress.com/2018/10/electric_use.png?w=456" data-permalink="https://scottishsnow.wordpress.com/2018/10/10/monitoring-electricity-use/electric_use/" data-large-file="https://scottishsnow.files.wordpress.com/2018/10/electric_use.png?w=456?w=620" alt="Electric_use" data-image-title="Electric_use" sizes="(max-width: 620px) 100vw, 620px" data-comments-opened="1" class="wp-image-1584" data-recalc-dims="1"></a></p>
<p>Downloaded data showed an instantaneous electricity use in Watts, recorded every 10 seconds. These values were converted to kWh and summed to hourly or daily. Days or hours with incomplete records were discarded. Here’s the code to make the plots:</p>
<pre>
library(tidyverse)
library(patchwork)

elec = read_csv(&quot;~/Downloads/file.csv&quot;, col_names=c(&quot;time&quot;, &quot;use&quot;))

elec_hrly = elec %>%
   mutate(hr = str_sub(time, 12, 13),
          date = as.Date(str_sub(time, 1, 10), format=&quot;%d/%m/%Y&quot;)) %>%
   group_by(date, hr) %>%
   summarise(use_hr = sum(use/360000),
             n=n()) %>%
   filter(n==360)

elec_daily = elec %>%
   mutate(date = as.Date(str_sub(time, 1, 10), format=&quot;%d/%m/%Y&quot;)) %>%
   group_by(date) %>%
   summarise(use_dly = sum(use/360000),
             n=n()) %>%
   filter(n==8640)

png(&quot;~/Cloud/House/Electric_use.png&quot;, width=1400, height=500)
ggplot(elec_hrly, aes(hr, use_hr)) +
   geom_boxplot() +
   labs(title=paste(&quot;Home electricity use:&quot;,
                    min(elec_hrly$date), &quot;to&quot;, max(elec_hrly$date)),
        subtitle=&quot;By hour of the day (GMT)&quot;,
        x=&quot;Hour of the day (GMT)&quot;,
        y=&quot;Electricity use (kWh)&quot;) +
   theme_grey(base_size = 22) +
ggplot(elec_daily, aes(use_dly)) +
   geom_histogram(bins=20) +
   labs(subtitle=&quot;By daily use&quot;,
        x=&quot;Daily use (kWh)&quot;,
        y=&quot;Count of days&quot;) +
   theme_grey(base_size = 22)
dev.off()
</pre>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://scottishsnow.wordpress.com/2018/10/10/monitoring-electricity-use/"> R – scottishsnow</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/9Js320juaxc" height="1"></a></div>