Last active
July 8, 2024 08:53
-
-
Save WietseWind/51ee698dbcff135a8af66aee5755ec51 to your computer and use it in GitHub Desktop.
PRTG formatted JSON endpoint for "HTTP Data Advanced" sensor straight from Shelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shelly: Scripts - create prtg.js with contents below - Start - Scripts main page: "Run on start" | |
// Call with (assuming the first script): http://{shellyip}/script/1/prtg | |
// PRTG: Import HTTP Data Advanced sensor. | |
HTTPServer.registerEndpoint('prtg', function (request, response) { | |
response.headers = [ | |
['content-type', 'application/json'] | |
] | |
const em = Shelly.getComponentStatus('em', 0) | |
const emdata = Shelly.getComponentStatus('emdata', 0) | |
response.body = JSON.stringify({ | |
prtg: { | |
result: [ | |
{ | |
Channel: "Total Consumption", | |
Value: Math.round(emdata.total_act * 1000) / 1000 / 1000, | |
CustomUnit: "kWh", | |
Float: 1, | |
DecimalMode: 3 | |
}, | |
{ | |
Channel: "Current", | |
Value: em.total_current, | |
CustomUnit: "A", | |
Float: 1, | |
DecimalMode: 3, | |
LimitMode: 1, | |
LimitMaxError: 20, | |
LimitMaxWarning: 10, | |
LimitMinWarning: 0.5, | |
LimitMinError: 0.1, | |
}, | |
{ | |
Channel: "Actual Power", | |
Value: em.total_act_power, | |
CustomUnit: "VA", | |
Float: 1, | |
DecimalMode: 3, | |
LimitMode: 1, | |
LimitMaxError: 10000, | |
LimitMaxWarning: 8000, | |
LimitMinWarning: 50, | |
LimitMinError: 10, | |
}, | |
{ | |
Channel: "Apparent Power", | |
Value: em.total_aprt_power, | |
CustomUnit: "W", | |
Float: 1, | |
DecimalMode: 3, | |
LimitMode: 1, | |
LimitMaxError: 10000, | |
LimitMaxWarning: 8000, | |
LimitMinWarning: 50, | |
LimitMinError: 10, | |
}, | |
{ | |
Channel: "Power Factor %", | |
Value: Math.round(em.total_act_power / em.total_aprt_power * 100) / 100, | |
CustomUnit: "λ", | |
LimitMode: 1, | |
DecimalMode: 2, | |
LimitMinWarning: 0.6, | |
LimitMinError: 0.5, | |
} | |
] | |
} | |
}) | |
response.code = 200 | |
response.send() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment