I am now struggeling with this shit easy rule since hours.
I checked all different forums post but i have no clue.
How can I easily replace (now.withTimeAtStartOfDay) in OH3 rules?
I would like to display my energy consumption per day.
I changed my rules already x times today… so this is my current setup:
rule "Stromzaehler kWh"
when
Item Steckdose_Gefrierschrank received update
then
var_WH = Steckdose_Gefrierschrank.state
var Number Var_kWh = Var_WH /1000
Stromverbrauch_Gefrierschrank_kWh.postUpdate(Var_kWh)
end
rule "Stromzaehler Verbrauch Tag"
when
Time cron "0 0/5 * * * ? *"
then
val ZonedDateTime zdt = ZonedDateTime.now()
var ZonedDateTime start_of_day = zdt.toLocalDate().atStartOfDay(zdt.getZone())
var Strom = Stromverbrauch_Gefrierschrank_kWh.deltaSince(now.with(start_of_day))
postUpdate(Stromverbrauch_Gefrierschrank_heute, Strom)
end
maybe I need another hint.
Rules are working but with strange numbers.
Convert from W in kWh is working fine.
Steckdose_Gefrierschrank’ changed from 28.89 W to 0.0 W
Stromverbrauch_Gefrierschrank_kWh’ changed from 0.02889000 to 0.00000000
but total consumption is showing negative
Stromverbrauch_Gefrierschrank_heute’ changed from -0.00170000 to -0.03059000
rule "Stromzaehler Verbrauch Tag"
when
Item Stromverbrauch_Gefrierschrank_kWh received update
then
Stromverbrauch_Gefrierschrank_heute.postUpdate(Stromverbrauch_Gefrierschrank_kWh.deltaSince(ZonedDateTime.now().with(LocalTime.MIDNIGHT)))
end
It’s negative because of the (fallse) value from Steckdose_Gefrierschrank. When adding -0.00170000 and the negative from the previous value of Steckdose_Gefrierschrank you get -0.03059000.
So what made this odd value of Steckdose_Gefrierschrank? (a reset of the device?)
Which values do you compute and which values are read from a device?