Send a var value to a string item

Hi all,
I’m not sure if the correct place for my question is here or in the iOS App section of the forum. Sorry if I got it wrong.
My system is: Raspberry Pi 4 with openhabian, OH3.0.1, iOS App version 2.4.20

I have a string item that I want to hold my public IP address to show in a sitemap. The check is triggered manually with a switch item
The items definition:

String Sys_PublicIP "Systme Public IP [%s]"             <ip>      ["Point"]
Switch Sys_CheckPublicIP "System Public IP Check"       <search>  ["Point"]

I’m populating the value with the following rule:

val String filename = "system.rules"

rule "Check Public IP"
    Item Sys_CheckPublicIP received command ON
    logInfo(filename, "Checking Public IP")
    val String currentIP = executeCommandLine(Duration.ofSeconds(15),"dig","+short","","")
    logInfo(filename, "IP is: " + currentIP)

The relevant part of the sitemap:

        Text        item=Sys_PublicIP       label="Public IP [%s]"
        Switch      item=Sys_CheckPublicIP  label="Update Public IP" mappings=[ON="Check"]

Now the problem is that my iOS App doesn’t show the value.

I know the value is correct by checking the logs from the rule and also on every other device the sitemap shows the value correctly.
For example- BasicUI on my PC, checking the value in MainUI, and the android app on another mobile device.

Unless it’s a problem of the iOS App, I think that the problem is connected to the type the currentIP var get. (That’s why I decided to put it in this section of the forum)
If I simply write something like this, the iOS App shows the value like expected:


It’s obviously not the correct IP, just put a random string value but of the same “structure”. But any proper string works.

My guess is that I should cast the result of the executeCommandLine somehow but I can’t figure out the proper way. But then again I might be totally wrong :thinking:

Any idea would be appreciated.
Thank you all…

I don’t think you’ve ever asked for it.
Trying putting [%s] at end of Item definition label, or at end of sitemap Switch widget label.

EDIT - oh wait,I got muddled about which Item is which. I think you’re just
suffering IoS app reluctance to display.

As an aside, if you just want to update an Item then do so using postUpdate, no need for commands.

Hi thanks for your answer.

Ok. I understand the difference most of the times, but I guess I don’t really understand what’s under the hood and why is it important when the item is not linked to a binding.

So you think it’s an app related problem?
Is there another way to cast the var to String type I might want to try?

Thank you very much.

I think you’ve worked this out for yourself.

A string state is a string state. Barring exposing some odd presentation bug with some weird character combination - has happened with e.g. “[text]” - and I’m sure you haven’t with just numbers and dots.

You might check if it is just numbers and dots - count characters,in case your query return begins with a newline or similar.

Thanks for the tip.
Will try it and report the result…

So I tried to following:

    logInfo(filename, "Number of chars: " + currentIP.length)

and the result was 13 so it looks pretty normal to me.
So I guess it is an iOS problem. I have no idea how or if I should let someone know about it…

In the meantime I found a workaround. I added a sendNotification line to the rule with the currentIP and it send it to my app so I can see it.


So after a good night sleep I found the problem and the solution.

It occurred to me that 13 wasn’t the right number after all. It should have been 12 so I figured the extra character is probably \n.

So I tried it and confirmed that a string with \n at the end will display correctly in BasicUI and Android App but not in the iOS App.

So the obvious solution is to remove the last character.
Final rule is:

val String filename = "system.rules"

rule "Check Public IP"
    Item Sys_CheckPublicIP received command ON
    logInfo(filename, "Checking Public IP")
    var String currentIP = executeCommandLine(Duration.ofSeconds(15),"dig","+short","","")
    logInfo(filename, "IP is: " + currentIP)
    currentIP = currentIP.substring(0,currentIP.length-1)

Thank you @rossko57 for the length tip.