finally back to trying to get my heater rules to work. struggling to get this rule to work. it is a null issue but not seeming to find the problem child.
i am on 3.4.2.
I get the following error when i run this rule:
Script execution of rule with UID 'heater_new-1' failed: An error occurred during the script execution: null in heater_new```
i ran a rule at startup to update HeaterTotalRuntime to 0. It runs just fine:
```yaml
Item 'HeaterTotalRuntime' changed from NULL to 0 s
I have it persisted as well.
Here is the code:
rule "Heater Runtime"
when
System started or
Item main_heater_power changed to ON or
Time cron "0 0 0 * * ?" // At midnight every day
then
val DateTime now = new DateTime()
val lastRun = (MainHeater_timestamp.state as DateTimeType)?.zonedDateTime.toEpochSecond()
val runtimeToday = if (lastRun == null) 0 else now.withTimeAtStartOfDay().toEpochSecond() - lastRun
val totalRuntime = (HeaterTotalRuntime.state as NumberState)?.doubleValue() ?: 0
val newTotalRuntime = totalRuntime + runtimeToday
HeaterTotalRuntime.postUpdate(newTotalRuntime)
MainHeater_timestamp.postUpdate(now.toString)
logInfo("Heater Runtime", "HeaterTotalRuntime: {}", HeaterTotalRuntime.state)
end```
thanks for any help!