I need some help of a script wizzard to solve a problem with 2 scripts I have. The first script gets values out of the Solax Cloud and updates some sensors. This one works like a charm, I am very happy with it

========================================================================
-- Script to retrieve real-time data from a Solax solar inverter and update a Domoticz device
Code: Select all
return {
-- Define triggers for the script
on = {
timer = { 'every 2 minutes' },
httpResponses = { 'trigger' }
},
-- Configure logging settings
logging = {
level = domoticz.LOG_INFO,
marker = 'Solax-X3-Hybrid'
},
-- Define the main function of the script
execute = function(domoticz, item)
-- Handle the timer trigger
if item.isTimer then
domoticz.openURL({
url = 'https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=TOKEN&sn=inverter1',
method = 'GET',
callback = 'trigger'
})
end
-- Handle the HTTP response trigger
if item.isHTTPResponse then
-- Check if the response was successful
if item.ok then
-- Check if the response is in JSON format
if item.isJSON then
-- Extract the relevant data from the response
local inverterData = item.json.result
if inverterData == nil then
-- Log a message indicating failure
domoticz.log('Problemas de comunicação')
domoticz.log(item)
else
-- Update the Domoticz device with the retrieved data
local device = domoticz.devices('Solax X3 String1')
device.updateElectricity(inverterData.powerdc1)
local device = domoticz.devices('Solax X3 String2')
device.updateElectricity(inverterData.powerdc2)
local device = domoticz.devices('X3 Powerbank transfer')
device.updateElectricity(inverterData.batPower)
local device = domoticz.devices('Solax Powerbank')
device.updatePercentage(inverterData.soc)
local device = domoticz.devices('House Load')
device.updateElectricity(inverterData.acpower)
local device = domoticz.devices('Grid_Feed')
device.updateElectricity(inverterData.feedinpower)
-- Log a message indicating success
domoticz.log('Data updated successfully', domoticz.LOG_INFO)
end
end
end
end
end
}
Yesterday, I have Installed a second Inverter and of course I need some values from that one too.
Putting the GET in a browser works, however a copy of the script doesn't of course. So I made a copy of the running script from Inverter1,
altered the String and teh values I need, made the sensors in Domoticz. It runs just like the first script, however now the updating of my sensors gets tangled up. So I guess I need to change the output in the second script so it would be available as a parralel to the first (?)
I have played around a little, however as I am no scripting man I guess it would be better to ask anyone what I need to change in the second script.
It looks like this (for now):
-- Script to retrieve real-time data from a Solax solar inverter and update a Domoticz device
Code: Select all
return {
-- Define triggers for the script
on = {
timer = { 'every 3 minutes' },
httpResponses = { 'trigger' }
},
-- Configure logging settings
logging = {
level = domoticz.LOG_INFO,
marker = 'Solax-X1-Hybrid'
},
-- Define the main function of the script
execute = function(domoticz, item)
-- Handle the timer trigger
if item.isTimer then
domoticz.openURL({
url = 'https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=TOKEN&sn=inverter2',
method = 'GET',
callback = 'trigger'
})
end
-- Handle the HTTP response trigger
if item.isHTTPResponse then
-- Check if the response was successful
if item.ok then
-- Check if the response is in JSON format
if item.isJSON then
-- Extract the relevant data from the response
local inverterData = item.json.result
if inverterData == nil then
-- Log a message indicating failure
domoticz.log('Communication Problems')
domoticz.log(item)
else
-- Update the Domoticz device with the retrieved data
local device = domoticz.devices('Solax X1 String')
device.updateElectricity(inverterData.powerdc1)
local device = domoticz.devices('X1 Powerbank transfer')
device.updateElectricity(inverterData.batPower)
local device = domoticz.devices('Solax X1 Powerbank')
device.updatePercentage(inverterData.soc)
local device = domoticz.devices('L1 Load X1_Group')
device.updateElectricity(inverterData.acpower)
-- Log a message indicating success
domoticz.log('Data updated successfully', domoticz.LOG_INFO)
end
end
end
end
end
}
Thx in advance for helping!