[SOLVED] Use variable (item.name) with sumSince

Hey,

I´m trying to get the sum of my persisted item-states (influxdb) with a rule.

Everything works fine when I use the item-name itself, but if I try to make this rule more generic, sumSince can´t handle the item.name stored in a variable:

*.items (for each room)

Switch	WhnZ_BewegungSensor_Switch		 "Bewegung [MAP(motion.map):%s]"             (gPresence)           { channel="hue:0107:huebridge:presence_whnz:presence" }
Number  WhnZ_BewegungSensor_Occupancy    "Wohnzimmer [%s]"                           (gPresence_Timeline)  { expire="2m,command=0" }
Number  WhnZ_BewegungSensor_TimeCounter  "Anwesenheit / heute [JS(duration.js):%s]"  (gPresence_Counter)

.
*.rules

rule "Motion sensor triggered"
when
    Member of gPresence received update ON
then
    // Building item-strings
    val occupancy = triggeringItem.name.split("_").get(0).toString + "_" + triggeringItem.name.split("_").get(1).toString + "_Occupancy"
    val timeCounter = triggeringItem.name.split("_").get(0).toString + "_" + triggeringItem.name.split("_").get(1).toString + "_TimeCounter"

    gPresence_Timeline.members.filter[ a | a.name == occupancy.toString].forEach[ a | 
        sendCommand(a.name, "1")
        val Number onToday = a.name.sumSince(now.withTimeAtStartOfDay, "influxdb")
        sendCommand(timeCounter, onToday)
    ]
end

.
error

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Motion sensor triggered': 'sumSince' is not a member of 'java.lang.String'; line 26, column 30, length 53

I would apreciate any hints to solve my problem.

Thank you!

The error message is fairly clear, as rules go. a.name is a string “myItemName” and so doesn’t have a sumSince method.

If a is the Item you extracted from the group, it’s a you want to work with, as in a.sumSince?

1 Like

Thanks for your quick answer - I feel a bit embarrassed now. I was thinking way to complicated…

Oh,it happens, getting bogged down searching for stuff by name :slight_smile: