Need help Number conversion/casting

That isn’t quite what I said but it is a good approach.

What I said was to just store the Joda DateTime instead of the millis as a primitive long so you would initialize your global var with null to avoid the apparent problem with now not being available when global vars and vals are first initialized.

There is a difference between java.lang.Number, which is what the Rule’s DSL uses for all numerical values and the results of calculations unless explicitly told otherwise) and NumberItem which is the type of object that a Number defined in .items is.

What I actually suggested is something along the lines of:

var lightOnStart = null

rule "light turned on"
when
    Item MyLight changed to ON
then
    lightOnStart = now
end

rule "light turned off"
when
    Item MyLight changed to OFF
then
    LightRuntime.postUpdate(0)
end

rule "Periodically update LightRuntime"
when
    Time cron "0 * * * * ?"
then
    if(MyLight.state == ON) {
        LightRuntime.postUpdate(now.millis - lightOnStart.millis)
    }
end

No casting. No conversion. There should be no errors. I’m assuming your code fragment is in a rule that runs periodically so you can see your Licht_Carport_Heute update on the sitemap while the light is ON.