[SOLVED] Homematic Battery check - What's wrong?

rule "Batterie leer"
  when
    Item gBattery changed to ON
  then
    val lastitem = gBattery.members.filter[i | i.lastUpdate !== null].sortBy[lastUpdate].last
      sendTelegram("main",lastitem.label+": Bitte Batterie wechseln !")
end

with

Group:Switch:OR(ON, OFF) gBattery

comes to the following error message, Why?

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Batterie leer': java.lang.Double cannot be cast to java.lang.String

Add some logInfo to find out what line the rule breaks

rule "Batterie leer"
when
    Item gBattery changed to ON
then
    logInfo("RULE","BREAK 1")
    val lastitem = gBattery.members.filter[i | i.lastUpdate !== null].sortBy[lastUpdate].last
    logInfo("RULE","BREAK 2")
    sendTelegram("main",lastitem.label+": Bitte Batterie wechseln !")
end

I’m using this somewhere in my rules:

val lastItem = Windows.members.filter[ w | w.lastUpdate !== null ].sortBy[ lastUpdate ].last
val String nameOfItem = lastItem.name

The only difference I can see are the spaces after [ and before ] and lastItem.name instead of .label. But not sure as I don’t know the Telegram-Command itself. Hope this helps :slight_smile:

I changed both and now I am again with another fault I thought I solved already:

2018-10-06 10:31:26.819 [INFO ] [.eclipse.smarthome.model.script.RULE] - BREAK 1
2018-10-06 10:31:27.201 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Batterie leer': null

Thought with putting the values “everyminute” into persistence should result in no "null"s. At least I have to have more time to check this. Meanwhile any hints are welcome …

Your solution is much too complex. Have a look here:

rule "Batterie leer"
when
    Member of gBattery changed to ON
then
    sendTelegram("main",triggeringItem.label+": Bitte Batterie wechseln !")
end
3 Likes

Looks like a quite easier solution and it seems to work :smiley:
Knowing that syntax will most likely also help me in other rules.

Thanks !