OH3 Expire to set STRING to ""

Is this the complete Line ??? There are some more errors in there :

There is a superfluent ’ before and after the third (items[… statement
There is a missing " : EXPRESSION" part after the third (items[… statement

So correctly it should be something like this:

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

Thank you so much.

What I have now is:

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

Which is working as I wanted.

If you don’t mind can you clarify the syntax for me then?
From what I understand:

If alarmFeedback.state === “-” then text : “”
:
If alarmFeedback.state !== “-” then text : alarmFeedback.state
:
Not sure what the last one does?

Thanks again. Was really starting to doubt my sanity

Okay, I try to explain :

You have several booleans nested.

  1. (items[props.alarmFeedback].state === “-”)
    If it is true, resulting text is empty (""), if it is false, check second boolean :

  2. (items[props.alarmFeedback].state !== “”)
    If it is true, text result is set to alarmFeedback.state, if it is false, you now set it again to state…

So you will see

  • No text if state is undefined
  • State if not empty
  • No text if state is empty

I think you could simplify your expression to be the following :

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

I think my problem was trying to do your shortened version more explicitly… So was still think that either the string is “-” or it isn’t.
Have used you shortened version and it is great.

Once again thank you.

1 Like

I didn’t see where this specific statement was address in the thread. That is not correct. A Timer runs in the background, it does not tie up a rule thread. It sits quietly in the background until the scheduled time comes to run the passed in lambda.

So if the reason for changing is you are afraid of long running rules, you’ve nothing to fear. Timers exist to avoid tying up a thread waiting around doing nothing.

1 Like

Thanks for the confirmation. Went with expire in the end… to justify the effort to get the expression working.

Appreciate your help.

Rich, I was hoping you’d be curious enough to investigate “expire to empty string”. :wink: (We did flush all this out for OH2)

I suspect it is a UI limitation, and directly editing expire metadata to state:"" will work.
But it is a different expire implementation in OH3, and the lesson may have been forgotten.

I brought it up on the PR where Expire was added to the core and was under the impression that it was added. But I never tested it. If it’s not working perhaps an issue should be filled. My understanding was it was supposed to be possible.

I’m a little short on time theses days (lots of personal stuff) and it’s challenging to even keep up with the forum. So I really can’t sign myself up for a looking deep into stuff like this right now.

1 Like

It is possible to get an empty string through the expire metadata, but you have to use the “send command” version and not the “update state” version. I don’t think it’s the UI but how the metadata is interpreted by the core. If the update state option is selected, the format of the expire metadata is:

value: time,new state

If it’s just value: time or if it is value: time, this is interpreted as an absence of value and UNDEF is the resultant state.

If the send command option is used the format of the metadata is:

value: time,command=new state

But here if the command is blank after the = you actually get an empty string as the value. Here are the logs from an example value: 0h0m5s,command=

2021-05-01 17:31:45.338 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Expire_Test' received command Test
2021-05-01 17:31:45.339 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Expire_Test' changed from UNDEF to Test
2021-05-01 17:31:50.698 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Expire_Test' received command 
2021-05-01 17:31:50.698 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Expire_Test' changed from Test to 
1 Like

Makes sense - you cannot command UNDEF.

That just leaves the regression bug of state="" (this works in OH2).
Does that really not work with explicitly setting empty string “” in metadata?

One thing to be sure to look at is how the metadata is rendered in the UI, in the code tab, and how it’s rendered in the JSON itself. There might be some translation issues going on with empty strings between the three that is causing problems. I know that with widgets I think the UI treats empty string to mean “use the default” and it actually doesn’t save/render the empty string. That’s why (I think) you have to use " " in the State Description metadata to suppress the printing of the Item’s state when it’s rendered in a List Item Widget.