Rule Error after Upgrade to 3.0

Hello,

after my migration from OH2.5 to OH3.0 two rules arent working anymore and i dont really know, whats the reason.
I already posted this question on another post, which is already closed so i tried it again here:

Error message:

18:06:11.127 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'notifications_luftfeuchtigkeit-1' failed: Conversion = ')' in notifications_luftfeuchtigkeit

Rule:

rule "Luftfeuchtigkeit_Wohnzimmer_zu_hoch"
when
	Item HM_WZ_Heizung_Humidity changed
then
	if ((HM_WZ_Heizung_Humidity.state >= 60 && previousState <  60) && (Notification_High_Humidity.state == ON)) {
		val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot1_Alexander")
    	telegramAction.sendTelegram(1234567890,"Im Wohnzimmer ist die Luftfeuchtigkeit zu hoch ("+HM_WZ_Heizung_Humidity.state+"%).")
	}
end
rule "Luftfeuchtigkeit_Wohnzimmer_wieder_ok"
when
	Item HM_WZ_Heizung_Humidity changed
then
	if ((HM_WZ_Heizung_Humidity.state < 60 && previousState >=  60) && (Notification_High_Humidity.state == ON))  {
		val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot1_Alexander")
    	telegramAction.sendTelegram(1234567890,"Im Wohnzimmer ist die Luftfeuchtigkeit wieder ok ("+HM_WZ_Heizung_Humidity.state+"%).")
	}
end

Thanks a lot,
Alex

What kind of Item is HM_WZ_Heizung_Humidity now?

If it is a Number:Dimensionless, it’s probably already got a unit as part of its state - 33.0 % or suchlike.

You might need to get that as a string in order to put it in another string
HM_WZ_Heizung_Humidity.state.toString
and you may find that you don’t need to add the % character yourself.

Actually it is just a number, but i added the following meta description:

I think maybe you’ll need to escape the % in the last string fragment, \%. I don’t know how the Action is handling the string but it looks like it’s complaining about it.

I am not sure, if i unterstood this right, but when i change the pattern as followed, i get another error:

%.1f %\%

But i also tried again after removing the state description and got the same error in the log.

No, leave the [state presentation] alone, it’s not involved here.

I meant change

telegramAction.sendTelegram(1234567890,"Im Wohnzimmer ist die Luftfeuchtigkeit zu hoch ("+HM_WZ_Heizung_Humidity.state+"%).")

to

telegramAction.sendTelegram(1234567890,"Im Wohnzimmer ist die Luftfeuchtigkeit zu hoch ("+HM_WZ_Heizung_Humidity.state.toString+"\%).")

Thank you, i already thought i am not at the right point.
I changed the part in the rule but now i get an error uploading the new .rules:

21:48:12.401 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'notifications_luftfeuchtigkeit.rules' has errors, therefore ignoring it: [9,136]: Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )
[18,138]: Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

edit: i changed the escape from \ to \ - now i get no error at uploading the file but still the same error at the execution of the rule:

21:51:16.087 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'notifications_luftfeuchtigkeit-2' failed: Conversion = ')' in notifications_luftfeuchtigkeit

Don’t know quite how to escape it then. Just leave the wretched % out!

1 Like

Great! Thats it! Thank you so much!

Looking at the binding docs, the Action example in particular, it looks like sendTelegram() uses the java parameterised formatter on the string you give it - similar to [state presentation].
So to get a % in text, use double %%

 ... HM_WZ_Heizung_Humidity.state.toString+"%%).")

2 Likes

try

%.1f%%

with no space between the f and the first %

... HM_WZ_Heizung_Humidity.state.toString+"%%).")

Perfekt, thank you! With this change the % is shown correctly in the message!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.