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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
| ----------------------------------------------------------------------------------------------------------
-- /home/pi/domoticz/scripts/lua/script_device_aurora.lua
----------------------------------------------------------------------------------------------------------
-- This script collects the values directly from a one-line.csv
-- Copy http://www.curtronics.com/Solar/ftp/aurora-1.9.3.tar.gz in /home/pi and extract with tar -xvf aurora-1.9.3.tar.gz and sudo make to install it.
-- * A single line csv with the latest Power one, Aurora data
--
-- To send the value to Domoticz enter the *IDX and *Name
----------------------------------------------------------------------------------------------------------
-- Written by Alphons Uijtdehaag (Auijtdehaag) 2017
----------------------------------------------------------------------------------------------------------
-- V1.0 Initial versions
----------------------------------------------------------------------------------------------------------
--
----------------------------------------------------------------------------------------------------------
-- Domoticz IDX and names of the needed devices
----------------------------------------------------------------------------------------------------------
-- System settings
local AuroraData = "/home/pi/aurora-1.9.3" -- Location of Aurora installation on the Pi
local GenerationDeviceName = "Zonnepanelen" -- Device name of the Generated energy
-- Domoticz IDX
local Udc1IDX = 7 -- IDX of the energy device that shows Udc1 voltage (volt)
local Idc1IDX = 8 -- IDX of the energy device that shows Idc2 current (ampere)
local Pdc1IDX = 9 -- IDX of the energy device that shows Pdc1 power (watt)
local Udc2IDX = 10 -- IDX of the energy device that shows Udc2 voltage (volt)
local Idc2IDX = 11 -- IDX of the energy device that shows Idc1 current (ampere)
local Pdc2IDX = 12 -- IDX of the energy device that shows Pdc2 power (watt)
local Uac1IDX = 13 -- IDX of the energy device that shows Uac1 voltage (volt)
local Iac1IDX = 14 -- IDX of the energy device that shows Iac1 current (ampere)
local Pac1IDX = 15 -- IDX of the energy device that shows Pac1 power (watt)
local FrequencyIDX = 20 -- IDX of the energy device that shows frequency (Hz)
local EfficiencyIDX = 17 -- IDX of the energy device that shows the efficiency (%)
local InverterTempIDX = 18 -- IDX of the energy device that shows inverter temperature (degrees C)
local BoosterTempIDX = 19 -- IDX of the energy device that shows booster temperature (degrees C)
local DailyEnergyIDX = 54 -- IDX of the energy device that shows today's generated electricity (kWh)
local WeeklyEnergyIDX = 0 -- IDX of the energy device that shows daily generated electricity (kWh)
local UnknownParameterIDX = 0
local MonthlyEnergyIDX = 51 -- IDX of the energy device that shows weekly generated electricity (kWh)
local YearlyEnergyIDX = 52 -- IDX of the energy device that shows yearly generated electricity (kWh)
local TotalEnergyIDX = 53 -- IDX of the energy device that shows total generated electricity (kWh)
local PartialEnergyIDX = 0 -- IDX of the energy device that shows total generated electricity (kWh)
local InverterActiveIDX = 0 -- IDX of the energy device that shows inverter is active
-- Domoticz device names
local Udc1DeviceName = "Udc1" -- DeviceName of the energy device that shows Udc1 voltage (volt)
local Idc1DeviceName = "Idc1" -- DeviceName of the energy device that shows Idc2 current (ampere)
local Pdc1DeviceName = "Pdc1" -- DeviceName of the energy device that shows Pdc1 power (watt)
local Udc2DeviceName = "Udc2" -- DeviceName of the energy device that shows Udc2 voltage (volt)
local Idc2DeviceName = "Idc2" -- DeviceName of the energy device that shows Idc1 current (ampere)
local Pdc2DeviceName = "Pdc2" -- DeviceName of the energy device that shows Pdc2 power (watt)
local Uac1DeviceName = "Uac1" -- DeviceName of the energy device that shows Uac1 voltage (volt)
local Iac1DeviceName = "Iac1" -- DeviceName of the energy device that shows Iac1 current (ampere)
local Pac1DeviceName = "Pac1" -- DeviceName of the energy device that shows Pac1 power (watt)
local FrequencyDeviceName = "Frequency" -- DeviceName of the energy device that shows frequency (Hz)
local EfficiencyDeviceName = "Efficiency" -- DeviceName of the energy device that shows the efficiency (%)
local InverterTempDeviceName = "InverterTemp" -- DeviceName of the energy device that shows inverter temperature (degrees C)
local BoosterTempDeviceName = "BoosterTemp" -- DeviceName of the energy device that shows booster temperature (degrees C)
local DailyEnergyDeviceName = "Aurora Dag" -- DeviceName of the energy device that shows today's generated electricity (kWh)
local WeeklyEnergyDeviceName = "EWeekly" -- DeviceName of the energy device that shows daily generated electricity (kWh)
local UnknownParameterDeviceName = "Unknown"
local MonthlyEnergyDeviceName = "Aurora Maand" -- DeviceName of the energy device that shows weekly generated electricity (kWh)
local YearlyEnergyDeviceName = "Aurora Jaar" -- DeviceName of the energy device that shows yearly generated electricity (kWh)
local TotalEnergyDeviceName = "Aurora Totaal" -- DeviceName of the energy device that shows total generated electricity (kWh)
local PartialEnergyDeviceName = "EPartial" -- DeviceName of the energy device that shows partial generated electricity (kWh)
local InverterActive = "InverterActive" -- DeviceName of the energy device that shows inverter is active
----------------------------------------------------------------------------------------------------------
-- Require parameters
----------------------------------------------------------------------------------------------------------
-- None
----------------------------------------------------------------------------------------------------------
-- Script parameters including all parameters in sbfspot single line csv
----------------------------------------------------------------------------------------------------------
local CSVfile = AuroraData .. '/' .. 'one-line.csv'
CurrentTime = 0
Udc1 = 0
Idc1 = 0
Pdc1 = 0
Udc2 = 0
Idc2 = 0
Pdc2 = 0
Uac1 = 0
Iac1 = 0
Pac1 = 0
Frequency = 0
Efficiency = 0
InverterTemp = 0
BoosterTemp = 0
DailyEnergy = 0
WeeklyEnergy = 0
UnknownParameter = 0
MonthlyEnergy = 0
YearlyEnergy = 0
TotalEnergy = 0
PartialEnergy = 0
InverterActive = 0
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Lua Functions
----------------------------------------------------------------------------------------------------------
-- Update to domoticz
function update(device, id, value, index)
if Debug=="YES" then print("Lua Aurora: commandArray[" .. index .. "] = {['" ..device .. "'] = " .. id .. "|0|" .. value .."}") end
commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. value}
end
-- Round up number
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
if devicechanged[GenerationDeviceName] then
-- Read aurora single line csv file
if Debug=="YES" then
print("Lua Aurora: Using file: " .. CSVfile)
end
file = io.open(CSVfile, "r")
CurrentTime,Udc1,Idc1,Pdc1,Udc2,Idc2,Pdc2,Uac1,Iac1,Pac1,Frequency,Efficiency,InverterTemp,BoosterTemp,DailyEnergy,WeeklyEnergy,UnknownParameter,MonthlyEnergy,YearlyEnergy,TotalEnergy,PartialEnergy,InverterActive=file:read():match '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)'
-- remove comma's
if Debug=="YES" then
print("Lua Aurora: Replacing comma's with dots and rounding up/down")
end
-- Udc1=round(string.gsub(Udc1,"%,","."))
-- Idc1=round(string.gsub(Idc1,"%,","."),2)
-- Pdc1=round(string.gsub(Pdc1,"%,","."))
-- Udc2=round(string.gsub(Udc2,"%,","."))
-- Idc2=round(string.gsub(Idc2,"%,","."),2)
-- Pdc2=round(string.gsub(Pdc2,"%,","."))
-- Uac1=round(string.gsub(Uac1,"%,","."))
-- Iac1=round(string.gsub(Iac1,"%,","."),2)
-- Pac1=round(string.gsub(Pac1,"%,","."))
-- Frequency=round(string.gsub(Frequency,"%,","."),2)
-- Efficiency=round(string.gsub(Efficiency,"%,","."),2)
-- InverterTemp=round(string.gsub(InverterTemp,"%,","."),1)
-- BoosterTemp=round(string.gsub(BoosterTemp,"%,","."),1)
-- DailyEnergy=string.gsub(DailyEnergy,"%,",".")
-- WeeklyEnergy=string.gsub(WeeklyEnergy,"%,",".")
-- MonthlyEnergy=string.gsub(MonthlyEnergy,"%,",".")
-- YearlyEnergy=string.gsub(YearlyEnergy,"%,",".")
-- TotalEnergy=string.gsub(TotalEnergy,"%,",".")
-- PartialEnergy=string.gsub(PartialEnergy,"%,",".")
if Debug=="YES" then
print("Lua Aurora: CurrentDateTime= " .. CurrentTime)
print("Lua Aurora: Udc1= " .. Udc1.. " volt")
print("Lua Aurora: Idc1= " .. Idc1.. " ampere")
print("Lua Aurora: Pdc1= " .. Pdc1.. " watt")
print("Lua Aurora: Udc2= " .. Udc2.. " volt")
print("Lua Aurora: Idc2= " .. Idc2.. " ampere")
print("Lua Aurora: Pdc2= " .. Pdc2.. " watt")
print("Lua Aurora: Uac1= " .. Uac1.. " volt")
print("Lua Aurora: Iac1= " .. Iac1.. " ampere")
print("Lua Aurora: Pac1= " .. Pac1.. " watt")
print("Lua Aurora: Frequency= " .. Frequency.. " Hz")
print("Lua Aurora: Efficiency= " .. Efficiency .. " %")
print("Lua Aurora: InverterTemp= " .. InverterTemp .. " C")
print("Lua Aurora: BoosterTemp= " .. BoosterTemp .. " C")
print("Lua Aurora: DailyEnergy= " .. DailyEnergy .. " kWh")
print("Lua Aurora: WeeklyEnergy= " .. WeeklyEnergy .. " kWh")
print("Lua Aurora: UnknownParameter= " .. UnknownParameter .. " kWh")
print("Lua Aurora: MonthlyEnergy= " .. MonthlyEnergy .. " kWh")
print("Lua Aurora: YearlyEnergy= " .. YearlyEnergy .. " kWh")
print("Lua Aurora: TotalEnergy= " .. TotalEnergy .. " kWh")
print("Lua Aurora: PartialEnergy= " .. PartialEnergy .. " kWh")
print("Lua Aurora: InverterActive= " .. InverterActive)
end
-- Create array with values to update'
local count = 0
if Udc1IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Udc1DeviceName, Udc1IDX, Udc1, count) " .. Udc1DeviceName .. "," .. Udc1IDX .. "," .. Udc1 .. "," .. count) end
update(Udc1DeviceName, Udc1IDX, Udc1, count)
end
if Idc1IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Idc1DeviceName, Idc1IDX, Idc1, count) " .. Idc1DeviceName .. "," .. Idc1IDX .. "," .. Idc1 .. "," .. count) end
update(Idc1DeviceName, Idc1IDX, Idc1, count)
end
if Pdc1IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Pdc1DeviceName, Pdc1IDX, Pdc1, count) " .. Pdc1DeviceName .. "," .. Pdc1IDX .. "," .. Pdc1 .. "," .. count) end
update(Pdc1DeviceName, Pdc1IDX, Pdc1, count)
end
if Udc2IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Udc1DeviceName, Udc2IDX, Udc2, count) " .. Udc2DeviceName .. "," .. Udc2IDX .. "," .. Udc2 .. "," .. count) end
update(Udc2DeviceName, Udc2IDX, Udc2, count)
end
if Idc2IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Idc2DeviceName, Idc2IDX, Idc2, count) " .. Idc2DeviceName .. "," .. Idc2IDX .. "," .. Idc2 .. "," .. count) end
update(Idc2DeviceName, Idc2IDX, Idc2, count)
end
if Pdc2IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Pdc2DeviceName, Pdc2IDX, Pdc2, count) " .. Pdc2DeviceName .. "," .. Pdc2IDX .. "," .. Pdc2 .. "," .. count) end
update(Pdc2DeviceName, Pdc2IDX, Pdc2, count)
end
if Uac1IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Uac1DeviceName, Uac1IDX, Uac1, count) " .. Uac1DeviceName .. "," .. Uac1IDX .. "," .. Uac1 .. "," .. count) end
update(Uac1DeviceName, Uac1IDX, Uac1, count)
end
if Iac1IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Iac1DeviceName, Iac1IDX, Iac1, count) " .. Iac1DeviceName .. "," .. Iac1IDX .. "," .. Iac1 .. "," .. count) end
update(Iac1DeviceName, Iac1IDX, Iac1, count)
end
if Pac1IDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(Pac1DeviceName, Pac1IDX, Pac1, count) " .. Pac1DeviceName .. "," .. Pac1IDX .. "," .. Pac1 .. "," .. count) end
update(Pac1DeviceName, Pac1IDX, Pac1, count)
end
if FrequencyIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(FrequencyDeviceName, FrequencyIDX, Frequency, count) " .. FrequencyDeviceName .. "," .. FrequencyIDX .. "," .. Frequency .. "," .. count) end
update(FrequencyDeviceName, FrequencyIDX, Frequency, count)
end
if EfficiencyIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(EfficiencyDeviceName, EfficiencyIDX, Efficiency, count) " .. EfficiencyDeviceName .. "," .. EfficiencyIDX .. "," .. Efficiency*100 .. "," .. count) end
update(EfficiencyDeviceName, EfficiencyIDX, Efficiency, count)
end
if InverterTempIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(InverterTempDeviceName, InverterTempIDX, InverterTemp, count) " .. InverterTempDeviceName .. "," .. InverterTempIDX .. "," .. InverterTemp .. "," .. count) end
update(InverterTempDeviceName, InverterTempIDX, InverterTemp, count)
end
if BoosterTempIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(BoosterTempDeviceName, BoosterTempIDX, BoosterTemp, count) " .. BoosterTempDeviceName .. "," .. BoosterTempIDX .. "," .. BoosterTemp .. "," .. count) end
update(BoosterTempDeviceName, BoosterTempIDX, BoosterTemp, count)
end
if DailyEnergyIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(MonthlyEnergyDeviceName, MonthlyEnergyIDX, MonthlyEnergy, count) " .. MonthlyEnergyDeviceName .. "," .. MonthlyEnergyIDX .. "," .. MonthlyEnergy .. "," .. count) end
update(DailyEnergyDeviceName, DailyEnergyIDX, DailyEnergy, count)
end
if MonthlyEnergyIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(MonthlyEnergyDeviceName, MonthlyEnergyIDX, MonthlyEnergy, count) " .. MonthlyEnergyDeviceName .. "," .. MonthlyEnergyIDX .. "," .. MonthlyEnergy .. "," .. count) end
update(MonthlyEnergyDeviceName, MonthlyEnergyIDX, MonthlyEnergy, count)
end
if YearlyEnergyIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(YearlyEnergyDeviceName, YearlyEnergyIDX, YearlyEnergy, count) " .. YearlyEnergyDeviceName .. "," .. YearlyEnergyIDX .. "," .. YearlyEnergy .. "," .. count) end
update(YearlyEnergyDeviceName, YearlyEnergyIDX, YearlyEnergy, count)
end
if TotalEnergyIDX ~=0 then
count= count +1
if Debug=="YES" then print("Lua Aurora: update(YearlyEnergyDeviceName, YearlyEnergyIDX, YearlyEnergy, count) " .. YearlyEnergyDeviceName .. "," .. YearlyEnergyIDX .. "," .. YearlyEnergy .. "," .. count) end
update(TotalEnergyDeviceName, TotalEnergyIDX, TotalEnergy, count)
end
-- if ETodayIDX ~=0 then
-- count= count +1
-- if Debug=="YES" then print("Lua Calculate PacX: update(ETodayDeviceName, ETodayIDX, EToday, count) " .. ETodayDeviceName .. "," .. ETodayIDX .. "," .. EToday .. "," .. count) end
-- update(ETodayDeviceName, ETodayIDX, EToday, count)
-- end
-- if ETotalIDX ~=0 then
--- count= count +1
-- - if Debug=="YES" then print("Lua Calculate PacX: update(ETotalDeviceName, ETotalIDX, ETotal, count) " .. ETotalDeviceName .. "," .. ETotalIDX .. "," .. ETotal .. "," .. count) end
-- update(ETotalDeviceName, ETotalIDX, ETotal, count)
-- end
-- if OperatingTimeIDX ~=0 then
-- count= count +1
-- if Debug=="YES" then print("Lua Calculate PacX: update(OperatingTimeDeviceName, OperatingTimeIDX, OperatingTime, count) " .. OperatingTimeDeviceName .. "," .. OperatingTimeIDX .. "," .. OperatingTime .. "," .. count) end
-- update(OperatingTimeDeviceName, OperatingTimeIDX, OperatingTime, count)
-- end
-- if FeedInTimeIDX ~=0 then
-- count= count +1
-- if Debug=="YES" then print("Lua Calculate PacX: update(FeedInTimeDeviceName, FeedInTimeIDX, FeedInTime, count) " .. FeedInTimeDeviceName .. "," .. FeedInTimeIDX .. "," .. FeedInTime .. "," .. count) end
-- update(FeedInTimeDeviceName, FeedInTimeIDX, FeedInTime, count)
-- end
-- if BT_SignalIDX ~=0 then
-- count= count +1
-- if Debug=="YES" then print("Lua Calculate PacX: update(BT_SignalDeviceName, BT_SignalIDX, BT_Signal, count) " .. BT_SignalDeviceName .. "," .. BT_SignalIDX .. "," .. BT_Signal .. "," .. count) end
-- update(BT_SignalDeviceName, BT_SignalIDX, BT_Signal, count)
-- end
-- if ConditionIDX ~=0 then
-- count= count +1
-- if Debug=="YES" then print("Lua Calculate PacX: update(ConditionDeviceName, ConditionIDX, Condition, count) " .. ConditionDeviceName .. "," .. ConditionIDX .. "," .. Condition .. "," .. count) end
-- update(ConditionDeviceName, ConditionIDX, Condition, count)
-- end
-- if GridRelayIDX ~=0 then
-- count= count +1
-- if Debug=="YES" then print("Lua Calculate PacX: update(GridRelayDeviceName, GridRelayIDX, GridRelay, count) " .. GridRelayDeviceName .. "," .. GridRelayIDX .. "," .. GridRelay .. "," .. count) end
-- update(GridRelayDeviceName, GridRelayIDX, GridRelay, count)
-- end
end
return commandArray |