@semmy wo kommen denn die Sensordaten an?
Der Sensor misst von oben auf die Öloberfläche?
Der Sensor gibt den Abstand in cm aus?
Dann braucht es noch den Sensorwert in cm bei vollem Tank.
Man trigget auf den Datenpunkt des Sensorwerts
Man rechnet dann von Abstand Sensor zur Öloberfläche auf Füllstandshöhe (Level) um und füttert damit die function getVolume
Das könnte funktionieren, konnte es aber nicht testen. Habe ja andere Datenpunkte. Und es ist meine Tanktabelle drin, mußt durch Deine ersetzen
// Interpolation Tanktabelle // Tabelle Hans Tank 10 000 Liter /* Testscript currently not needed var res = null; { for (let x=-1; x<182; x=x+17.3){ res = getVolume(x); console.log('x: ' + x + ' Volume: ' + res); }; console.log('Test program executed'); }; Testscript currently not needed */ const sensorValueInCmId = 'hierMussDieAdresseDesDatenpunktsRein'; // richtige Adresse eintragen const tankVolumeLiterId = '0_userdata.0.power.tank.tankinhalt'; const abstandSensorZuOeloberflaecheWennVollInCm = 30; // richtigen Wert eintragen const maximaleTankfuellHoehe = 119; // aus Peiltabelle // Datenpunkt für Tankinhalt erzeugen createState(tankVolumeLiterId, undefined , false, { name: tankVolumeLiter, desc: 'total quantity in liter', type: 'number', unit: 'Liter', role: 'value' }); on(sensorValueInCmId, function (dp) { let sensorDistanceValue = dp.state.val; let distanceSensorToSurface = sensorDistanceValue - abstandSensorZuOeloberflaecheWennVollInCm; let fuellHoehe = maximaleTankfuellHoehe - distanceSensorToSurface; let tankInhalt = getVolume(fuellHoehe); setState(tankVolumeLiterId, tankInhalt); }); function getVolume(myLevel){ const tankVolume = [0, 8.409859784, 23, 43.5318943, 65, 93.30470164, 119, 153.9586423, 184, 223.5705811, 257, 300.8977322, 337, 385.04257, 424, 475.3122288, 510, 571.1472806, 615, 672.0811422, 718, 777.7149676, 827, 887.7011452, 939, 1001.731933, 1056, 1119.531332, 1177, 1240.849092, 1301, 1365, 1429, 1494, 1559, 1624, 1691, 1760, 1829, 1898, 1968, 2039, 2110, 2182, 2255, 2328, 2402, 2477, 2552, 2627, 2702, 2778, 2855, 2932, 3010, 3088, 3166, 3244, 3323, 3402, 3482, 3562, 3642, 3722, 3803, 3884, 3965, 4046, 4127, 4209, 4291, 4373, 4455, 4537, 4619, 4701, 4783, 4865, 4947, 5029, 5111, 5193, 5275, 5357, 5439, 5521, 5603, 5685, 5767, 5849, 5931, 6013, 6094, 6175, 6256, 6337, 6418, 6498, 6578, 6658, 6738, 6817, 6896, 6974, 7052, 7130, 7208, 7300, 7362, 7438, 7513, 7588, 7663, 7738, 7812, 7885, 7958, 8030, 8101, 8172, 8242, 8311, 8380, 8449, 8516, 8581, 8646, 8711, 8775, 8839, 8902, 8963, 9024, 9084, 9143, 9201, 9258, 9313, 9368, 9422, 9474, 9525, 9575, 9624, 9671, 9716, 9760, 9803, 9844, 9883, 9921, 9956, 9990, 10021, 10049, 10075, 10098, 10117, 10132, 10140, ]; const minLevel = 0; // min index const maxLevel = tankVolume.length -1; // max index let volume = 0; if(myLevel >= minLevel && myLevel <= (maxLevel +0.5)){ let truncLevel = Math.trunc(myLevel); if(truncLevel == maxLevel) { volume = tankVolume[truncLevel]; // top of table. Interpolation neither necessary nor possible } else { // inertpolation according https://en.wikipedia.org/wiki/Line_(geometry) ; https://de.wikipedia.org/wiki/Zweipunkteform /* y = (x-x1) * (y2-y1)/(x2-x1) +y1 y : volume */ let x = myLevel; let x1 = truncLevel; let x2 = truncLevel + 1; let y1 = tankVolume[x1]; let y2 = tankVolume[x2]; volume = (x-x1) * (y2-y1)/(x2-x1) +y1; }; return volume; } else{ // level out of range console.log('Error, level out of range: ' + myLevel); return null; }; };