// // YouLess LS120 Parser // Tested with YouLess LS120 firmware 1.4.1-EL // Tested with Loxone firmware v10 // // By: Richard Verkaik // // Version 20180920 // // AQ1 returns total energy comsumption (kWh) as the sum of both tariff meters p1 and p2 // AQ2 returns total energy production (kWh) as the sum of both tariff meters n1 and n2 // AQ3 returns actual power use (kWh) // AQ4 returns total gas consumption (M3) as displayed on the gas meter (if present) // enum OutputPorts { EnergyConsumption, // AQ1 EnergyProduction, // AQ2 ActualPowerUse, // AQ3 GasConsumption // AQ4 }; float GetValue(char *name, float def) { float value = def; int pos = strfind(result, name, 0); if(pos > 0) { 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}] // while(TRUE) { char *host = "192.168.101.20"; char *page = "/e?f=j"; char *result = httpget(host, page); // printf ("Result: %s", result); if(result != 0) { float p1 = GetValue("\"p1\":", 0); float p2 = GetValue("\"p2\":", 0); setoutput(EnergyConsumption, p1+p2); float n1 = GetValue("\"n1\":", 0); float n2 = GetValue("\"n2\":", 0); setoutput(EnergyProduction, n1+n2); float pwr = GetValue("\"pwr\":", 0); setoutput(ActualPowerUse, pwr / 1000); float gas = GetValue("\"gas\":", 0); setoutput(GasConsumption, gas); free(result); } // Sleep int sleepTime = 10; sleeps(sleepTime); }