Re: Stromverbrauch für Tag, Woche, Monat, Jahr berechnen
Verfasst: 25. Jan 2024 17:05
Beitrag verschoben: viewtopic.php?p=59681#p59681
Code: Alles auswählen
rule "Gasverbrauch Tag Woche Monat Jahr" // Deutscher Zeichensatz zulässig
when
Item heatQuellen_consumption changed // changed reicht.
then
val kwprol = 0.140 // Umrechnung kWh in Liter
val Preis = 1.061 // Preis pro Liter
val ZonedDateTime zdt = ZonedDateTime.now() // jetzt
val ZonedDateTime start_of_day = zdt.with(LocalTime.MIDNIGHT) // heute, Mitternacht
val ZonedDateTime start_of_week = start_of_day.minusDays(start_of_day.getDayOfWeek.getValue - 1) // Montag
val ZonedDateTime start_of_month = start_of_day.withDayOfMonth(3) // Erster Tag des Monats (1)
val ZonedDateTime start_of_year = start_of_day.withDayOfYear(34) // Erster Tag des Jahres (1)
val Gas_Heute = (heatQuellen_consumption.deltaSince(start_of_day) as Number).floatValue // kWh Delta holen
val Gas_Woche = (heatQuellen_consumption.deltaSince(start_of_week) as Number).floatValue
val Gas_Monat = (heatQuellen_consumption.deltaSince(start_of_month) as Number).floatValue
val Gas_Jahr = (heatQuellen_consumption.deltaSince(start_of_year) as Number).floatValue
val Liter_Heute = Gas_Heute * kwprol // kWh in Liter umrechnen
val Liter_Woche = Gas_Woche * kwprol
val Liter_Monat = Gas_Monat * kwprol
val Liter_Jahr = Gas_Jahr * kwprol
val Euro_Heute = String::format("%.2f €",(Liter_Heute * Preis)) // Summe in Euro berechnen
val Euro_Woche = String::format("%.2f €",(Liter_Woche * Preis))
val Euro_Monat = String::format("%.2f €",(Liter_Monat * Preis))
val Euro_Jahr = String::format("%.2f €",(Liter_Jahr * Preis))
GasSumme_Heute.postUpdate(Gas_Heute.toString+" kWh/"+ String::format("%.2f",(Liter_Heute)) +" l/" + Euro_Heute)
GasSumme_Woche.postUpdate(Gas_Woche.toString+" kWh/"+ String::format("%.2f",(Liter_Woche)) +" l/" + Euro_Woche)
GasSumme_Monat.postUpdate(Gas_Monat.toString+" kWh/"+ String::format("%.2f",(Liter_Monat)) +" l/" + Euro_Monat)
GasSumme_Jahr.postUpdate(Gas_Jahr.toString+" kWh/"+ String::format("%.2f",(Liter_Jahr)) +" l/" + Euro_Jahr)
endCode: Alles auswählen
Group Gasverbrauch
String GasSumme_Heute "Gasverbrauch Heute " <energy> (GroupGasverbrauch)
String GasSumme_Woche "Gasverbrauch Woche " < energy> (GroupGasverbrauch)
String GasSumme_Monat "Gasverbrauch Monat " <energy> (GroupGasverbrauch)
String GasSumme_Jahr "Gasverbrauch Jahr " <energy> (GroupGasverbrauch)Code: Alles auswählen
Tried to set invalid state 1157.7 (DecimalType) on item GasSumme_Jahr of type StringItem, ignoring itCode: Alles auswählen
Group Gasverbrauch
String GasSumme_Heute "Gasverbrauch Heute" <energy> (GroupGasverbrauch)
String GasSumme_Woche "Gasverbrauch Woche" <energy> (GroupGasverbrauch)
String GasSumme_Monat "Gasverbrauch Monat" <energy> (GroupGasverbrauch)
String GasSumme_Jahr "Gasverbrauch Jahr" <energy> (GroupGasverbrauch)Code: Alles auswählen
Group Gasverbrauch
String GasSumme_Heute "GasHeute" <energy> (GroupGasverbrauch)
String GasSumme_Woche "GasWoche" <energy> (GroupGasverbrauch)
String GasSumme_Monat "GasMonat" <energy> (GroupGasverbrauch)
String GasSumme_Jahr "GasJahr" <energy> (GroupGasverbrauch)Code: Alles auswählen
Group WaschmaschineKosten
String Waschmaschine_Heute "WaschHeute" <energy> (GroupWaschmaschineKosten)
String Waschmaschine_Woche "WaschWoche" <energy> (GroupWaschmaschineKosten)
String Waschmaschine_Monat "WaschMonat" <energy> (GroupWaschmaschineKosten)
String Waschmaschine_Jahr "WaschJahr" <energy> (GroupWaschmaschineKosten)Code: Alles auswählen
rule "Waschmaschine Tag Woche Monat Jahr" // Deutscher Zeichensatz zulässig
when
Item Waschmaschine_Gesamtverbrauch changed // changed reicht.
then
val Preis = 0.48
val ZonedDateTime zdt = ZonedDateTime.now() // jetzt
val ZonedDateTime start_of_day = zdt.with(LocalTime.MIDNIGHT) // heute, Mitternacht
val ZonedDateTime start_of_week = start_of_day.minusDays(start_of_day.getDayOfWeek.getValue - 1) // Montag
val ZonedDateTime start_of_month = start_of_day.withDayOfMonth(3) // Erster Tag des Monats (1)
val ZonedDateTime start_of_year = start_of_day.withDayOfYear(34) // Erster Tag des Jahres (1)
val WMaschine_Heute = (Waschmaschine_Gesamtverbrauch.deltaSince(start_of_day) as Number).floatValue // kWh Delta holen
val WMaschine_Woche = (Waschmaschine_Gesamtverbrauch.deltaSince(start_of_week) as Number).floatValue
val WMaschine_Monat = (Waschmaschine_Gesamtverbrauch.deltaSince(start_of_month) as Number).floatValue
val WMaschine_Jahr = (Waschmaschine_Gesamtverbrauch.deltaSince(start_of_year) as Number).floatValue
val Euro_Heute = String::format("%.2f €",(WMaschine_Heute * Preis)) // Summe in Euro berechnen
val Euro_Woche = String::format("%.2f €",(WMaschine_Woche * Preis))
val Euro_Monat = String::format("%.2f €",(WMaschine_Monat * Preis))
val Euro_Jahr = String::format("%.2f €",(WMaschine_Jahr * Preis))
Waschmaschine_Heute.postUpdate(WMaschine_Heute.toString + " kWh/" + Euro_Heute)
Waschmaschine_Woche.postUpdate(WMaschine_Woche.toString + " kWh/" + Euro_Woche)
Waschmaschine_Monat.postUpdate(WMaschine_Monat.toString + " kWh/" + Euro_Monat)
Waschmaschine_Jahr.postUpdate(WMaschine_Jahr.toString + " kWh/" + Euro_Jahr)
endCode: Alles auswählen
2024-02-03 23:50:08.722 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Waschmaschine_Kosten-1' failed: cannot invoke method public abstract float java.lang.Number.floatValue() on null in Waschmaschine_KostenCode: Alles auswählen
Group WaschmaschineKosten // Der Name der Gruppe lautet WaschmaschineKosten, nicht GroupWaschmaschineKostenCode: Alles auswählen
2024-02-04 20:43:58.811 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Gasverbrauch-1' failed: cannot invoke method public abstract float java.lang.Number.floatValue() on null in GasverbrauchJetzt wollte ich mal analysieren wo das Problem liegt und mir die Werte ausgeben lassen.Script execution of rule with UID heizung-1' failed: cannot invoke method public abstract float java.lang.Number.floatValue() on null in heizung
Code: Alles auswählen
logInfo("Stromverbrauch","Test 1:", WEZ_Gesamtenergie.persistedState(now.minusDays(1)))
logInfo("Stromverbrauch","Test 2:", WEZ_Gesamtenergie.lastChange("influxdb"))
logInfo("Stromverbrauch","Test 3:", (WEZ_Gesamtenergie.deltaSince(start_of_day) as Number))
Ja, die Syntax ist fehlerhaftTomW80 hat geschrieben: 14. Okt 2025 00:41 Doch ich erhalte hiermit immer keinen Wert. ist da die Syntax falsch?
Code: Alles auswählen
logInfo("Stromverbrauch","Test 1: {}", WEZ_Gesamtenergie.persistedState(now.minusDays(1)))
logInfo("Stromverbrauch","Test 2: {}", WEZ_Gesamtenergie.lastChange("influxdb"))
logInfo("Stromverbrauch","Test 3: {}", WEZ_Gesamtenergie.deltaSince(start_of_day))
Code: Alles auswählen
logInfo("Stromverbrauch","gestern: {} letzte Änderung: {} bisher: {}",
WEZ_Gesamtenergie.persistedState(now.minusDays(1)),
WEZ_Gesamtenergie.lastChange("influxdb"),
WEZ_Gesamtenergie.deltaSince(start_of_day)
)