Energy consumption rule - shifted range

Hey, I have energy meter and I’m reading its values by MQTT.
I’m using rule to count energy consumption for this day, this month and this year.
my rule looks like this:

rule "zuzycie"
when
Item pompa_zuzycie changed
then
var Number pompa_dzis1
var Number pompa_miesiac1
var Number pompa_rok1

if (pompa_zuzycie.historicState(now.withHour(0).withMinute(0).withSecond(0).withDayOfMonth(1).withDayOfYear(1)) === null) { pompa_rok1 = 0 } else {
pompa_rok1 = pompa_zuzycie.historicState(now.withHour(0).withMinute(0).withSecond(0).withDayOfYear(1)).state as Number }
if (pompa_zuzycie.historicState(now.withHour(0).withMinute(0).withSecond(0).withDayOfMonth(1)) === null) { pompa_miesiac1 = 0 } else { 
pompa_miesiac1 = pompa_zuzycie.historicState(now.withHour(0).withMinute(0).withSecond(0).withDayOfMonth(1)).state as Number }
if (pompa_zuzycie.historicState(now.withHour(0).withMinute(0).withSecond(0)) === null) { pompa_dzis1 = 0 } else { 
pompa_dzis1 = pompa_zuzycie.historicState(now.withHour(0).withMinute(0).withSecond(0)).state as Number }

var pompa_obecnie = pompa_zuzycie.state as Number
val pompa_dzis3 = pompa_obecnie - pompa_dzis1
val pompa_miesiac3 = pompa_obecnie - pompa_miesiac1
val pompa_rok3 = pompa_obecnie - pompa_rok1

postUpdate(pompa_dzis, pompa_dzis3)
postUpdate(pompa_miesiac, pompa_miesiac3)
postUpdate(pompa_rok, pompa_rok3)

end

Item “pompa_zuzycie” still rises as normal energy meter value.
And then it checks value of it from start of day, month and year and subtracts it from actual value.

BUT - look on values saved in influx:

On 0:00:00 it should be “0” but it always gets “0” past 0:10:00…
How to prevent it?