Strings in rules

Tags: #<Tag:0x00007f616f26a9d0>

I have the Alarm Decoder binding set up and I want to determine whether the alarm is armed. The Galant panel I have operates differently to the Vista, for which the Alarm Decoder was designed. None of the bits are set/unset when the panel is armed (except during the exit time) but what does happen is the display goes clear until the alarm is unset.

Therefore I am trying to use a simple rule to update a Number item to either 0 or 1 depending on whether the display is blank.

I have this rule but it doesn’t work:

rule AlarmArmed
when Item alarmPanelDisplay changed
if (alarmPanelDisplay == “” “”) {
else {

I have tried with and without the escaped quotes (the quotes are present when I view the string in either the REST API or the Classic UI).

I have also tried the string with only a single space (with and without quotes) because the string of 32 spaces appears to collapse to a single space when viewed in the REST API.

Whatever I do, the value of alarmArmed stays at 0.

I guess I’m doing the string comparison wrong but I can’t work out how. Any help please?

Two issues:

You need to compare the state of alarmPanelDisplay.

if(alarmPanelDisplay.state.toString == "\"\"") {

The second is you should print out exactly what the string looks like, not just how it is encoded on a GUI somewhere. Add

logInfo("AlarmArmed", "alarmPanelDisplay is set to ---" + alarmPanelDisplay.state.toString + "--")

Whatever appears between the “—” in your log is what you need to compare against. If nothing appears (i.e. ------) then use == "". It must exactly match though. Same number of spaces, quotes (escaped as you are doing above) and all.

That worked brilliantly.

Thanks for your help.