Garbage rule

Hello,

I’ve a rule for my garbage. But I get an error. But I couldn’t figure out what is caussing the error.
Can someone look at my rule?

rule "Tage bis Abfall berechnen"
when 
	Time cron "0 5 * 1/1 * ? *" or
	Item Restmuell changed or
	Item Biomuell changed or
	Item Papiermuell changed or
	Item DelayedStartup changed from OFF to ON
then
	logInfo("all.rules", "Tage bis Abfall berechnen")
	//Restmuell
	val DateTime varRestmuellDatum = new DateTime((Restmuell.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).withTimeAtStartOfDay
	val Long varRestmuellDiff = Math::round((varRestmuellDatum.millis - now.withTimeAtStartOfDay.millis) / (86400000.0))
	if ( varRestmuellDiff == 0 ) {
		RestmuellTage.postUpdate("heute")
	} else if ( varRestmuellDiff == 1 ) {
		RestmuellTage.postUpdate("morgen")
	} else {
		RestmuellTage.postUpdate(String::format("(%1$d T.)", varRestmuellDiff))
	}
	//Biomuell
	val DateTime varBiomuellDatum = new DateTime((Biomuell.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).withTimeAtStartOfDay
	val Long varBiomuellDiff = Math::round((varBiomuellDatum.millis - now.withTimeAtStartOfDay.millis) / (86400000.0))
	if ( varBiomuellDiff == 0 ) {
		BiomuellTage.postUpdate("heute")
	} else if ( varBiomuellDiff == 1 ) {
		BiomuellTage.postUpdate("morgen")
	} else {
		BiomuellTage.postUpdate(String::format("(%1$d T.)", varBiomuellDiff))
	}
	//Papiermuell
	val DateTime varPapiermuellDatum = new DateTime((Papiermuell.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).withTimeAtStartOfDay
	val Long varPapiermuellDiff = Math::round((varPapiermuellDatum.millis - now.withTimeAtStartOfDay.millis) / (86400000.0))
	if ( varPapiermuellDiff == 0 ) {
		PapiermuellTage.postUpdate("heute")
	} else if ( varPapiermuellDiff == 1 ) {
		PapiermuellTage.postUpdate("morgen")
	} else {
		PapiermuellTage.postUpdate(String::format("(%1$d T.)", varPapiermuellDiff))
	}
end

rule "Abfalltermine sortieren"
when
	Item Restmuell received update or
	Item Biomuell received update or
	Item Papiermuell received update or
	Item RaWeg received update or
	Item RestmuellTage changed or
	Item PapiermuellTage changed or
	Item BiomuellTage changed or
	Item RaWegTage changed or
	//Time cron "0 8 0 1/1 * ? *" or
	Item DelayedStartup changed from OFF to ON
then
	Thread::sleep(3000)
	var DateTime varTempDatum
	var DateTime varAbfall1Datum = new DateTime((Restmuell.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
	var DateTime varAbfall2Datum = new DateTime((Biomuell.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
	var DateTime varAbfall3Datum = new DateTime((Papiermuell.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
	var String varTempArt
	var String varAbfall1Art = "Restmuell"
	var String varAbfall2Art = "Biomuell"
	var String varAbfall3Art = "Papiermuell"
	var String varTempTage
	var String varAbfall1Tage = RestmuellTage.state.toString
	var String varAbfall2Tage = BiomuellTage.state.toString
	var String varAbfall3Tage = PapiermuellTage.state.toString
	logInfo("Afval.rules", "varAbfall1Datum: " +varAbfall1Datum)
	logInfo("Afval.rules", "varAbfall1Tage: " +varAbfall1Tage)
	logInfo("Afval.rules", "varAbfall2Datum: " +varAbfall2Datum)
	logInfo("Afval.rules", "varAbfall2Tage: " +varAbfall2Tage)
	logInfo("Afval.rules", "varAbfall3Datum: " +varAbfall3Datum)
	logInfo("Afval.rules", "varAbfall3Tage: " +varAbfall3Tage)
	var i = 1
	while ((i=i+1) < 6) {
		if (varAbfall1Datum > varAbfall2Datum) {
			varTempDatum = varAbfall1Datum
			varAbfall1Datum = varAbfall2Datum
			varAbfall2Datum = varTempDatum
			varTempArt = varAbfall1Art
			varAbfall1Art = varAbfall2Art
			varAbfall2Art = varTempArt
			varTempTage = varAbfall1Tage
			varAbfall1Tage = varAbfall2Tage
			varAbfall2Tage = varTempTage
			if (varAbfall2Datum > varAbfall3Datum) {
				varTempDatum = varAbfall2Datum
				varAbfall2Datum = varAbfall3Datum
				varAbfall3Datum = varTempDatum
				varTempArt = varAbfall2Art
				varAbfall2Art = varAbfall3Art
				varAbfall3Art = varTempArt
				varTempTage = varAbfall2Tage
				varAbfall2Tage = varAbfall3Tage
				varAbfall3Tage = varTempTage
				}
		}
		if (varAbfall2Datum > varAbfall3Datum) {
				varTempDatum = varAbfall2Datum
				varAbfall2Datum = varAbfall3Datum
				varAbfall3Datum = varTempDatum
				varTempArt = varAbfall2Art
				varAbfall2Art = varAbfall3Art
				varAbfall3Art = varTempArt
				varTempTage = varAbfall2Tage
				varAbfall2Tage = varAbfall3Tage
				varAbfall3Tage = varTempTage
				}
		}
	Abfall_1_Datum.postUpdate(varAbfall1Datum.toString)
	Abfall_2_Datum.postUpdate(varAbfall2Datum.toString)
	Abfall_3_Datum.postUpdate(varAbfall3Datum.toString)
	Abfall_1_Art.postUpdate(varAbfall1Art)
	Abfall_2_Art.postUpdate(varAbfall2Art)
	Abfall_3_Art.postUpdate(varAbfall3Art)
	Abfall_1_Tage.postUpdate(varAbfall1Tage)
	Abfall_2_Tage.postUpdate(varAbfall2Tage)
	Abfall_3_Tage.postUpdate(varAbfall3Tage)
end

rule "Abfall steht an - Blinkeding"
when
	Time cron "0 0 17 1/1 * ? *"
then
	if (Abfall_1_Tage.state.toString == "morgen") {
	Abfall_Steht_An.postUpdate(ON)
	}
end

rule "Abfall steht an - Informiere Jochen"
when
	Time cron "0 30 20 1/1 * ? *"
then
	if (Abfall_Steht_An.state == ON ) {
	sendTelegram("Jeroen", "%s moet je nog buiten zetten", Abfall_1_Art.state.toString)
	}
end

rule "Abfall steht an - Informiere -Frau- und Jochen"
when
	Time cron "0 30 21 1/1 * ? *"
then
	if (Abfall_Steht_An.state == ON) {
	sendTelegram("Jeroen ", "Oh je, %s staat nog steeds niet aan straat!", Abfall_1_Art.state.toString)
	sendTelegram("Jeroen", "%s staat nog niet aan straat, schiet nou eens op", Abfall_1_Art.state.toString)
	}
end

this is my log:

2018-09-08 00:44:52.817 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum: 2018-09-12T00:00:00.000+02:00

2018-09-08 00:44:52.818 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum: 2018-09-12T00:00:00.000+02:00

2018-09-08 00:44:52.817 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum: 2018-09-12T00:00:00.000+02:00

2018-09-08 00:44:52.825 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage: (4 T.)

2018-09-08 00:44:52.826 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage: (4 T.)

2018-09-08 00:44:52.831 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum: 2018-09-19T00:00:00.000+02:00

2018-09-08 00:44:52.836 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum: 2018-09-19T00:00:00.000+02:00

2018-09-08 00:44:52.836 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage: (4 T.)

2018-09-08 00:44:52.837 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage: (11 T.)

2018-09-08 00:44:52.844 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum: 2018-09-19T00:00:00.000+02:00

2018-09-08 00:44:52.844 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum: 2018-09-26T00:00:00.000+02:00

2018-09-08 00:44:52.844 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage: (11 T.)

2018-09-08 00:44:52.850 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage: (11 T.)

2018-09-08 00:44:52.850 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum: 2018-09-26T00:00:00.000+02:00

2018-09-08 00:44:52.857 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum: 2018-09-26T00:00:00.000+02:00

2018-09-08 00:44:52.857 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage: (18 T.)

2018-09-08 00:44:52.864 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage: (18 T.)

2018-09-08 00:44:52.866 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage: (18 T.)

2018-09-08 00:44:52.910 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Abfalltermine sortieren': An error occurred during the script execution: null

I note there are at least three copies of your “Abfalltermine sortieren” rule running at the same time (multiple logInfo messages).
I can’t see an obvious reason that would break it, but it doesn’t seem like that was what you intended?

With a role as long and complicated as this first narrow it down to a specific line in the rule adds log statements until you can figure out which one it is.

This error almost always is caused when trying to convert from one type to another and the two types are not compatible, like trying to assign a NULL to a Number variable.

I add log statements to check if the items retreive their values. But i don’t know how to get further.
How do I add a log statement to the comparison part of the rule?

In order to check where the error occurs(or better where the rule is left) place a logInfo behind any line you think it is worthwhile checking. Using a different string in each will help to find the error.

Looking a bit again, the rule “Abfalltermine sortieren” has a lot of Item triggers - which explains the multiple copies running, of course.

As you seem to be setting up the value of these Items in other rules - have you considered what happens when the rule “Abfalltermine sortieren” runs using a ‘set’ of Items that haven’t all been updated yet? I’m thinking particularly of some Items still being NULL from startup, perhaps?

In any case, there is a risk of inconsistency using part of a set of Items from one event with part from some other event/time?

I’d add more log statements in the rule and now I see values of “NULL” :

==> /mnt/shares/Openhablog/openhab.log <==

2018-09-08 21:57:38.442 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum: 2018-09-12T00:00:00.000+02:00

2018-09-08 21:57:38.444 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum: 2018-09-12T00:00:00.000+02:00

2018-09-08 21:57:38.451 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage: NULL

2018-09-08 21:57:38.451 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage: NULL

2018-09-08 21:57:38.457 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum: 2018-09-19T00:00:00.000+02:00

2018-09-08 21:57:38.457 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum: 2018-09-12T00:00:00.000+02:00

2018-09-08 21:57:38.463 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage: NULL

2018-09-08 21:57:38.463 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum: 2018-09-19T00:00:00.000+02:00

2018-09-08 21:57:38.470 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum: 2018-09-26T00:00:00.000+02:00

2018-09-08 21:57:38.473 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage: NULL

2018-09-08 21:57:38.465 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage: NULL

2018-09-08 21:57:38.481 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum: 2018-09-26T00:00:00.000+02:00

2018-09-08 21:57:38.489 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage: NULL

2018-09-08 21:57:38.490 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum: 2018-09-19T00:00:00.000+02:00

2018-09-08 21:57:38.496 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage: NULL

2018-09-08 21:57:38.510 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage: NULL

2018-09-08 21:57:38.520 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum: 2018-09-26T00:00:00.000+02:00

2018-09-08 21:57:38.532 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage: NULL

==> /mnt/shares/Openhablog/events.log <==

2018-09-08 21:57:38.608 [vent.ItemStateChangedEvent] - LiamCamImage changed from raw type (image/jpeg): 41043 bytes to raw type (image/jpeg): 40773 bytes

==> /mnt/shares/Openhablog/openhab.log <==

2018-09-08 21:57:38.665 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_DatumAbfall_1_Datum (Type=DateTimeItem, State=2018-09-12T00:00:00.000+0200, Label=Afval 1 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.695 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_DatumAbfall_1_Datum (Type=DateTimeItem, State=2018-09-12T00:00:00.000+0200, Label=Afval 1 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.697 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_DatumAbfall_2_Datum (Type=DateTimeItem, State=2018-09-19T00:00:00.000+0200, Label=Afval 2 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.725 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_DatumAbfall_3_Datum (Type=DateTimeItem, State=2018-09-26T00:00:00.000+0200, Label=Afval 3 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.732 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_DatumAbfall_2_Datum (Type=DateTimeItem, State=2018-09-19T00:00:00.000+0200, Label=Afval 2 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.738 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_ArtAbfall_1_Art (Type=StringItem, State=Restmuell, Label=Afval 1 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.740 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_DatumAbfall_3_Datum (Type=DateTimeItem, State=2018-09-26T00:00:00.000+0200, Label=Afval 3 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.746 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_ArtAbfall_2_Art (Type=StringItem, State=Biomuell, Label=Afval 2 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.756 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_ArtAbfall_3_Art (Type=StringItem, State=Papiermuell, Label=Afval 3 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.757 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_ArtAbfall_1_Art (Type=StringItem, State=Restmuell, Label=Afval 1 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.769 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_ArtAbfall_2_Art (Type=StringItem, State=Biomuell, Label=Afval 2 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.781 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_ArtAbfall_3_Art (Type=StringItem, State=Papiermuell, Label=Afval 3 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.795 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_TageAbfall_1_Tage (Type=StringItem, State=NULL, Label=Afval 1 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.799 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_TageAbfall_1_Tage (Type=StringItem, State=NULL, Label=Afval 1 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.803 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_TageAbfall_2_Tage (Type=StringItem, State=NULL, Label=Afval 2 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.811 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_TageAbfall_2_Tage (Type=StringItem, State=NULL, Label=Afval 2 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.811 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_TageAbfall_3_Tage (Type=StringItem, State=NULL, Label=Afval 3 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.822 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_TageAbfall_3_Tage (Type=StringItem, State=NULL, Label=Afval 3 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.828 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_DatumAbfall_1_Datum (Type=DateTimeItem, State=2018-09-12T00:00:00.000+0200, Label=Afval 1 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.839 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_DatumAbfall_2_Datum (Type=DateTimeItem, State=2018-09-19T00:00:00.000+0200, Label=Afval 2 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.851 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_DatumAbfall_3_Datum (Type=DateTimeItem, State=2018-09-26T00:00:00.000+0200, Label=Afval 3 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 21:57:38.864 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_ArtAbfall_1_Art (Type=StringItem, State=Restmuell, Label=Afval 1 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.876 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_ArtAbfall_2_Art (Type=StringItem, State=Biomuell, Label=Afval 2 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.889 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_ArtAbfall_3_Art (Type=StringItem, State=Papiermuell, Label=Afval 3 Art, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.904 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_TageAbfall_1_Tage (Type=StringItem, State=NULL, Label=Afval 1 Tage, Category=null, Groups=[gAbfall])

2018-09-08 21:57:38.922 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_TageAbfall_2_Tage (Type=StringItem, State=NULL, Label=Afval 2 Tage, Category=null, Groups=[gAbfall])

==> /mnt/shares/Openhablog/events.log <==

2018-09-08 21:57:38.928 [vent.ItemStateChangedEvent] - RoanCamImage changed from raw type (image/jpeg): 32700 bytes to raw type (image/jpeg): 32659 bytes

==> /mnt/shares/Openhablog/openhab.log <==

2018-09-08 21:57:38.929 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_TageAbfall_3_Tage (Type=StringItem, State=NULL, Label=Afval 3 Tage, Category=null, Groups=[gAbfall])

And now 5 minutes later:

==> /mnt/shares/Openhablog/openhab.log <==

2018-09-08 22:05:38.380 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Abfalltermine sortieren': An error occurred during the script execution: null

2018-09-08 22:05:38.450 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_DatumAbfall_1_Datum (Type=DateTimeItem, State=2018-09-12T00:00:00.000+0200, Label=Afval 1 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 22:05:38.458 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_DatumAbfall_2_Datum (Type=DateTimeItem, State=2018-09-19T00:00:00.000+0200, Label=Afval 2 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 22:05:38.458 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_DatumAbfall_1_Datum (Type=DateTimeItem, State=2018-09-12T00:00:00.000+0200, Label=Afval 1 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 22:05:38.465 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_DatumAbfall_2_Datum (Type=DateTimeItem, State=2018-09-19T00:00:00.000+0200, Label=Afval 2 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 22:05:38.465 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_DatumAbfall_3_Datum (Type=DateTimeItem, State=2018-09-26T00:00:00.000+0200, Label=Afval 3 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 22:05:38.472 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_DatumAbfall_3_Datum (Type=DateTimeItem, State=2018-09-26T00:00:00.000+0200, Label=Afval 3 Datum, Category=calendar, Groups=[gAbfall])

2018-09-08 22:05:38.473 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_ArtAbfall_1_Art (Type=StringItem, State=Restmuell, Label=Afval 1 Art, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.479 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_ArtAbfall_1_Art (Type=StringItem, State=Restmuell, Label=Afval 1 Art, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.479 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_ArtAbfall_2_Art (Type=StringItem, State=Biomuell, Label=Afval 2 Art, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.486 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_ArtAbfall_2_Art (Type=StringItem, State=Biomuell, Label=Afval 2 Art, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.494 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_ArtAbfall_3_Art (Type=StringItem, State=Papiermuell, Label=Afval 3 Art, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.502 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_TageAbfall_1_Tage (Type=StringItem, State=(4 T.), Label=Afval 1 Tage, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.509 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_TageAbfall_2_Tage (Type=StringItem, State=(11 T.), Label=Afval 2 Tage, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.515 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_ArtAbfall_3_Art (Type=StringItem, State=Papiermuell, Label=Afval 3 Art, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.516 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_TageAbfall_3_Tage (Type=StringItem, State=(18 T.), Label=Afval 3 Tage, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.526 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_1_TageAbfall_1_Tage (Type=StringItem, State=(4 T.), Label=Afval 1 Tage, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.543 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_2_TageAbfall_2_Tage (Type=StringItem, State=(11 T.), Label=Afval 2 Tage, Category=null, Groups=[gAbfall])

2018-09-08 22:05:38.550 [INFO ] [e.smarthome.model.script.Afval.rules] - Abfall_3_TageAbfall_3_Tage (Type=StringItem, State=(18 T.), Label=Afval 3 Tage, Category=null, Groups=[gAbfall])

I think that this part is causing the error:

var i = 1
	while ((i=i+1) < 6) {
		if (varAbfall1Datum > varAbfall2Datum) {
			varTempDatum = varAbfall1Datum
			varAbfall1Datum = varAbfall2Datum
			varAbfall2Datum = varTempDatum
			varTempArt = varAbfall1Art
			varAbfall1Art = varAbfall2Art
			varAbfall2Art = varTempArt
			varTempTage = varAbfall1Tage
			varAbfall1Tage = varAbfall2Tage
			varAbfall2Tage = varTempTage
			if (varAbfall2Datum > varAbfall3Datum) {
				varTempDatum = varAbfall2Datum
				varAbfall2Datum = varAbfall3Datum
				varAbfall3Datum = varTempDatum
				varTempArt = varAbfall2Art
				varAbfall2Art = varAbfall3Art
				varAbfall3Art = varTempArt
				varTempTage = varAbfall2Tage
				varAbfall2Tage = varAbfall3Tage
				varAbfall3Tage = varTempTage
				}
		}
		if (varAbfall2Datum > varAbfall3Datum) {
				varTempDatum = varAbfall2Datum
				varAbfall2Datum = varAbfall3Datum
				varAbfall3Datum = varTempDatum
				varTempArt = varAbfall2Art
				varAbfall2Art = varAbfall3Art
				varAbfall3Art = varTempArt
				varTempTage = varAbfall2Tage
				varAbfall2Tage = varAbfall3Tage
				varAbfall3Tage = varTempTage
				}
		}

but I don’t know why. I copied it from the der_optimist garbage_widget .

I’d any of the values on either side of the > or < comparisons are NULL I would expect to see an error like this.

I add log statements at the comparison and there are some variables with value ‘NULL’:

2018-09-09 09:21:59.244 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempDatumnull

2018-09-09 09:21:59.247 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempDatumnull

2018-09-09 09:21:59.256 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum2018-09-12T00:00:00.000+02:00

2018-09-09 09:21:59.261 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempDatumnull

2018-09-09 09:21:59.268 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum2018-09-19T00:00:00.000+02:00

2018-09-09 09:21:59.269 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum2018-09-12T00:00:00.000+02:00

2018-09-09 09:21:59.274 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum2018-09-26T00:00:00.000+02:00

2018-09-09 09:21:59.279 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum2018-09-19T00:00:00.000+02:00

2018-09-09 09:21:59.285 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum2018-09-26T00:00:00.000+02:00

2018-09-09 09:21:59.289 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Datum2018-09-12T00:00:00.000+02:00

2018-09-09 09:21:59.295 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempArtnull

2018-09-09 09:21:59.295 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Datum2018-09-19T00:00:00.000+02:00

2018-09-09 09:21:59.307 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Datum2018-09-26T00:00:00.000+02:00

2018-09-09 09:21:59.308 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1ArtRestmuell

2018-09-09 09:21:59.308 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempArtnull

2018-09-09 09:21:59.314 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1ArtRestmuell

2018-09-09 09:21:59.314 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempArtnull

2018-09-09 09:21:59.319 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3ArtPapiermuell

2018-09-09 09:21:59.319 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3ArtPapiermuell

2018-09-09 09:21:59.324 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempTagenull

2018-09-09 09:21:59.324 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempTagenull

2018-09-09 09:21:59.329 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1ArtRestmuell

2018-09-09 09:21:59.340 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3ArtPapiermuell

2018-09-09 09:21:59.349 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage(3 T.)

2018-09-09 09:21:59.350 [INFO ] [e.smarthome.model.script.Afval.rules] - varTempTagenull

2018-09-09 09:21:59.355 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage(10 T.)

2018-09-09 09:21:59.359 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage(3 T.)

2018-09-09 09:21:59.362 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall1Tage(3 T.)

2018-09-09 09:21:59.372 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage(10 T.)

2018-09-09 09:21:59.376 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall2Tage(10 T.)

2018-09-09 09:21:59.392 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage(17 T.)

2018-09-09 09:21:59.384 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage(17 T.)

2018-09-09 09:21:59.396 [INFO ] [e.smarthome.model.script.Afval.rules] - varAbfall3Tage(17 T.)

All your Items start out as NULL, until something updates them. Maybe a rule, maybe a binding, maybe restore-on-startup. This is normal.

Your rule deals with a collection of Items. It gets triggered when one of those Items gets updated.

You probably need to think about what happens when the rule is triggered by the first Item updating, before the others in the collection are set up.

And then what happens if the next Item changes while that previous rule is still running - a new copy of the rule will start running, probably also using other Items that aren’t set up yet.

So far as I can see in your log, there are at least three copies of your rule running at the same time, see those duplicate logInfo messages.

I think you need to look at the triggering for your rule - when does it really need to run?

the only thing I want is the following widget. I don’t know if there is an easier way to accomplish that?

image

I don’t know if I need that comparison part in the rule.

Where did you find the recycling bin icon? That would be perfect for my habpanel.

Thanks,

squid

Okay, understood - I guess you copied


which I think was a work in progress.

Maybe the author @der_optimist will be able to help better

I asked him before. But he also didn’t know what’s
causing the error.

Well, we know you are getting NULL Item states. If he has his Items using restore-on-startup, he won’t be having that, after getting through the rules for the first time.

So I’ve to use restore-on-startup? How do I do that?

Keywords: persistence , mapdb, restore on startup

I did this. But how do the items get values?

1 Like