OH3 Expire to set STRING to ""

Hi All

I am, trying to clean up my rules and wanted to replace the following snippet with EXPIRE:

    Alarm_Feedback.postUpdate("Alarm is already ARMED")
            createTimer(now.plusSeconds(5), [
            Alarm_Feedback.postUpdate("")
        ])

From what I have been reading this Timer will hold the rule thread for 5 seconds?

I can however not work out how to clear the item state to “” with EXPIRE.


I End up with:

""
NULL
UNDEF

But can’t get the string just EMPTY

Any suggestions please?

Cheers
Mark

This was working in OH2, more than likely it’s a UI limitation. You might try escaping quotes \"\"

Hi. No luck. Seems to use exactly what is put in the field

Result:

I suppose it’s doing its own escaping. And of course if you literally have the input field empty you get the default UNDEF I suppose?
Distinguishing empty string from real null is always a pain.

Circumvent by expiring to"BANANAS" or “idle” or something, and adjust your rules?

Thank you.

Will have to get my mind around modifying text: =items[props.alarmFeedback].state to only work if items[props.alarmFeedback].state != "CLEAR"
Will do some research
Appreciate the assistance.

For visuals, “-” or “…” might be acceptable.

A thought though - you might find you can directly edit the Item’s expire metadata for the empty string “”

This is not the case, by the way. createTimer() does what it says - creates an free-standing Timer for later execution and then immediately moves on to the next line in the “parent” rule.

So there would be no real advantage to using EXPIRE in this case? It would be more portable to have the rule clear the state for my use case - if there is no real advantage to using EXPIRE in this case?

Well, expire is (usually!) simpler to use.
It’s deliberately unsophisticated - but it does do more than your rule.
This rule blindly sets “” after 5 secs.
But expire will reset its timer every time the Item is updated (to something other than “”). That’s to say, if you post a second message within the 5 secs, it does get not blotted out by the timer from the previous message.

You can modify your rule to offer the same effect, of course, see “motion timer” examples.

OK Cool. Will see if I can get my display condition to work correctly. Not really 100% clear on the syntax, so battling…

Doesn’t work as required. I am getting the condition wrong somehow - the result is working

 text: '=!(items[props.alarmFeedback].state) ? "-" : (items[props.alarmFeedback].state)'

Appreciate the feedback.

I have tried the example straight out of the docs:

      config:
        text: =(items[props.alarmFeedback].state === 'ON') ? 'f7:lightbulb_fill' : 'f7:lightbulb'
        raised: true
        large: true
        textColor: white
        bgColor: gray
        style:
          position: absolute
          left: 103px
          top: 60px
          width: 150px
          z-index: 999

But get:

All collection items must start at the same column at line 108, column 9:

        text: '=(items[props.alarmFeedback].state === '-') ? "" : (items[props.…

What am I doing wrong?

You have the wrong quotes in your bracket, please try

Thank you.

Tried:

=(items[props.alarmFeedback].state === "ON") ? 'f7:lightbulb_fill' : 'f7:lightbulb'

Which gives me the following error now:

Nested mappings are not allowed in compact mappings at line 108, column 15:

        text: =(items[props.alarmFeedback].state === "ON") ? 'f7:lightbulb_fill…
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

Think I copied /pasted the incorrect error on my last try, so here for clarity (example direct from docs (used my Props):

=(items[props.alarmFeedback].state === 'ON') ? 'f7:lightbulb_fill' : 'f7:lightbulb'

Same error:

Nested mappings are not allowed in compact mappings at line 108, column 15:

        text: =(items[props.alarmFeedback].state === 'ON') ? 'f7:lightbulb_fill…
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

Also Tried:

= (items[props.alarmFeedback].state  === '-') ? '' : (items[props.alarmFeedback].state !== '') ? '(items[props.alarmFeedback].state)' 

Gives:

Nested mappings are not allowed in compact mappings at line 108, column 15:

        text: = (items[props.alarmFeedback].state  === '-') ? '' : (items[props…
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

And

= (items[props.alarmFeedback].state  === "-") ? '' : (items[props.alarmFeedback].state !== "") ? '(items[props.alarmFeedback].state)' 

Gives:

Nested mappings are not allowed in compact mappings at line 108, column 15:

        text: = (items[props.alarmFeedback].state  === "-") ? '' : (items[props…
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

Cheers
Mark

You are not trying what I quoted. I only changed this part :

=== "-")

The rest was unchanged…

Sorry, I am not clear which of my attempts you were quoting as it was only a portion.

Change to

        text: '=(items[props.alarmFeedback].state === "-") ? "" : (items[props.…

I think I messed up my copy paste earlier and pasted incorrect error with one of the expressions.

Anyway so have now chnaged to:

text: =(items[props.alarmFeedback].state  === "-") ? "" : (items[props.alarmFeedback].state !== "") ? '(items[props.alarmFeedback].state)' 

Which is I hope what you meant?

And get error:

Nested mappings are not allowed in compact mappings at line 108, column 15:

        text: =(items[props.alarmFeedback].state  === "-") ? "" : (items[props.…
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

This is not what I quotet, now you are missing the

'

at the beginning and probably the end…

        text: '=(items[props.alarmFeedback].state === "-") 
              ^                                        ^ ^

I realise this has become an interesting trail to follow now … but did you try directly editing Item’s expire metadata with empty string “” (not blank)? Set up an expire for “-” or whatever from UI, then you have a pattern to edit.

So I now have:

text: '=(items[props.alarmFeedback].state  === "-") ? "" : (items[props.alarmFeedback].state !== "") ? '(items[props.alarmFeedback].state)''

which gives

All collection items must start at the same column at line 108, column 9:

        text: '=(items[props.alarmFeedback].state  === "-") ? "" : (items[props…
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

Sorry, I am not clear on what you mean…