iobroker.pvnode 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AlPi-BRV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
1
+ ![Logo](admin/pvnode.png)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # ioBroker.pvnode
4
+
5
+ [![NPM version](https://img.shields.io/npm/v/iobroker.pvnode.svg)](https://www.npmjs.com/package/iobroker.pvnode)
6
+ [![License](https://img.shields.io/github/license/AlPi-BRV/ioBroker.pvnode)](LICENSE)
7
+ [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-%E2%98%95-yellow)](https://buymeacoffee.com/alpi_brv)
8
+
9
+ <a href="https://buymeacoffee.com/alpi_brv"><img src="admin/coffee.png" alt="Buy me a coffee" width="200"></a>
10
+
11
+ **PV production forecast from [pvnode.com](https://pvnode.com) (API v2) for ioBroker.**
12
+
13
+ 🇩🇪 [Deutsche Anleitung](docs/de/README.md)
14
+
15
+ ## Features
16
+
17
+ - pvnode **API v2** with saved sites (Site ID) – the v1 API is switched off by pvnode on 31.12.2026
18
+ - **All plans** (Free, Light, Plus): features are detected automatically from the API response, no plan setting needed
19
+ - **Quota-friendly polling**: the adapter only asks for data when pvnode has computed a new forecast (`next_poll_at`), keeps the last forecast over restarts and shows the remaining monthly requests
20
+ - Values **per string** (module area), e.g. east/west roofs
21
+ - Locally computed every 5 minutes, without API requests: current power, energy of the next hour, **remaining energy today**, expected energy so far, peak power and time
22
+ - Daily forecast for up to 7 days (depending on plan)
23
+ - Optional: weather, irradiance, clear-sky power and – on paid plans – the **variability band** (min/max)
24
+ - JSON series for charts in VIS
25
+
26
+ ## Setup
27
+
28
+ 1. Create a site with your strings at [pvnode.com](https://pvnode.com/sites/new) and copy your API key.
29
+ 2. Install the adapter and enter the API key.
30
+ 3. Select the site (with only one site you can leave it empty).
31
+
32
+ ## States
33
+
34
+ | State | Description |
35
+ | --- | --- |
36
+ | `now.power` | Forecast power of the current 15-minute slot (W) |
37
+ | `now.energy_next_hour` | Expected energy in the next hour (kWh) |
38
+ | `today.energy` / `tomorrow.energy` | Daily forecast (kWh) |
39
+ | `today.remaining` | Remaining energy today from now on (kWh) |
40
+ | `today.expected_so_far` | Energy expected until now (kWh) – compare with your real production |
41
+ | `today.peak_power` / `today.peak_time` | Peak of the day |
42
+ | `days.N.*` | Daily forecast, N = 0 today … 6 |
43
+ | `strings.N.*` | Per string: current power, today / tomorrow / remaining energy, orientation, tilt, kWp |
44
+ | `weather.*` | Weather and irradiance of the current slot (optional) |
45
+ | `*_min` / `*_max` | Variability band (paid plans only) |
46
+ | `json.today` / `json.forecast` | Series `[{t, pv, s0, s1, …}]`, t = epoch ms, power in W |
47
+ | `json.daily` | Daily values as returned by pvnode |
48
+ | `html.today` / `html.tomorrow` | Ready-made SVG power curve (dark theme) – show it in VIS with the basic widget "String (unescaped)" |
49
+ | `html.days` | Ready-made SVG bar chart of the daily energy |
50
+ | `info.requestsRemaining` | Remaining requests this month |
51
+ | `info.nextPoll` | Time of the next API request |
52
+ | `control.refresh` | Request a new forecast now (costs one request) |
53
+
54
+ ## Plans and requests
55
+
56
+ | Plan | Forecast | New forecast | Requests / month |
57
+ | --- | --- | --- | --- |
58
+ | Free | today + tomorrow | 1× per day | 250 |
59
+ | Light | 7 days | 24× per day | 3,000 |
60
+ | Plus | 7 days, variability band | up to 144× per day | 3,000 |
61
+
62
+ The adapter follows `next_poll_at`, so on the Free plan it needs about one request per day.
63
+
64
+ ## Why this adapter?
65
+
66
+ We had trouble getting pvnode forecasts into ioBroker reliably with existing solutions – in our setup we only got empty values. So we decided to build a simple, uncomplicated adapter that does exactly one thing: bring the pvnode forecast into ioBroker, with as few settings and requests as possible.
67
+
68
+ ## Disclaimer and thanks
69
+
70
+ This adapter is an independent community project. We are **not affiliated with pvnode** in any way, and pvnode does not provide support for this adapter. pvnode is a trademark of its owner.
71
+
72
+ Many thanks to the pvnode team for providing their service and the public API that makes this adapter possible.
73
+
74
+ ## Changelog
75
+
76
+ <!--
77
+ Placeholder for the next version (at the beginning of the line):
78
+ ### **WORK IN PROGRESS**
79
+ -->
80
+
81
+ ### 0.2.0 (2026-11-15)
82
+
83
+ - First public release
84
+ - Requires Node.js 22 or newer
85
+
86
+ ### 0.1.4 (2026-11-12)
87
+
88
+ - Ready-made SVG charts for VIS (`html.today`, `html.tomorrow`, `html.days`)
89
+
90
+ ### 0.1.3 (2026-11-12)
91
+
92
+ - Much lower memory and CPU usage (date formatters are cached)
93
+
94
+ ### 0.1.2 (2026-11-12)
95
+
96
+ - Coffee cup button in the settings
97
+
98
+ ### 0.1.1 (2026-11-12)
99
+
100
+ - Smaller donation link in the settings
101
+ - Buy me a coffee link added
102
+
103
+ ### 0.1.0 (2026-11-12)
104
+
105
+ - Initial release
106
+
107
+ ## License
108
+
109
+ MIT License
110
+
111
+ Copyright (c) 2026 AlPi-BRV
112
+
113
+ See [LICENSE](LICENSE).
Binary file
@@ -0,0 +1,188 @@
1
+ {
2
+ "i18n": false,
3
+ "type": "panel",
4
+ "items": {
5
+ "_headerAccess": {
6
+ "type": "header",
7
+ "size": 3,
8
+ "text": {
9
+ "en": "pvnode access",
10
+ "de": "pvnode-Zugang"
11
+ }
12
+ },
13
+ "apiKey": {
14
+ "type": "password",
15
+ "visible": true,
16
+ "label": {
17
+ "en": "API key",
18
+ "de": "API-Key"
19
+ },
20
+ "help": {
21
+ "en": "Starts with sk_live_ – create it at pvnode.com",
22
+ "de": "Beginnt mit sk_live_ – wird auf pvnode.com erzeugt"
23
+ },
24
+ "xs": 12,
25
+ "sm": 12,
26
+ "md": 6,
27
+ "lg": 6
28
+ },
29
+ "siteId": {
30
+ "type": "selectSendTo",
31
+ "command": "getSites",
32
+ "jsonData": "{\"apiKey\": \"${data.apiKey}\"}",
33
+ "alsoDependsOn": [
34
+ "apiKey"
35
+ ],
36
+ "manual": true,
37
+ "label": {
38
+ "en": "Site",
39
+ "de": "Standort"
40
+ },
41
+ "help": {
42
+ "en": "Select your pvnode site (adapter instance must be running). Leave empty if you only have one site.",
43
+ "de": "pvnode-Standort auswählen (Instanz muss laufen). Leer lassen, wenn es nur einen Standort gibt."
44
+ },
45
+ "xs": 12,
46
+ "sm": 12,
47
+ "md": 6,
48
+ "lg": 6
49
+ },
50
+ "_headerData": {
51
+ "type": "header",
52
+ "size": 3,
53
+ "text": {
54
+ "en": "Data",
55
+ "de": "Daten"
56
+ },
57
+ "newLine": true
58
+ },
59
+ "_planInfo": {
60
+ "type": "staticText",
61
+ "text": {
62
+ "en": "Your plan is detected automatically. The adapter only requests new data when pvnode has computed a new forecast (Free: 1×/day, Light: hourly, Plus: up to every 15 min) and shows the remaining monthly requests in info.requestsRemaining.",
63
+ "de": "Dein Plan wird automatisch erkannt. Der Adapter fragt nur ab, wenn pvnode eine neue Prognose berechnet hat (Kostenlos: 1×/Tag, Light: stündlich, Plus: bis alle 15 min), und zeigt die restlichen Monatsanfragen in info.requestsRemaining."
64
+ },
65
+ "xs": 12,
66
+ "sm": 12,
67
+ "md": 12,
68
+ "lg": 12
69
+ },
70
+ "forecastDays": {
71
+ "type": "number",
72
+ "min": 0,
73
+ "max": 7,
74
+ "label": {
75
+ "en": "Forecast days (0 = plan maximum)",
76
+ "de": "Prognosetage (0 = Maximum des Plans)"
77
+ },
78
+ "newLine": true,
79
+ "xs": 12,
80
+ "sm": 6,
81
+ "md": 3,
82
+ "lg": 3
83
+ },
84
+ "includeWeather": {
85
+ "type": "checkbox",
86
+ "label": {
87
+ "en": "Weather (temperature, wind, rain …)",
88
+ "de": "Wetter (Temperatur, Wind, Regen …)"
89
+ },
90
+ "newLine": true,
91
+ "xs": 12,
92
+ "sm": 6,
93
+ "md": 3,
94
+ "lg": 3
95
+ },
96
+ "includeIrradiance": {
97
+ "type": "checkbox",
98
+ "label": {
99
+ "en": "Irradiance (GHI, DHI, BNI)",
100
+ "de": "Einstrahlung (GHI, DHI, BNI)"
101
+ },
102
+ "xs": 12,
103
+ "sm": 6,
104
+ "md": 3,
105
+ "lg": 3
106
+ },
107
+ "includeClearsky": {
108
+ "type": "checkbox",
109
+ "label": {
110
+ "en": "Clear-sky power",
111
+ "de": "Leistung bei klarem Himmel"
112
+ },
113
+ "xs": 12,
114
+ "sm": 6,
115
+ "md": 3,
116
+ "lg": 3
117
+ },
118
+ "useVariability": {
119
+ "type": "checkbox",
120
+ "label": {
121
+ "en": "Variability band (min/max, paid plans)",
122
+ "de": "Schwankungsband (min/max, Bezahlpläne)"
123
+ },
124
+ "help": {
125
+ "en": "Used automatically if your plan includes it",
126
+ "de": "Wird automatisch genutzt, wenn dein Plan es enthält"
127
+ },
128
+ "xs": 12,
129
+ "sm": 6,
130
+ "md": 3,
131
+ "lg": 3
132
+ },
133
+ "createSvg": {
134
+ "type": "checkbox",
135
+ "label": {
136
+ "en": "Create SVG charts for VIS (html.*)",
137
+ "de": "SVG-Diagramme für VIS erzeugen (html.*)"
138
+ },
139
+ "newLine": true,
140
+ "xs": 12,
141
+ "sm": 12,
142
+ "md": 6,
143
+ "lg": 6
144
+ },
145
+ "_divider": {
146
+ "type": "divider",
147
+ "newLine": true
148
+ },
149
+ "_pvnode": {
150
+ "type": "staticLink",
151
+ "href": "https://pvnode.com/",
152
+ "text": {
153
+ "en": "pvnode.com",
154
+ "de": "pvnode.com"
155
+ },
156
+ "newLine": true,
157
+ "style": {
158
+ "fontSize": "0.85em",
159
+ "opacity": 0.7,
160
+ "display": "inline-block",
161
+ "marginTop": 30
162
+ },
163
+ "xs": 6,
164
+ "sm": 6,
165
+ "md": 6,
166
+ "lg": 6
167
+ },
168
+ "_donate": {
169
+ "type": "staticImage",
170
+ "src": "coffee.png",
171
+ "href": "https://buymeacoffee.com/alpi_brv",
172
+ "style": {
173
+ "width": 200,
174
+ "height": 50,
175
+ "display": "block",
176
+ "marginLeft": "auto",
177
+ "marginTop": 16,
178
+ "marginRight": 16,
179
+ "marginBottom": 16,
180
+ "cursor": "pointer"
181
+ },
182
+ "xs": 6,
183
+ "sm": 6,
184
+ "md": 6,
185
+ "lg": 6
186
+ }
187
+ }
188
+ }
Binary file
@@ -0,0 +1,199 @@
1
+ {
2
+ "common": {
3
+ "name": "pvnode",
4
+ "version": "0.2.0",
5
+ "news": {
6
+ "0.2.0": {
7
+ "en": "First public release: pvnode API v2 for all plans (Free, Light, Plus), per-string values, remaining energy, ready-made SVG charts for VIS",
8
+ "de": "Erste öffentliche Version: pvnode API v2 für alle Pläne (Kostenlos, Light, Plus), Werte pro String, Restertrag, fertige SVG-Diagramme für VIS",
9
+ "ru": "Первый публичный выпуск: pvnode API v2 для всех тарифов (Free, Light, Plus), значения по стрингам, оставшаяся энергия, готовые SVG-графики для VIS",
10
+ "pt": "Primeira versão pública: pvnode API v2 para todos os planos (Free, Light, Plus), valores por string, energia restante, gráficos SVG prontos para VIS",
11
+ "nl": "Eerste publieke versie: pvnode API v2 voor alle abonnementen (Free, Light, Plus), waarden per string, resterende energie, kant-en-klare SVG-grafieken voor VIS",
12
+ "fr": "Première version publique : pvnode API v2 pour toutes les offres (Free, Light, Plus), valeurs par chaîne, énergie restante, graphiques SVG prêts pour VIS",
13
+ "it": "Prima versione pubblica: pvnode API v2 per tutti i piani (Free, Light, Plus), valori per stringa, energia residua, grafici SVG pronti per VIS",
14
+ "es": "Primera versión pública: pvnode API v2 para todos los planes (Free, Light, Plus), valores por string, energía restante, gráficos SVG listos para VIS",
15
+ "pl": "Pierwsza publiczna wersja: pvnode API v2 dla wszystkich planów (Free, Light, Plus), wartości dla stringów, pozostała energia, gotowe wykresy SVG dla VIS",
16
+ "uk": "Перший публічний випуск: pvnode API v2 для всіх тарифів (Free, Light, Plus), значення за стрингами, залишкова енергія, готові SVG-графіки для VIS",
17
+ "zh-cn": "首个公开版本:支持所有套餐(Free、Light、Plus)的 pvnode API v2,各组串数值、剩余发电量、适用于 VIS 的现成 SVG 图表"
18
+ },
19
+ "0.1.4": {
20
+ "en": "Ready-made SVG charts for VIS (html.today, html.tomorrow, html.days)",
21
+ "de": "Fertige SVG-Diagramme für VIS (html.today, html.tomorrow, html.days)",
22
+ "ru": "Готовые SVG-графики для VIS (html.today, html.tomorrow, html.days)",
23
+ "pt": "Gráficos SVG prontos para VIS (html.today, html.tomorrow, html.days)",
24
+ "nl": "Kant-en-klare SVG-grafieken voor VIS (html.today, html.tomorrow, html.days)",
25
+ "fr": "Graphiques SVG prêts à l'emploi pour VIS (html.today, html.tomorrow, html.days)",
26
+ "it": "Grafici SVG pronti per VIS (html.today, html.tomorrow, html.days)",
27
+ "es": "Gráficos SVG listos para VIS (html.today, html.tomorrow, html.days)",
28
+ "pl": "Gotowe wykresy SVG dla VIS (html.today, html.tomorrow, html.days)",
29
+ "uk": "Готові SVG-графіки для VIS (html.today, html.tomorrow, html.days)",
30
+ "zh-cn": "适用于 VIS 的现成 SVG 图表(html.today、html.tomorrow、html.days)"
31
+ },
32
+ "0.1.3": {
33
+ "en": "Much lower memory and CPU usage (date formatters are cached)",
34
+ "de": "Deutlich weniger Speicher- und CPU-Verbrauch (Datumsformate werden zwischengespeichert)",
35
+ "ru": "Значительно меньшее потребление памяти и CPU (кэширование форматов даты)",
36
+ "pt": "Uso de memória e CPU muito menor (formatadores de data em cache)",
37
+ "nl": "Veel lager geheugen- en CPU-gebruik (datumformatters worden gecachet)",
38
+ "fr": "Consommation mémoire et CPU nettement réduite (formateurs de date mis en cache)",
39
+ "it": "Uso di memoria e CPU molto inferiore (formattatori di data in cache)",
40
+ "es": "Uso de memoria y CPU mucho menor (formateadores de fecha en caché)",
41
+ "pl": "Znacznie mniejsze zużycie pamięci i CPU (buforowanie formaterów dat)",
42
+ "uk": "Значно менше споживання пам'яті та CPU (кешування форматів дати)",
43
+ "zh-cn": "内存和 CPU 占用大幅降低(缓存日期格式化器)"
44
+ },
45
+ "0.1.2": {
46
+ "en": "Coffee cup button in settings",
47
+ "de": "Kaffeebecher-Button in den Einstellungen",
48
+ "ru": "Кнопка с чашкой кофе в настройках",
49
+ "pt": "Botão de chávena de café nas configurações",
50
+ "nl": "Koffiekop-knop in de instellingen",
51
+ "fr": "Bouton tasse de café dans les paramètres",
52
+ "it": "Pulsante tazza di caffè nelle impostazioni",
53
+ "es": "Botón de taza de café en la configuración",
54
+ "pl": "Przycisk z filiżanką kawy w ustawieniach",
55
+ "uk": "Кнопка з чашкою кави в налаштуваннях",
56
+ "zh-cn": "设置中的咖啡杯按钮"
57
+ },
58
+ "0.1.1": {
59
+ "en": "Smaller donation link in settings, Buy me a coffee link added",
60
+ "de": "Dezenterer Spenden-Link in den Einstellungen, Buy-me-a-coffee-Link eingetragen",
61
+ "ru": "Более скромная ссылка для пожертвований в настройках, добавлена ссылка Buy me a coffee",
62
+ "pt": "Link de doação mais discreto nas configurações, link Buy me a coffee adicionado",
63
+ "nl": "Kleinere donatielink in de instellingen, Buy me a coffee-link toegevoegd",
64
+ "fr": "Lien de don plus discret dans les paramètres, lien Buy me a coffee ajouté",
65
+ "it": "Link per donazioni più discreto nelle impostazioni, aggiunto link Buy me a coffee",
66
+ "es": "Enlace de donación más discreto en la configuración, enlace Buy me a coffee añadido",
67
+ "pl": "Mniej widoczny link do darowizn w ustawieniach, dodano link Buy me a coffee",
68
+ "uk": "Менш помітне посилання для пожертв у налаштуваннях, додано посилання Buy me a coffee",
69
+ "zh-cn": "设置中的捐赠链接更低调,已添加 Buy me a coffee 链接"
70
+ },
71
+ "0.1.0": {
72
+ "en": "Initial release: pvnode API v2, all plans (Free, Light, Plus), polling based on next_poll_at",
73
+ "de": "Erste Version: pvnode API v2, alle Pläne (Kostenlos, Light, Plus), Abfrage nach next_poll_at",
74
+ "ru": "Первый выпуск: pvnode API v2, все тарифы (Free, Light, Plus), опрос по next_poll_at",
75
+ "pt": "Versão inicial: pvnode API v2, todos os planos (Free, Light, Plus), consulta baseada em next_poll_at",
76
+ "nl": "Eerste versie: pvnode API v2, alle abonnementen (Free, Light, Plus), polling op basis van next_poll_at",
77
+ "fr": "Première version : pvnode API v2, toutes les offres (Free, Light, Plus), interrogation selon next_poll_at",
78
+ "it": "Prima versione: pvnode API v2, tutti i piani (Free, Light, Plus), interrogazione basata su next_poll_at",
79
+ "es": "Versión inicial: pvnode API v2, todos los planes (Free, Light, Plus), consulta basada en next_poll_at",
80
+ "pl": "Pierwsza wersja: pvnode API v2, wszystkie plany (Free, Light, Plus), odpytywanie według next_poll_at",
81
+ "uk": "Перший випуск: pvnode API v2, усі тарифи (Free, Light, Plus), опитування за next_poll_at",
82
+ "zh-cn": "首个版本:pvnode API v2,支持所有套餐(Free、Light、Plus),按 next_poll_at 轮询"
83
+ }
84
+ },
85
+ "titleLang": {
86
+ "en": "pvnode PV forecast",
87
+ "de": "pvnode PV-Prognose",
88
+ "ru": "Прогноз PV pvnode",
89
+ "pt": "Previsão FV pvnode",
90
+ "nl": "pvnode PV-voorspelling",
91
+ "fr": "Prévision PV pvnode",
92
+ "it": "Previsione FV pvnode",
93
+ "es": "Previsión FV pvnode",
94
+ "pl": "Prognoza PV pvnode",
95
+ "uk": "Прогноз PV pvnode",
96
+ "zh-cn": "pvnode 光伏预测"
97
+ },
98
+ "desc": {
99
+ "en": "PV production forecast from pvnode.com (API v2) with per-string values, remaining energy and chart data",
100
+ "de": "PV-Ertragsprognose von pvnode.com (API v2) mit Werten pro String, Restertrag und Diagrammdaten",
101
+ "ru": "Прогноз выработки PV от pvnode.com (API v2) со значениями по стрингам, оставшейся энергией и данными для графиков",
102
+ "pt": "Previsão de produção FV do pvnode.com (API v2) com valores por string, energia restante e dados para gráficos",
103
+ "nl": "PV-opbrengstvoorspelling van pvnode.com (API v2) met waarden per string, resterende energie en grafiekgegevens",
104
+ "fr": "Prévision de production PV de pvnode.com (API v2) avec valeurs par chaîne, énergie restante et données de graphique",
105
+ "it": "Previsione di produzione FV da pvnode.com (API v2) con valori per stringa, energia residua e dati per grafici",
106
+ "es": "Previsión de producción FV de pvnode.com (API v2) con valores por string, energía restante y datos para gráficos",
107
+ "pl": "Prognoza produkcji PV z pvnode.com (API v2) z wartościami dla stringów, pozostałą energią i danymi do wykresów",
108
+ "uk": "Прогноз виробітку PV від pvnode.com (API v2) зі значеннями за стрингами, залишковою енергією та даними для графіків",
109
+ "zh-cn": "来自 pvnode.com (API v2) 的光伏发电预测,包含各组串数值、剩余发电量和图表数据"
110
+ },
111
+ "authors": [
112
+ "AlPi-BRV"
113
+ ],
114
+ "keywords": [
115
+ "pvnode",
116
+ "pv",
117
+ "solar",
118
+ "forecast",
119
+ "prognose",
120
+ "photovoltaik"
121
+ ],
122
+ "licenseInformation": {
123
+ "type": "free",
124
+ "license": "MIT"
125
+ },
126
+ "platform": "Javascript/Node.js",
127
+ "icon": "pvnode.png",
128
+ "extIcon": "https://raw.githubusercontent.com/AlPi-BRV/ioBroker.pvnode/main/admin/pvnode.png",
129
+ "readme": "https://github.com/AlPi-BRV/ioBroker.pvnode/blob/main/README.md",
130
+ "enabled": true,
131
+ "loglevel": "info",
132
+ "tier": 3,
133
+ "mode": "daemon",
134
+ "type": "energy",
135
+ "compact": true,
136
+ "connectionType": "cloud",
137
+ "dataSource": "poll",
138
+ "adminUI": {
139
+ "config": "json"
140
+ },
141
+ "messagebox": true,
142
+ "dependencies": [
143
+ {
144
+ "js-controller": ">=6.0.11"
145
+ }
146
+ ],
147
+ "globalDependencies": [
148
+ {
149
+ "admin": ">=7.0.23"
150
+ }
151
+ ]
152
+ },
153
+ "native": {
154
+ "apiKey": "",
155
+ "siteId": "",
156
+ "forecastDays": 0,
157
+ "includeWeather": true,
158
+ "includeIrradiance": false,
159
+ "includeClearsky": false,
160
+ "useVariability": true,
161
+ "createSvg": true
162
+ },
163
+ "encryptedNative": [
164
+ "apiKey"
165
+ ],
166
+ "protectedNative": [
167
+ "apiKey"
168
+ ],
169
+ "objects": [],
170
+ "instanceObjects": [
171
+ {
172
+ "_id": "info",
173
+ "type": "channel",
174
+ "common": {
175
+ "name": {
176
+ "en": "Information",
177
+ "de": "Information"
178
+ }
179
+ },
180
+ "native": {}
181
+ },
182
+ {
183
+ "_id": "info.connection",
184
+ "type": "state",
185
+ "common": {
186
+ "role": "indicator.connected",
187
+ "name": {
188
+ "en": "Connected to pvnode",
189
+ "de": "Verbunden mit pvnode"
190
+ },
191
+ "type": "boolean",
192
+ "read": true,
193
+ "write": false,
194
+ "def": false
195
+ },
196
+ "native": {}
197
+ }
198
+ ]
199
+ }
package/lib/api.js ADDED
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ const BASE_URL = 'https://api.pvnode.com';
4
+ const TIMEOUT_MS = 30000;
5
+
6
+ class PvnodeError extends Error {
7
+ /**
8
+ * @param {string} message error message
9
+ * @param {number} status HTTP status (0 = network error)
10
+ * @param {string} detail detail text from the API
11
+ * @param {object} quota parsed quota headers
12
+ */
13
+ constructor(message, status, detail, quota) {
14
+ super(message);
15
+ this.name = 'PvnodeError';
16
+ this.status = status;
17
+ this.detail = detail || '';
18
+ this.quota = quota || null;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Parse the RequestLimit-* headers. Limit/Remaining may be "unmetered".
24
+ *
25
+ * @param {Headers} headers fetch response headers
26
+ */
27
+ function parseQuota(headers) {
28
+ const limit = headers.get('requestlimit-limit');
29
+ if (limit === null) {
30
+ return null;
31
+ }
32
+ const num = v => (v !== null && v !== '' && !Number.isNaN(Number(v)) ? Number(v) : v);
33
+ return {
34
+ limit: num(limit),
35
+ used: num(headers.get('requestlimit-used')),
36
+ remaining: num(headers.get('requestlimit-remaining')),
37
+ reset: headers.get('requestlimit-reset'),
38
+ };
39
+ }
40
+
41
+ class PvnodeApi {
42
+ /**
43
+ * @param {string} apiKey pvnode API key
44
+ * @param {string} userAgent User-Agent header value
45
+ */
46
+ constructor(apiKey, userAgent) {
47
+ this.apiKey = apiKey;
48
+ this.userAgent = userAgent;
49
+ }
50
+
51
+ async _get(path) {
52
+ const ctrl = new AbortController();
53
+ const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
54
+ let res;
55
+ try {
56
+ res = await fetch(BASE_URL + path, {
57
+ headers: {
58
+ Authorization: `Bearer ${this.apiKey}`,
59
+ 'User-Agent': this.userAgent,
60
+ Accept: 'application/json',
61
+ },
62
+ signal: ctrl.signal,
63
+ });
64
+ } catch (err) {
65
+ throw new PvnodeError(`Network error: ${err.name === 'AbortError' ? 'timeout' : err.message}`, 0, '', null);
66
+ } finally {
67
+ clearTimeout(timer);
68
+ }
69
+ const quota = parseQuota(res.headers);
70
+ const text = await res.text();
71
+ let body = null;
72
+ try {
73
+ body = text ? JSON.parse(text) : null;
74
+ } catch {
75
+ body = null;
76
+ }
77
+ if (!res.ok) {
78
+ const detail = body && typeof body.detail === 'string' ? body.detail : text.slice(0, 300);
79
+ throw new PvnodeError(`HTTP ${res.status}: ${detail}`, res.status, detail, quota);
80
+ }
81
+ if (body === null) {
82
+ throw new PvnodeError('Invalid JSON response', res.status, text.slice(0, 300), quota);
83
+ }
84
+ return { body, quota };
85
+ }
86
+
87
+ /** List sites. Does not consume forecast quota; validates the key (401 = invalid). */
88
+ async getSites() {
89
+ const { body } = await this._get('/v2/sites/');
90
+ return Array.isArray(body) ? body : [];
91
+ }
92
+
93
+ /**
94
+ * Get forecast for a saved site.
95
+ *
96
+ * @param {string} siteId site id
97
+ * @param {string[]} include include groups
98
+ * @param {number} [forecastDays] 0/undefined = plan maximum
99
+ */
100
+ async getForecast(siteId, include, forecastDays) {
101
+ const params = new URLSearchParams();
102
+ for (const g of include) {
103
+ params.append('include', g);
104
+ }
105
+ if (forecastDays && forecastDays > 0) {
106
+ params.set('forecast_days', String(forecastDays));
107
+ }
108
+ return this._get(`/v2/forecast/${encodeURIComponent(siteId)}?${params.toString()}`);
109
+ }
110
+ }
111
+
112
+ module.exports = { PvnodeApi, PvnodeError, parseQuota };