The script that I am using
Code: Select all
commandArray = {}
-- API credentials and URL
local username = '[email protected]'
local password = 'myactualpassword'
local site_id = 'myactualsiteID'
local api_url_power = 'https://my.autarco.com/api/m1/site/' .. site_id .. '/power'
-- Function to fetch data from API
function fetch_data(url)
local handle = io.popen("curl -s -u ' .. username .. ':' .. password .. ' ' .. api_url_power ..'")
local result = handle:read("*a")
handle:close()
return result
end
-- Fetch and parse power data
local power_data = fetch_data(api_url_power)
local power_json = json.decode(power_data)
local pv_now = power_json.stats.kpis.pv_now / 1000 -- Convert to kW
-- Update Domoticz virtual sensors
commandArray['UpdateDevice'] = 'myactualidx|0|' .. pv_now
return commandArray
The error message:
Code: Select all
EventSystem: in SpeelScript: [string "commandArray = {} ..."]:20: attempt to index a nil value (global 'json')
The virtual domoticz device is available. It should work.
Furthermore I tested the API manually:
When I simply type in
Code: Select all
my.autarco.com/api/m1/site/myactualsiteID/power
Code: Select all
{
"dt_config_changed": "202x-0x-10T12:41:06+00:00",
"inverters": {
"myactualinverterid01": {
"sn": "myactualserialnumber01",
"dt_latest_msg": "2024-07-06T18:38:59+00:00",
"out_ac_power": 190,
"out_ac_energy_total": 5506,
"error": null,
"grid_turned_off": false,
"health": "OK"
},
"myactualinverterid02": {
"sn": "myactualserialnumber02",
"dt_latest_msg": "2024-07-06T11:22:46+00:00",
"out_ac_power": 940,
"out_ac_energy_total": 3156,
"error": null,
"grid_turned_off": false,
"health": "OK"
}
},
"stats": {
"graphs": {
"pv_power": {
"myactualinverterid01": {
"2024-07-06 00:00:00": 0,
"2024-07-06 01:00:00": 0,
"2024-07-06 02:00:00": 0,
"2024-07-06 03:00:00": 0,
"2024-07-06 04:00:00": 0,
"2024-07-06 05:00:00": 0,
"2024-07-06 06:00:00": 60,
"2024-07-06 07:00:00": 827,
"2024-07-06 08:00:00": 460,
"2024-07-06 09:00:00": 687,
"2024-07-06 10:00:00": 780,
"2024-07-06 11:00:00": 883,
"2024-07-06 12:00:00": 713,
"2024-07-06 13:00:00": 1427,
"2024-07-06 14:00:00": 2320,
"2024-07-06 15:00:00": 2700,
"2024-07-06 16:00:00": 1273,
"2024-07-06 17:00:00": 820,
"2024-07-06 18:00:00": 387,
"2024-07-06 19:00:00": 190,
"2024-07-06 20:00:00": 120,
"2024-07-06 20:30:00": 165
},
"myactualinverterid02": {
"2024-07-06 00:00:00": 0,
"2024-07-06 01:00:00": 0,
"2024-07-06 02:00:00": 0,
"2024-07-06 03:00:00": 0,
"2024-07-06 04:00:00": 0,
"2024-07-06 05:00:00": 0,
"2024-07-06 06:00:00": 25,
"2024-07-06 07:00:00": 167,
"2024-07-06 08:00:00": 245,
"2024-07-06 09:00:00": 390,
"2024-07-06 10:00:00": 470,
"2024-07-06 11:00:00": 520,
"2024-07-06 12:00:00": 460,
"2024-07-06 13:00:00": 823,
"2024-07-06 14:00:00": 0,
"2024-07-06 15:00:00": 0,
"2024-07-06 16:00:00": 0,
"2024-07-06 17:00:00": 0,
"2024-07-06 18:00:00": 0,
"2024-07-06 19:00:00": 0,
"2024-07-06 20:00:00": 0,
"2024-07-06 20:15:00": 0,
"2024-07-06 20:30:00": null
}
},
"no_comms": [
{
"start": "2024-07-06 08:30:00",
"end": "2024-07-06 08:44:59"
},
{
"start": "2024-07-06 13:30:00",
"end": null
}
]
},
"kpis": {
"pv_now": 190
}
}
}
Code: Select all
curl -s -u 'username':'password' https://my.autarco.com/api/m1/site/myactualsiteID/power
Code: Select all
{"dt_config_changed":"202x-05-10T12:41:06+00:00","inverters":{"myactualinverterid01":{"sn":"myactualserialnumber01","dt_latest_msg":"2024-07-06T18:53:59+00:00","out_ac_power":190,"out_ac_energy_total":5506,"error":null,"grid_turned_off":false,"health":"OK"},"myactualinverterid02":{"sn":"myactualserialnumber02","dt_latest_msg":"2024-07-06T11:22:46+00:00","out_ac_power":940,"out_ac_energy_total":3156,"error":null,"grid_turned_off":false,"health":"OK"}},"stats":{"graphs":{"pv_power":{"154812216300018":{"2024-07-06 00:00:00":0,"2024-07-06 00:15:00":0,"2024-07-06 00:30:00":0,"2024-07-06 00:45:00":0,"2024-07-06 01:00:00":0,"2024-07-06 01:15:00":0,"2024-07-06 01:30:00":0,"2024-07-06 01:45:00":0,"2024-07-06 02:00:00":0,"2024-07-06 02:15:00":0,"2024-07-06 02:30:00":0,"2024-07-06 02:45:00":0,"2024-07-06 03:00:00":0,"2024-07-06 03:15:00":0,"2024-07-06 03:30:00":0,"2024-07-06 03:45:00":0,"2024-07-06 04:00:00":0,"2024-07-06 04:15:00":0,"2024-07-06 04:30:00":0,"2024-07-06 04:45:00":0,"2024-07-06 05:00:00":0,"2024-07-06 05:15:00":0,"2024-07-06 05:30:00":0,"2024-07-06 05:45:00":20,"2024-07-06 06:00:00":60,"2024-07-06 06:15:00":113,"2024-07-06 06:30:00":240,"2024-07-06 06:45:00":563,"2024-07-06 07:00:00":827,"2024-07-06 07:15:00":533,"2024-07-06 07:30:00":407,"2024-07-06 07:45:00":347,"2024-07-06 08:00:00":460,"2024-07-06 08:15:00":547,"2024-07-06 08:30:00":603,"2024-07-06 08:45:00":600,"2024-07-06 09:00:00":687,"2024-07-06 09:15:00":647,"2024-07-06 09:30:00":737,"2024-07-06 09:45:00":840,"2024-07-06 10:00:00":780,"2024-07-06 10:15:00":523,"2024-07-06 10:30:00":223,"2024-07-06 10:45:00":523,"2024-07-06 11:00:00":883,"2024-07-06 11:15:00":693,"2024-07-06 11:30:00":513,"2024-07-06 11:45:00":393,"2024-07-06 12:00:00":713,"2024-07-06 12:15:00":763,"2024-07-06 12:30:00":1493,"2024-07-06 12:45:00":1413,"2024-07-06 13:00:00":1427,"2024-07-06 13:15:00":2010,"2024-07-06 13:30:00":1923,"2024-07-06 13:45:00":1493,"2024-07-06 14:00:00":2320,"2024-07-06 14:15:00":2710,"2024-07-06 14:30:00":2513,"2024-07-06 14:45:00":2733,"2024-07-06 15:00:00":2700,"2024-07-06 15:15:00":1513,"2024-07-06 15:30:00":2513,"2024-07-06 15:45:00":1393,"2024-07-06 16:00:00":1273,"2024-07-06 16:15:00":943,"2024-07-06 16:30:00":850,"2024-07-06 16:45:00":817,"2024-07-06 17:00:00":820,"2024-07-06 17:15:00":520,"2024-07-06 17:30:00":747,"2024-07-06 17:45:00":437,"2024-07-06 18:00:00":387,"2024-07-06 18:15:00":417,"2024-07-06 18:30:00":510,"2024-07-06 18:45:00":573,"2024-07-06 19:00:00":190,"2024-07-06 19:15:00":230,"2024-07-06 19:30:00":110,"2024-07-06 19:45:00":110,"2024-07-06 20:00:00":120,"2024-07-06 20:15:00":157,"2024-07-06 20:30:00":167,"2024-07-06 20:45:00":210},"1805030221110035":{"2024-07-06 00:00:00":0,"2024-07-06 00:15:00":0,"2024-07-06 00:30:00":0,"2024-07-06 00:45:00":0,"2024-07-06 01:00:00":0,"2024-07-06 01:15:00":0,"2024-07-06 01:30:00":0,"2024-07-06 01:45:00":0,"2024-07-06 02:00:00":0,"2024-07-06 02:15:00":0,"2024-07-06 02:30:00":0,"2024-07-06 02:45:00":0,"2024-07-06 03:00:00":0,"2024-07-06 03:15:00":0,"2024-07-06 03:30:00":0,"2024-07-06 03:45:00":0,"2024-07-06 04:00:00":0,"2024-07-06 04:15:00":0,"2024-07-06 04:30:00":0,"2024-07-06 04:45:00":0,"2024-07-06 05:00:00":0,"2024-07-06 05:15:00":0,"2024-07-06 05:30:00":0,"2024-07-06 05:45:00":0,"2024-07-06 06:00:00":25,"2024-07-06 06:15:00":30,"2024-07-06 06:30:00":67,"2024-07-06 06:45:00":100,"2024-07-06 07:00:00":167,"2024-07-06 07:15:00":177,"2024-07-06 07:30:00":177,"2024-07-06 07:45:00":170,"2024-07-06 08:00:00":245,"2024-07-06 08:15:00":295,"2024-07-06 08:30:00":0,"2024-07-06 08:45:00":330,"2024-07-06 09:00:00":390,"2024-07-06 09:15:00":390,"2024-07-06 09:30:00":430,"2024-07-06 09:45:00":528,"2024-07-06 10:00:00":470,"2024-07-06 10:15:00":313,"2024-07-06 10:30:00":153,"2024-07-06 10:45:00":267,"2024-07-06 11:00:00":520,"2024-07-06 11:15:00":323,"2024-07-06 11:30:00":410,"2024-07-06 11:45:00":157,"2024-07-06 12:00:00":460,"2024-07-06 12:15:00":410,"2024-07-06 12:30:00":1060,"2024-07-06 12:45:00":1040,"2024-07-06 13:00:00":823,"2024-07-06 13:15:00":1130,"2024-07-06 13:30:00":0,"2024-07-06 13:45:00":0,"2024-07-06 14:00:00":0,"2024-07-06 14:15:00":0,"2024-07-06 14:30:00":0,"2024-07-06 14:45:00":0,"2024-07-06 15:00:00":0,"2024-07-06 15:15:00":0,"2024-07-06 15:30:00":0,"2024-07-06 15:45:00":0,"2024-07-06 16:00:00":0,"2024-07-06 16:15:00":0,"2024-07-06 16:30:00":0,"2024-07-06 16:45:00":0,"2024-07-06 17:00:00":0,"2024-07-06 17:15:00":0,"2024-07-06 17:30:00":0,"2024-07-06 17:45:00":0,"2024-07-06 18:00:00":0,"2024-07-06 18:15:00":0,"2024-07-06 18:30:00":0,"2024-07-06 18:45:00":0,"2024-07-06 19:00:00":0,"2024-07-06 19:15:00":0,"2024-07-06 19:30:00":0,"2024-07-06 19:45:00":0,"2024-07-06 20:00:00":0,"2024-07-06 20:15:00":0,"2024-07-06 20:30:00":0,"2024-07-06 20:45:00":null}},"no_comms":[{"start":"2024-07-06 08:30:00","end":"2024-07-06 08:44:59"},{"start":"2024-07-06 13:30:00","end":null}]},"kpis":{"pv_now":190}}}
Anybody have any ideas?