Item item_name changed from true to false does not work

  • Platform information: Raspberry Pi Nano
    • Hardware: Raspberry Pi Nano
    • OS: Rasbian image from openHABian
    • Java Runtime Environment:Zulu Embedded OpenJDK Java 8
    • openHAB version: 2
  • Issue of the topic: Item item_name changed from true to false does not work

From the rules documentation I’m trying to use a rule like this:

//Item <item> changed [from <state>] [to <state>]
Item item_name changed from true to false

But that causes an error in the openhab.log

2018-04-11 09:29:43.496 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Presence_Joseph.rules' has errors, therefore ignoring it: [7,46]: no viable alternative at input 'true'

I just want to confirm that I can only do:

Item <item> changed from <state> 

OR

Item <item> changed to <state>] 

but not both. Even though I see the following in the events.log:

2018-04-11 05:05:05.930 [vent.ItemStateChangedEvent] - HUE_Presence_Joseph_iPhone changed from true to false

I ran into the same problem with the syntax “from OFF to ON”. I saw in another thread that using quotes:

Item <item> changed from "true" to "false" 

is not supported.

I’m trying to create rules that work when an item changes from true to false but not when it change from true to NULL or from NULL to false. So if there is another way to do that, I’m love to know.

  • Please post configurations (if applicable):
    • Items configuration related to the issue
String	HUE_Presence_Joseph_iPhone <present>	(gSkur)	{ http="<[HTTP://10.0.0.126/api/<API Key>/sensors/13:3000:JS(getHuePresence.js)]" }
  • Sitemap configuration related to the issue n/a

  • Rules code related to the issue

rule "Hue Joseph Presence" 
when
Item HUE_Presence_Joseph_iPhone changed from true to false
then
	logInfo("HUE", "HUE_Presence_Joseph_iPhone: " + HUE_Presence_Joseph_iPhone.state)
end
  • Services configuration related to the issue
    HTTP Binding

  • If logs where generated please post these here using code fences:

The changed from and changed to unfortunately doesn’t work for String items. You have to use just changed and then use an if -statement to check the state.

Edit: an alternative is to change to a Switch item and make your JS-transform return ON or OFF instead of true/false.

1 Like

Ander’s is correct, there is a bug that prevents this from working right now. You can only use changed from to with the Enum type states (ON/OFF, OPEN/CLOSED, etc).

However, even if it did work your code wouldn’t work because you do not have quotes around the “true” and “false”.

true is the boolean primitive indicating true
"true" is the sequence of letters that spell out true.

There is no Boolean Item type (Switch takes ON/OFF and Contact takes OPEN/CLOSED, no Item takes true and false as a state) so your HUE_Presence_Joseph_iPhone must be a String Item so you would need to use

Item HUE_Presence_Joseph_iPhone changed from "true" to "false"

But, like has been said, this is currently not working.

This will work, but only if the Item is a Switch Item.

There is nothing wrong with the syntax on putting the quotes around “true” and “false” (I have rules that do just this in preparation for when the bug gets fixed). The syntax is supported. It just doesn’t work right now.

Since you are using a JS transform, do as Ander’s suggests and change your transform to returns “ON” for true and “OFF” for false and change HUE_Presence_Joseph_iPhone to be a Switch instead of a String. Then

Item HUE_Presence_Joseph_iPhone changed from OFF to ON

will work.

1 Like

Thanks for the quick replies! I have from OPEN to CLOSED working.