-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
157 lines (102 loc) · 3.67 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# sunsynkr
<!-- badges: start -->
[![R-CMD-check](https://github.com/DavidASmith/sunsynkr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/DavidASmith/sunsynkr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
`sunsynkr` is an R package to help you acquire information about Sunsynk photovoltaic systems from their API. If you have a Sunsynk inverter and an account to view and manage it on [SunsynkConnect](https://sunsynk.net/), you should be able to use this package to retrieve information about your plant.
Note that this package is unofficial and is in no way associated with Sunsynk. It may stop working (or return misleading outputs) at any time and without warning.
Also note that this package is currently at an early stage of development. Functions may not work as specified and things may change fundamentally in future versions.
## Installation
From R, you can install the current release of `sunsynkr` like so:
``` r
devtools::install_github("DavidASmith/sunsynkr")
```
## Example usage
First, load the package.
```{r example}
library(sunsynkr)
```
### Authentication
You must configure environment variables to hold your sunsynk username and password (the ones you use to login to SunsynkConnect at https://sunsynk.net/). Configure the following environment variables:
- `SUNSYNK_USER`
- `SUNSYNK_PASS`
### Get a token
All `sunsynkr` functions which call the API require a token as an argument. Accordingly, you must first acquire an authentication token.
```{r}
token <- get_token()
token
```
You can now use this token to authenticate other `susynkr` functions to the API.
### Get plants details
```{r include=FALSE}
# Redact personal info
redact_character <- function(x) {
gsub("\\w", "X", x)
}
redact_plants <- function(x) {
plant_infos <- x$data$infos
redact_plant <- function(x) {
x$id <- redact_character(x$id)
x$name <- redact_character(x$name)
x$thumbUrl <- redact_character(x$thumbUrl)
x$address <- redact_character(x$address)
x$email <- redact_character(x$email)
x$phone <- redact_character(x$phone)
x$masterId <- redact_character(x$masterId)
x
}
x$data$infos <- lapply(plant_infos, redact_plant)
x
}
```
You can now get details of all plants associated with your account.
```{r}
plants <- get_plants(token)
```
```{r include=FALSE}
plant_id <- plants$data$infos[[1]]$id
plants <- plants |>
redact_plants()
```
Printing the `sunsynkr_plants` object returns a tibble summarising the information available for each plant.
```{r}
plants
```
### Flow
We can query the most recent power flow from the API for a given plant. We can extract the plant from `plants` like this.
```{r eval=FALSE}
plant_id <- plants$data$infos[[1]]$id
```
Then, we can obtain the power flow for the plant.
```{r}
flow <- get_flow(token,
plant_id)
```
Printing the `sunsynkr_flow` object outputs a representation of the power flows managed by the inverter.
```{r}
flow
```
### Day summary
You can return a summary of all power flows (and battery state of charge) at five minute intervals for a given day.
```{r}
date <- lubridate::today() - lubridate::days(1)
day_summary_table <- get_day_summary_table(token,
plant_id,
date)
day_summary_table
```
You can also generate a plot of the day summary table.
```{r fig.height=6, fig.width=6}
plot(day_summary_table)
```