1 + 1 = 2 ; Have Fun !
Code: Select all
--[[
dzVents script to collect real/time data from SAJ solar power inverter (https://www.saj-electric.com ) and send this to domoticz devices
Information layout
After modifying the relevant section, place the script in domoticz/scripts/dzVents/scripts or use the internal event editor
Create virtual hardware and the following devices
# Name Type Subtype
- Solar Power Today RFXMeter RFXMeter counter
- Frequency (Hz) General Text
- InverterTemperature Temp LaCrosse TX3
- Total generated RFXMeter RFXMeter counter
- PV1 DC Current General Current
- PV1 DC Voltage General Voltage
- Solar Power Usage Electric
response lay-out
Skip to line 101 and change the URL to match your situation, USERID, PASSWORD and IP-ADDRESS
# what value divider Value Quantity
1 System number 1 1
2 Total generated 786798 100 kWh
3 runTime 97063 10 hours
4 Today 39 100 Kwh
5 Today 43 10 hours
6 PV1 DC Voltage 1533 10 Volt
7 PV1 DC Current 20 10 Ampere
8 PV2 DC Voltage 2181 10 Volt
9 PV2 DC Current 19 10 Volt
10 PV3 DC Voltage 65535 N/A
11 PV3 DC Current 65535 N/A
12 Grid connected 123 1 Watt
13 Frequency 5000 100 Hz
14 Line1 voltage 2333 10 Volt
15 Line1 current 64 10 Ampere
16 Line2 voltage 65535 N/A
17 Line2 current 65535 N/A
18 Line3 voltage 65535 N/A
19 Line3 current 65535 N/A
20 Bus voltage 3619 10 Volt
21 Temperature 259 10 Celsius
22 CO2 emission 61762 10 Kg
23 system number 2 1
History:
20200112: Start coding
20200113: Start testing on life situation (thanks to nlfva1)
20200119: First public release
]]--
local scriptVar = 'getSolarInformation'
return
{
on =
{
timer =
{
'every 5 minutes at daytime',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
marker = scriptVar,
},
execute = function(dz, item)
----
-- Enter your setting below this line
----
local idTable = -- modify column devicetype / devicename where applicable
{
-- What, divider, Quantity, deviceType/nil, deviceName
{ "System number", 1, ""},
{ "Total generated", 100, "kWh", "Counter", "Total generated"}, -- define as Counter
{ "runTime", 10, "hours"},
{ "Today", 100, "kWh", "Counter", "Solar Power Today"},
{ "Today", 10, "hours"},
{ "PV1 DC Voltage", 10, "Volt", "Voltage", "PV1 DC Voltage"},
{ "PV1 DC Current", 10, "Ampere", "Ampere", "PV1 DC Current"},
{ "PV2 DC Voltage", 10, "Volt"},
{ "PV2 DC Current", 10, "Volt"},
{ "PV3 DC Voltage", 1, ""},
{ "PV3 DC Current", 1, ""},
{ "Grid connected", 1, "Watt", "Energy", "Solar Power"},
{ "Frequency", 100, "Hz", "Text", "Frequency (Hz)"},
{ "Line1 voltage", 10, "Volt"},
{ "Line1 current", 10, "Ampere"},
{ "Line2 voltage", 1, ""},
{ "Line2 current", 1, ""},
{ "Line3 voltage", 1, ""},
{ "Line3 current", 1, ""},
{ "Bus voltage", 10, "Volt"},
{ "Temperature", 10, "Celsius", "Temperature", "InverterTemperature"},
{ "CO2 emission", 10, "Kg"},
{ "next", 1, ""},
}
local SAJ_IP = '192.168.1.8'
local SAJ_userID = 'admin'
local SAJ_password = 'password'
----
-- No changes required below this line
----
-- testData = '1,786779,97053,69,43,1533,20,2181,19,65535,65535,123,5000,2333,64,65535,65535,65535,65535,3619,259,61762,2'
local function callSolarInverter()
local url = 'http://' .. SAJ_userID ..':' .. SAJ_password .. '@' .. SAJ_IP .. '/status/status.php'
-- url = 'http://admin:[email protected]/status/status.php' -- example URL
dz.openURL({ url = url, callback = scriptVar })
end
local function processValue(value, index)
local notApplicable = 65535
if value == notApplicable then
return 'N/A'
else
return value / idTable[index][2] -- divide by divider
end
end
local function updateDevice(deviceType, name, value)
dz.log(deviceType .. ' : ' .. name .. ' : ' .. value ,dz.LOG_DEBUG)
if deviceType == 'Temperature' then
dz.devices(name).updateTemperature(value)
elseif deviceType == 'Ampere' then
dz.devices(name).updateCurrent(value)
elseif deviceType == 'Voltage' then
dz.devices(name).updateVoltage(value)
elseif deviceType == 'Counter' then
dz.devices(name).updateCounter(value*1000)
elseif deviceType == 'Energy' then
dz.devices(name).updateEnergy(value)
elseif deviceType == 'kWh' then
dz.devices(name).updateElectricity(value,1)
elseif deviceType == 'Text' then
dz.devices(name).updateText(value)
end
end
local function processData(data)
dTable = dz.utils.stringSplit(data,',') -- convert data (string) to table
-- dz.utils.dumpTable(dTable) -- debug
for index, value in ipairs(dTable) do
local value = processValue(math.floor(value), index)
dz.log(idTable[index][1] .. ' : ' .. value .. ' ' .. idTable[index][3] ,dz.LOG_DEBUG)
if idTable[index][4] then
updateDevice(idTable[index][4], idTable[index][5], value )
end
end
end
-- main
if item.isTimer then
callSolarInverter()
else -- triggered by callback
if item.ok then
processData(item.data)
-- processData(testData) -- Test Data
else
dz.log('Problem retrieving data from inverter.. ' .. item.statusText,dz.LOG_ERROR)
end
end
end
}