Using sunsynkr
using_sunsynkr.Rmd
sunsynkr
helps you to 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, 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.
Setup
First, load the package.
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.
token <- get_token()
token
#> Sunsynk API token - Success
#> Type: bearer
#> Scope: all
You can now use this token to authenticate other susynkr
functions to the API.
Get plants details
You can now get details of all plants associated with your account.
plants <- get_plants(token)
The sunsynkr_plants
object returned by
get_plants()
is also a list. For example, we can return the
total kWh generated today for the first plant in the list with the
following.
plants[["data"]][["infos"]][[1]][["etoday"]]
#> [1] 27.3
Printing the sunsynkr_plants
object returns a tibble
summarising the information available for each plant.
plants
#> # A tibble: 1 × 7
#> id name address pac etoday etotal update_at
#> <chr> <chr> <chr> <int> <dbl> <dbl> <chr>
#> 1 XXXXXX XXXXX XXXXX XX XXXXXXX XX, XXXXXXXXX XXX… 0 27.3 7398. 2024-07-…
Note that, currently, this function will return details of a maximum of 100 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.
plant_id <- plants$data$infos[[1]]$id
Then, we can obtain the power flow for the plant.
flow <- get_flow(token,
plant_id)
The sunsynkr_flow
object returned by
get_flow()
is also a list and you can access its elements
in the conventional way. For example, to return the current state of
charge of the battery…
flow[["data"]][["soc"]]
#> [1] 89
Printing the sunsynkr_flow
object outputs a
representation of the power flows managed by the inverter.
flow
#> PV 0W ----- --<-- 19W Grid
#> | ------- |
#> -----| |--<--
#> | Inv |
#> -->--| |-->--
#> | ------- |
#> BATT 150W -->-- -->-- 167W Load
#> (89%)
Day summary
You can return a summary of all power flows (and battery state of charge) at five minute intervals for a given day.
date <- lubridate::today() - lubridate::days(1)
day_summary <- get_day_summary(token,
plant_id,
date)
get_day_summary()
returns an object of
sunsynkr_day_summary
which is also a list. It’s likely that
you might want this information in a more convenient table form.
day_summary_table <- get_day_summary_table(token,
plant_id,
date)
day_summary_table
#> # A tibble: 288 × 6
#> dt pv_w battery_w `soc_%` load_w grid_w
#> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2024-07-30 00:00:00 0 15 57 172 162
#> 2 2024-07-30 00:05:00 0 14 57 172 160
#> 3 2024-07-30 00:10:00 0 17 57 169 154
#> 4 2024-07-30 00:15:00 0 15 57 170 155
#> 5 2024-07-30 00:20:00 0 13 57 161 161
#> 6 2024-07-30 00:25:00 0 16 56 171 159
#> 7 2024-07-30 00:30:00 0 17 56 166 149
#> 8 2024-07-30 00:35:00 0 17 56 167 153
#> 9 2024-07-30 00:40:00 0 16 56 170 157
#> 10 2024-07-30 00:45:00 0 13 56 165 153
#> # ℹ 278 more rows
You can also generate a plot of the day summary table.
plot(day_summary_table)