-- Script to retrieve real-time data from a Solax solar inverter and update a Domoticz device
return {
-- Define triggers for the script
on = {
timer = { 'every 2 minutes' },
httpResponses = { 'trigger' }
},
-- Configure logging settings
logging = {
level = domoticz.LOG_INFO,
marker = 'solar-inverter'
},
-- 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/pro ... xdfgdstgzg',
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('Uso Baterias')
device.updateEnergy(inverterData.batPower)
local device = domoticz.devices('Carga baterias')
device.updateText(inverterData.soc.." %")
local device = domoticz.devices('Consumo Casa')
device.updateElectricity(inverterData.acpower)
-- Log a message indicating success
domoticz.log('Data updated successfully', domoticz.LOG_INFO)
end
end
end
end
end
}