OK, so you want to keep track of the heater’s total runtime? Assuming that influxdb is your default persistence service:
In JRuby:
rule "Heater runtime" do
changed main_heater_power, to: OFF
run do
new_duration = Time.now - main_heater_power.previous_state(skip_equal: true).timestamp
HeaterTotalRuntime << ((HeaterTotalRuntime.state || 0) + new_duration.to_f)
end
end
You don’t need to deal with startup / cron. The only gotcha is if you shutdown openhab while main_heater_power is ON, you would lose that duration between ON → OFF, or between oh shutdown → oh startup, because on startup, the item would change from UNDEF to ON, and I think it would persist, thus marking a new start. If this is important, we can try to handle such a case.