@kdtcat ```
var parm1, parm2, result, BatteryLevel, PowerConsumptionTotal, PowerProductionTotal, EnergyProductionTotalDay, EnergyConsumptionTotalDay, EnergyExternalTotalOutDay, EnergyBatteryChargeDay, EnergyStorageTotalOutDay, StromverbrauchAnteilSolarTag, STromverbrauchAlleTag;
// Beschreibe diese Funktion …
async function iq(parm1, parm2) {
// Beschreibe diese Funktion
var ergebnis, fparm, fparm2;
fparm = 'from(bucket: "solar") |> range(start: -1m) |> filter(fn: (r) => r["_field"] == ' + parm1 + ') |> aggregateWindow(every: 2m, fn: mean)';
fparm2 = '0_userdata.0.Enpal.' + parm2;
sendTo('influxdb.0', 'query', fparm, async (result) => {
test0 = (await jsonataExpression(result,'*[0]._value '));
setStateDelayed(fparm2, test0, true, parseInt(((0) || '').toString(), 10), false);
});
return ergebnis;
}
schedule("*/2 * * * *", async () => {
result = await iq('"Energy.Battery.Charge.Level"', 'BatteryLevel');
await wait(3000);
BatteryLevel = Math.round(getState('0_userdata.0.Enpal.BatteryLevel').val * 100) / 100;
setStateDelayed('0_userdata.0.Enpal.BatteryLevel', { val: BatteryLevel, ack: false }, parseInt(((0) || '').toString(), 10), false);
result = await iq('"Power.Consumption.Total"', 'PowerConsumptionTotal');
await wait(3000);
PowerConsumptionTotal = getState('0_userdata.0.Enpal.PowerConsumptionTotal').val;
result = await iq('"Power.Production.Total"', 'PowerProductionTotal');
await wait(3000);
PowerProductionTotal = getState('0_userdata.0.Enpal.PowerProductionTotal').val;
result = await iq('"Energy.Production.Total.Day"', 'EnergyProductionTotalDay');
await wait(3000);
EnergyProductionTotalDay = getState('0_userdata.0.Enpal.EnergyProductionTotalDay').val;
result = await iq('"Energy.Consumption.Total.Day"', 'EnergyConsumptionTotalDay');
await wait(3000);
EnergyConsumptionTotalDay = getState('0_userdata.0.Enpal.EnergyConsumptionTotalDay').val;
result = await iq('"Energy.External.Total.Out.Day"', 'EnergyExternalTotalOutDay');
await wait(3000);
EnergyExternalTotalOutDay = getState('0_userdata.0.Enpal.EnergyExternalTotalOutDay').val;
result = await iq('"Energy.Battery.Charge.Day"', 'EnergyBatteryChargeDay');
await wait(3000);
EnergyBatteryChargeDay = getState('0_userdata.0.Enpal.EnergyBatteryChargeDay').val;
result = await iq('"Energy.Storage.Total.Out.Day"', 'EnergyStorageTotalOutDay');
await wait(3000);
EnergyStorageTotalOutDay = getState('0_userdata.0.Enpal.EnergyStorageTotalOutDay').val;
StromverbrauchAnteilSolarTag = EnergyProductionTotalDay - EnergyExternalTotalOutDay;
StromverbrauchAnteilSolarTag = StromverbrauchAnteilSolarTag - EnergyBatteryChargeDay;
setStateDelayed('0_userdata.0.Enpal.StromverbrauchAnteilSolarTag', { val: StromverbrauchAnteilSolarTag, ack: false }, parseInt(((0) || '').toString(), 10), false);
STromverbrauchAlleTag = StromverbrauchAnteilSolarTag + EnergyStorageTotalOutDay + EnergyConsumptionTotalDay;
setStateDelayed('0_userdata.0.Enpal.StromverbrauchAlleTag', { val: STromverbrauchAlleTag, ack: false }, parseInt(((0) || '').toString(), 10), false);
console.info((['1: ',BatteryLevel,', 2: ',PowerConsumptionTotal,', 3: ',PowerProductionTotal,', 4: ',EnergyProductionTotalDay,', 5: ',EnergyConsumptionTotalDay,', 6: ',EnergyExternalTotalOutDay,', 7: ',EnergyBatteryChargeDay,', 8: ',EnergyStorageTotalOutDay,', 9: ',StromverbrauchAnteilSolarTag,', 10: ',STromverbrauchAlleTag].join('')));
});