[Solved] Cannot get Rules to work in OpenHab2

Hi There,
I’ve got OH2 working with lots of different devices and with different bindings (On RPi3 with OpenHabian).
However, I cannot get a single rule to work. I don’t get log errors. I get nothing. I must be doing something really obviously wrong but have no idea what.

Here’s a rule, for example.

/*** Kodi pause ***/

/* Needed as pause is a change state (play/pause) and alexa needs ON/OFF)  */

rule "kodi pause"


	Item KodiPauseAlexa received command

	if (KodiPauseAlexa.state == ON ) {
	sendCommand(KodiPause, PAUSE)

	if (KodiPauseAlexa.state == OFF) {
	sendCommand(KodiPause, PLAY)

and the items:

Player KodiPause "Kodi Pause" { channel="kodi:kodi:GuestRoom:control" }
Switch KodiPauseAlexa  "TV Pause"  [ "Switchable" ]

This is just an example to get an Alexa Echo to pause Kodi. Other commands (without rules) from Alexa to Kodi work perfectly.
Other rules don’t work either.
There are no log errors either.

My rules file is in /etc/openhab2/rules.

Any ideas? Thanks!

Change When to when.

1 Like

Thank you so much. That fixed it. Works perfectly now. Any rule I tried did not work and I was convinced it was something more fundamental.
I guess they must all have similar errors. Thank you again.

1 Like

I highly recommend Designer to quickly identify syntax errors on rules code.

1 Like

Your my hero. lol. Was just starting to figure out how to do this myself and was having issues. So this solved it immediately!