// // YouLess LS120 Parser // Tested with YouLess LS120 firmware 1.4.2-EL.DEbg // Tested with Loxone firmware v10 // // By: Richard Verkaik // // Version 20190818 (Modified by Mike Stamm) // Useful if only led input and S0 input is used, with S0 JSON output at end of string. // Richardīs version looks for a "," at the end of a value, while if S0 is the last value available, there is no comma after the value. // so looking up S0 in my configuration will crash the miniserver! // AQ1 returns actual power use (kW) // AQ2 returns total gas used (M3) S0 output // enum OutputPorts { PowerRate, // AQ1 PowerMeter, // AQ2 GasRate, // AQ3 GasMeter // AQ4 }; // float pwr = GetValue("\"pwr\":", 0); float GetValue(char *name, float def) { float value = def; int pos = strfind(result, name, 0); if(pos > 0) { if(strfind(result, ",", pos) < 0) { int posend = strfind(result, "}", pos); } else { int posend = strfind(result, ",", pos); } int lenName = strlen(name); int lenValue = posend - (pos + lenName); char *svalue = calloc(1, lenValue); // printf ("Name %s found. Pos = %d. Length = %d", name, pos, lenValue); strncpy(svalue, result + pos + lenName, lenValue); value = atof((char *)svalue+1); // printf ("sValue = %s | Value = %f", svalue, value); free(svalue); svalue = 0; } // printf ("%s = %f", name, value); return value; } // // Main loop // JSON expected: [{"tm":1537431308,"net": 33873.178,"pwr": 336,"ts0":1537365600,"cs0": 0.000,"ps0": 0,"p1": 18736.471,"p2": 15136.707,"n1": 0.000,"n2": 0.000,"gas": 11207.046,"gts":1809201000}] // JSON with only LED electrical power input and S0 input [{"tm":1566393127,"net": 78678.481,"pwr": 363,"ts0":1566393117,"cs0": 16200.848,"ps0": 433}] // ps0 is in gas litres/hr, while cs0 is in m3 while(TRUE) { char *host = "192.168.1.8"; char *page = "/e?f=j"; char *result = httpget(host, page); // printf ("Result: %s", result); if(result != 0) { float elP = GetValue("\"pwr\":", 0); setoutput(PowerRate, elP / 1000); float elE = GetValue("\"net\":", 0); setoutput(PowerMeter, elE / 1000); float gasP = GetValue("\"ps0\":", 0); setoutput(GasRate, gasP / 1000); float gasE = GetValue("\"cs0\":", 0); setoutput(GasMeter, gasE); free(result); } // Sleep int sleepTime = 10; sleeps(sleepTime); }