[SOLVED] Previousstate in notification rule


i created a notification rule so i get informed, if the price of gasoline at my favorite gas stations changed.

this is working quite good so far, but the last days i had the idea to show the previous price in the notification, too, so i can see if the prices were getting higher or lower:

rule "Spritpreise"
	Item TankstelleHoyerDodenhof_E10 changed or
	Item TankstelleTeamLilienthal_E10 changed or
	Item TankstelleHoyerOttersberg_E10 changed
	if ((Rule_Spritpreise.state == ON) && (nachtmodus.state == OFF)) {
	"Aktuelle E10-Preise:
	Hoyer Dodenhof " +TankstelleHoyerDodenhof_E10.state+ "€ (" +TankstelleHoyerDodenhof_E10.previousState+ "€)
	Hoyer Ottersberg " +TankstelleHoyerOttersberg_E10.state+ "€ (" +TankstelleHoyerOttersberg_E10.previousState+ "€)
	TEAM Lilienthal " +TankstelleTeamLilienthal_E10.state+ "€ (" +TankstelleTeamLilienthal_E10.previousState+ "€)"

the problem is, that i dont get the previous state correctly in the notification - i just get one of the following notifications (i dont know why, but sometimes i get the one and sometimes the other):

can you tell me whats wrong with the rule?

thanks a lot,

Do you have persistence set up?

yes, i am using mysql as default persistence service and also influxdb as a second service to play a bit around with grafana.

Are these items persisted?
And what does the error log show?

Try changing it to :


thanks! its working with previousState.state!

now i get a number (just with a lot of digits after “,” - can you also tell me how to cut it to 3 digits?)

Based on a previous post , try replacing this:

(" +TankstelleHoyerDodenhof_E10.previousState+ "€)

with this:

(" + String::format("%1$3d", TankstelleHoyerDodenhof_E10.previousState.state) + "€)
1 Like

thanks for your fast reply, but this doesnt seem to work, i get the following entry in the log:

==> /var/log/openhab2/openhab.log <==

2018-05-09 21:42:54.102 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Spritpreise': d != org.eclipse.smarthome.core.library.types.DecimalType

==> /var/log/openhab2/events.log <==

Try changing the d for an f
d is for integers
f for floats

(" + String::format("%1$3f", TankstelleHoyerDodenhof_E10.previousState.state) + "€)

tried it out, almost same result:

2018-05-09 21:47:18.310 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Spritpreise': f != org.eclipse.smarthome.core.library.types.DecimalType


2018-05-09 21:55:01.195 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Spritpreise': f != org.eclipse.smarthome.core.library.types.DecimalType


sorry for getting on your nervs, but:

2018-05-09 22:11:48.005 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Spritpreise': f != org.eclipse.smarthome.core.library.types.DecimalType

I was reading the docs but I ran out of ideas now…

ok, but thank you very much for trying to help me!

is it possible that its not working because the item is a number and no string?

No, one of these will work, we just have to find the right one…

...(" + String::format("%1$03f", (TankstelleHoyerDodenhof_E10.previousState.state as DecimalType).floatValue) + "€)...

almost :slight_smile: we are getting closer!

dont mint the UNDEF - this gas station is already closed.

Back to: