[oH3.1] Battery notification not working - Conversion = '

Hi there,

i moved this rule to oH3.1 some time ago but never tested it and it wasn´t fired by an empty battery.
Now it´s running but fails to send me the message because of a conversion error.

val String ruleId = "BatteryCheck"

rule "Batterien prüfen"

when

	Time cron "0 0 18 * * ?"

then

    val telegramAction = getActions("telegram","telegram:telegramBot:bot")
    val long bot1 = 456
    val long bot2 = 123

	val StringBuilder BatterieText = new StringBuilder
	BatterieText.append("Folgende Batterien sind leer:\n")

	var Integer emptyBatteriesS = 0
	var Integer emptyBatteriesP = 0

	emptyBatteriesS = gBatteryState.members.filter[ i | i.state == ON].size
	emptyBatteriesP = gBatteryPercent.members.filter[ i | i.state <= 20].size
	val emptyBatteries = emptyBatteriesS + emptyBatteriesP

	if(emptyBatteries == 1)
	{
		logInfo(ruleId, "Eine Batterie ist leer.", emptyBatteries)
	}

	if(emptyBatteries > 1)
	{
		logInfo(ruleId, "{} Batterien sind leer.", emptyBatteries)
	}

	if(emptyBatteries != 0)
	{
		gBatteryState.members.filter[ i | i.state == ON].forEach[ i | BatterieText.append(i.state+" - ")]
		gBatteryState.members.filter[ i | i.state == ON].forEach[ i | BatterieText.append(i.label+"\n")]
		gBatteryPercent.members.filter[ i | i.state <= 20].forEach[ i | BatterieText.append(i.label+" - ")]
		gBatteryPercent.members.filter[ i | i.state <= 20].forEach[ i | BatterieText.append(i.state+"%\n")]
		Thread::sleep(100)
		logInfo(ruleId, BatterieText.toString)
		telegramAction.sendTelegram(bot1, BatterieText.toString)
		telegramAction.sendTelegram(bot2, BatterieText.toString)
	}

end

The rule is working until it should send the telegram message.
The line before will be executed: logInfo(ruleId, BatterieText.toString)

2021-09-06 19:37:13.512 [INFO ] [enhab.core.model.script.BatteryCheck] - Eine Batterie ist leer.
2021-09-06 19:37:13.653 [INFO ] [enhab.core.model.script.BatteryCheck] - Folgende Batterien sind leer:
Sensor Flur - 18%
2021-09-06 19:37:13.659 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'batteryCheck-1' failed: Conversion = '
' in batteryCheck

I can´t find a place where the ' is coming from.
It´s not in the name or the state of any group member.

Any ideas?


  • Platform information:
    • Hardware: Raspberry Pi 4 Model B Rev 1.1
    • OS: Raspbian GNU/Linux 10 (buster)
    • Java Runtime Environment:
      • openjdk version “11.0.12” 2021-07-20 LTS
      • OpenJDK Runtime Environment Zulu11.50+19-CA (build 11.0.12+7-LTS)
      • OpenJDK Client VM Zulu11.50+19-CA (build 11.0.12+7-LTS, mixed mode)
    • openHAB version: 3.1.0 (Build)

Ok it seems like the Telegram binding doens´t like the % anymore.
I changed the % in gBatteryPercent.members.filter[ i | i.state <= 20].forEach[ i | BatterieText.append(i.state+"%\n")] to %% and now it´s working.
Atleast for Telegram…
The log now shows the double percent while Telegram only shows one.

I know it´s just something optical problem without any technical consequences.
Does someone know a fix to get a single percent in the log and the Telegram message?

The system logs are supposed to tell the unvarnished truth.
If you want your own logInfo to log something different, you can of course give it something different to show I.e. process and assemble some other message.

1 Like