alpha_ess 1.0 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -9
- data/alpha_ess-1.1.gem +0 -0
- data/alpha_ess.gemspec +3 -2
- data/lib/alpha_ess.rb +54 -8
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3403efae3e758f4f8ef2593edc6bdf9d268a34367ff99ab93a78cc80d007828f
|
4
|
+
data.tar.gz: 54233da976a52b1dd3c6a46cdcec89932398f9272eeedc54fc384714d27d3afc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d985dbad128c6b41adf906cf41d0dfe8ffcbf2fbf9ece3bfa83d20cca55bc4a8168d47daf8db80607bf52c750d2b14450dabc0a2a0a3c3248fa94001b96f0f3
|
7
|
+
data.tar.gz: 92e0ae0059e060ac6ccb7a6546df84b57b246188b82192768a713c5d81a0a62639f49902f21be0a62a6b26aedb3ed533219c4cb7dd30b0a049a772b3b23fe9f3
|
data/README.md
CHANGED
@@ -79,18 +79,27 @@ ae.send_pushover_alarm_by_soc("Nachrichtentext ...", po_user, po_token)
|
|
79
79
|
|
80
80
|
Wenn ihr wissen wollt, was die einzelnen Funktionen zurückgeben und wo ihr welche Daten findet, dann probiert es einfach aus. Ich werde sicherlich bald ein youtube Video dazu machen, wo ich das vorführe.
|
81
81
|
|
82
|
-
Folgende
|
82
|
+
Folgende 4 Funktionen für das Abholen von Daten gibt es derzeit:
|
83
83
|
|
84
|
-
- get_stics_by_day, bringt statische Daten des Tages
|
84
|
+
- get_stics_by_day, bringt statische Daten des aktuellen Tages
|
85
|
+
- get_stics_by_period, bringt statische Daten bezogen auf einen Zeitraum von ganzen Tagen
|
85
86
|
- get_last_power_data, bringt aktuelle Betriebsdaten (momentaner Verbrauch / Erzeugung etc.)
|
86
87
|
- get_custom_use_ess_setting, holt Daten zur aktuellen Systemeinstellung
|
87
88
|
|
89
|
+
## Systemeinstellungen verändern
|
90
|
+
|
91
|
+
Hier wird es spannend. Die Funktion `set_custom_use_ess_setting` erwartet einen Ruby-Hash. Wie die Schlüssel und Werte aussehen sollten, lassen sich aus der Ausgabe der Funktion `get_custom_use_ess_setting` ableiten.
|
92
|
+
Am besten Ihr spielt in den Einstellungen auf der Website herum speichert sie und prüft mit `get_custom_use_ess_setting` welche Schlüssel sich wie verändert haben. Dann habt ihr einen Idee wie ihr diese Werte per Script setzen
|
93
|
+
könnt. Viel Erfolg :-) .
|
94
|
+
|
95
|
+
Hinweis: Man kann über `get_custom_use_ess_setting` die Einstellungen sichern. Einfach die Ausgabe in eine Datei schreiben.
|
96
|
+
|
88
97
|
## aktuellen Status abfragen
|
89
98
|
|
90
99
|
Die Daten über `/api/ESS/GetLastPowerDataBySN` werden alle 10 Sekunden von der API neu bereitgestellt.
|
91
100
|
|
92
101
|
```ruby
|
93
|
-
|
102
|
+
require "alpha_ess"
|
94
103
|
ae = AlphaEss.new
|
95
104
|
data = ae.get_last_power_data()
|
96
105
|
netz = data["pmeter_l1"].to_f + data["pmeter_l2"].to_f + data["pmeter_l3"].to_f
|
@@ -111,16 +120,17 @@ Hier die Ausgabe und der Vergleich zur Website:
|
|
111
120
|
|
112
121
|
![picture 1](images/b965404834760626afe73785811995faa1629d2ab66a53f966443fbf22463a67.png)
|
113
122
|
|
114
|
-
|
115
123
|
## pushover Alarm auslösen, wenn die PV-Anlage einen speziellen Status hat
|
116
124
|
|
117
125
|
```ruby
|
118
|
-
|
126
|
+
require "alpha_ess"
|
119
127
|
ae = AlphaEss.new
|
120
128
|
ae_data = ae.get_last_power_data()
|
121
|
-
batterie_ladung_erwartet =
|
122
|
-
if (ae_data["soc"].to_f <
|
123
|
-
ae.send_pushover_alarm_by_soc "Die Batterie hat aktuell
|
129
|
+
batterie_ladung_erwartet = 15
|
130
|
+
if (ae_data["soc"].to_f < batterie_ladung_erwartet)
|
131
|
+
ae.send_pushover_alarm_by_soc "Die Batterie hat aktuell eine Ladung von #{ae_data["soc"]} %, erwartet sind #{batterie_ladung_erwartet} %!"
|
132
|
+
else
|
133
|
+
puts "OK, die Ladung beträgt derzeit #{ae_data["soc"]} %."
|
124
134
|
end
|
125
135
|
# ae.set_min_soc(((ae_data["soc"].to_f)+0.9).to_i)
|
126
136
|
# sleep 10
|
@@ -134,7 +144,7 @@ end
|
|
134
144
|
## update ESS Settings
|
135
145
|
|
136
146
|
```ruby
|
137
|
-
|
147
|
+
require "alpha_ess"
|
138
148
|
ae = AlphaEss.new
|
139
149
|
bat_min = ae.get_custom_use_ess_setting()["bat_use_cap"]
|
140
150
|
puts "Batterie-Minimum: #{bat_min}"
|
@@ -142,3 +152,15 @@ ae.set_custom_use_ess_setting({"bat_use_cap" => 15})
|
|
142
152
|
bat_min = ae.get_custom_use_ess_setting()["bat_use_cap"]
|
143
153
|
puts "Batterie-Minimum neu: #{bat_min}"
|
144
154
|
```
|
155
|
+
|
156
|
+
## Statischtische Daten über einen Zeitraum abfragen
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
require "alpha_ess"
|
160
|
+
ae = AlphaEss.new
|
161
|
+
# aktueller Tag
|
162
|
+
ae.get_stics_by_period()
|
163
|
+
# letzte 3 Tage, ohne den aktuellen Tag
|
164
|
+
ae.get_stics_by_period( (Time.now-86400*3).strftime("%Y-%m-%d"), (Time.now-86400).strftime("%Y-%m-%d"))
|
165
|
+
```
|
166
|
+
|
data/alpha_ess-1.1.gem
ADDED
Binary file
|
data/alpha_ess.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'alpha_ess'
|
3
|
-
spec.version = '1.
|
4
|
-
spec.date = '2022-10-
|
3
|
+
spec.version = '1.2'
|
4
|
+
spec.date = '2022-10-31'
|
5
5
|
spec.summary = "Alpha Ess API Calls"
|
6
6
|
spec.description = "a Ruby class for Alpha-Ess-API-Calls"
|
7
7
|
spec.authors = ["Oliver Gaida"]
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.homepage = 'https://github.com/ogaida/alpha_ess'
|
11
11
|
#spec.executables = %w(rusdc)
|
12
12
|
spec.add_runtime_dependency 'httparty'
|
13
|
+
spec.add_runtime_dependency 'digest'
|
13
14
|
#spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
|
14
15
|
spec.license = 'MIT'
|
15
16
|
end
|
data/lib/alpha_ess.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
require "httparty"
|
2
|
+
require "digest"
|
2
3
|
|
3
4
|
class AlphaEss
|
4
5
|
|
6
|
+
AUTHPREFIX = "al8e4s"
|
7
|
+
AUTHCONSTANT = "LS885ZYDA95JVFQKUIUUUV7PQNODZRDZIS4ERREDS0EED8BCWSS"
|
8
|
+
AUTHSUFFIX = "ui893ed"
|
9
|
+
|
5
10
|
def initialize(sn = ENV["ess_serial"], u = ENV["ess_username"], p = ENV["ess_password"])
|
6
11
|
@serial, @username, @password = sn, u, p
|
7
12
|
get_token()
|
8
13
|
end
|
9
14
|
|
10
15
|
def get_stics_by_day()
|
11
|
-
today = Time.now.strftime("%Y-%m-%d")
|
12
16
|
body = {
|
13
17
|
"sn" => @serial,
|
14
18
|
"userId" => @serial,
|
15
|
-
"szDay" =>
|
19
|
+
"szDay" => Time.now.strftime("%Y-%m-%d"),
|
16
20
|
"isOEM" => 0,
|
17
|
-
"sDate" =>
|
21
|
+
"sDate" => Time.now.strftime("%Y-%m-%d")
|
18
22
|
}
|
19
23
|
url = "https://cloud.alphaess.com/api/Power/SticsByDay"
|
20
24
|
res = HTTParty.post(url, headers: header(), body: body.to_json)
|
@@ -31,6 +35,20 @@ class AlphaEss
|
|
31
35
|
res.parsed_response["data"]
|
32
36
|
end
|
33
37
|
|
38
|
+
def get_stics_by_period(beginDay = Time.now.strftime("%Y-%m-%d"), endDay = Time.now.strftime("%Y-%m-%d"))
|
39
|
+
body = {
|
40
|
+
"beginDay" => beginDay,
|
41
|
+
"endDay" => endDay,
|
42
|
+
"tday" => Time.now.strftime("%Y-%m-%d"),
|
43
|
+
"isOEM" => 0,
|
44
|
+
"SN" => @serial,
|
45
|
+
"noLoading" => true
|
46
|
+
}
|
47
|
+
url = "https://cloud.alphaess.com/api/Power/SticsByPeriod"
|
48
|
+
res = HTTParty.post(url, headers: header(), body: body.to_json)
|
49
|
+
res.parsed_response["data"]
|
50
|
+
end
|
51
|
+
|
34
52
|
def get_custom_use_ess_setting()
|
35
53
|
url = "https://cloud.alphaess.com/api/Account/GetCustomUseESSSetting"
|
36
54
|
res = HTTParty.get(url, headers: header())
|
@@ -58,7 +76,7 @@ class AlphaEss
|
|
58
76
|
}, body: body.to_json)
|
59
77
|
end
|
60
78
|
|
61
|
-
private
|
79
|
+
private
|
62
80
|
|
63
81
|
def get_token()
|
64
82
|
Dir.mkdir "#{ENV["HOME"]}/.alpha_ess" if ! (Dir.exists?"#{ENV["HOME"]}/.alpha_ess")
|
@@ -87,21 +105,49 @@ class AlphaEss
|
|
87
105
|
res = HTTParty.post(url, headers: {
|
88
106
|
"Accept" => "application/json",
|
89
107
|
"Content-Type" => "application/json;charset=UTF-8"
|
90
|
-
}, body: body.to_json)
|
108
|
+
}.update(secure_header_addon()), body: body.to_json)
|
91
109
|
@token = res.parsed_response["data"]["AccessToken"]
|
92
110
|
@token_valid_to = Time.now.to_i+36000
|
93
111
|
save_token()
|
94
112
|
end
|
95
113
|
|
114
|
+
def secure_header_addon()
|
115
|
+
# thanks to https://github.com/CharlesGillanders
|
116
|
+
t = Time.now.to_i
|
117
|
+
{
|
118
|
+
"authtimestamp" => t,
|
119
|
+
"authsignature" => "#{AUTHPREFIX}#{Digest::SHA2.new(512).hexdigest("#{AUTHCONSTANT}#{t}")}#{AUTHSUFFIX}"
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
96
123
|
def header(hash={})
|
97
124
|
get_token()
|
98
|
-
|
125
|
+
{
|
99
126
|
"Accept" => "application/json",
|
100
127
|
"Content-Type" => "application/json;charset=UTF-8",
|
101
128
|
"Authorization" => "Bearer #{@token}"
|
102
|
-
}.update
|
103
|
-
|
129
|
+
}.update(hash).update(secure_header_addon())
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# some extensions for easier visualise data in irb
|
134
|
+
|
135
|
+
module Jsonpretty
|
136
|
+
def jp
|
137
|
+
# return in json_pretty
|
138
|
+
JSON.pretty_generate(self)
|
139
|
+
end
|
140
|
+
def jpp
|
141
|
+
# print in json_pretty
|
142
|
+
puts JSON.pretty_generate(self)
|
104
143
|
end
|
105
144
|
end
|
106
145
|
|
146
|
+
class Hash
|
147
|
+
include Jsonpretty
|
148
|
+
end
|
149
|
+
|
150
|
+
class Array
|
151
|
+
include Jsonpretty
|
152
|
+
end
|
107
153
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alpha_ess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Gaida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: digest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: a Ruby class for Alpha-Ess-API-Calls
|
28
42
|
email: ogaida@t-online.de
|
29
43
|
executables: []
|
@@ -32,6 +46,7 @@ extra_rdoc_files: []
|
|
32
46
|
files:
|
33
47
|
- LICENSE.md
|
34
48
|
- README.md
|
49
|
+
- alpha_ess-1.1.gem
|
35
50
|
- alpha_ess.gemspec
|
36
51
|
- images/b965404834760626afe73785811995faa1629d2ab66a53f966443fbf22463a67.png
|
37
52
|
- lib/alpha_ess.rb
|