[SOLVED] Persistence and triggeringItem

I’ve been trying to have a rule return the Min and Max of a item for the last 48 hours. I can’t get it to work right, and wondered if someone could help, or if it is even possible to do this.

With creative logging (not shown below), I’ve figure out that the error is when trying to retrieve the min or max values.

rule "Adaptive Lighting Min Max Calculations"
when
Member of LightSensorRaw changed
then
triggeringItem.name+"_Min".postUpdate(triggeringItem.minimumSince(now.minusHours(48)).state)
triggeringItem.name+"_Max".postUpdate(triggeringItem.maximumSince(now.minusHours(48)).state)
    logInfo("Adaptive Lighting", "Calculated Min Max Light Values")
end

Openhasbian 2.4, on RaspberryPi3 B+. using JDBC Persistence - Maria DB. A similar rule successfully retrieves min and max when using the direct item names.

2019-01-29 23:51:29.047 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'AdaptiveLighting Min Max Calculations': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(java.lang.String,java.lang.String) on instance: null

Any ideas on how to have one rule get Min, Max, and maybe even averages while using triggeringItem?

See:

import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule "Adaptive Lighting Min Max Calculations"
when
    Member of LightSensorRaw changed
then
    val minItem = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name .toString + "_Min")
    val maxItem = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name .toString + "_Max")

    minItem.postUpdate(triggeringItem.minimumSince(now.minusHours(48)).state)
    maxItem.postUpdate(triggeringItem.maximumSince(now.minusHours(48)).state)
    logInfo("Adaptive Lighting", "Calculated Min Max Light Values")
end

Thank you so much. I spent hours trying to find a solution. I never found your other post, probably because I wasn’t searching correctly. :grinning: