rdie77
(Diego)
January 31, 2022, 8:52pm
1
Platform information:
Hardware: Raspberry Pi 3 Model B Rev 1.2
OS: Raspbian GNU/Linux 10 (buster)
Java Runtime Environment: which java platform is used and what version
openHAB version: 2.5.12 (Build)
Hi all
I have the following item for ping device
Switch espSala { channel="network:pingdevice:espSala:online" }
Number:Time espSalaResponseTime { channel="network:pingdevice:espSala:latency" }
sitemap section
Text item=espSalaResponseTime label="Zona Giorno [%s]" icon="chip"
thing section
Thing network:pingdevice:espSala [ hostname="192.168.3.203" ]
This is the result on BasicUI from mobile phone when IP is OK
I would like if the ip was KO, the color was red, for example
How I can do this?
Matze0211
(Matthias)
January 31, 2022, 9:33pm
2
In the official documentation is an example to set colors. Have you seen this?
Try
Text item=espSalaResponseTime label="Zona Giorno [%s]" icon="chip" valuecolor=["ON"="green", "OFF"="red"]
rdie77
(Diego)
February 1, 2022, 3:15pm
5
Thanks a lot!!!
I works fine!!!
rdie77
(Diego)
February 9, 2022, 8:23pm
6
Hi everyone
I have another question and I don’t know how to solve it
I have this item to take the temperature value
String GY21 "Value: [%S C/U]" <temperature> ["CurrentTemperature"] {http="<[http://192.168.3.206/GY21.html:80000:REGEX((.*?))]"}
and the output format is “18.79|60.41” (temperature|humidity)
Now I want that if ONLY temperature value is more or less than specific value, the text must be of specific color.
How can I do this?
Thanks
rossko57
(Rossko57)
February 9, 2022, 8:49pm
7
You will have to parse out the temperature-only part into a separate Number type Item, either from another HTTP channel or by rule.
Then you can use something like
valuecolor=[someOtherItem>=20="red"]
Have you looked at the docs at all?
rdie77
(Diego)
February 9, 2022, 9:06pm
8
thank you very much, but I don’t want to use another HTTP channel just for temperature, because the value is taken from an esp8266 with all values
Can I parse the value with HTTP channel?
rossko57
(Rossko57)
February 9, 2022, 11:51pm
9
It doesn’t cost anything. The HTTP Thing fetches the data; as “children” of that Thing you can have a whole bunch of channels, each interpreting and selecting from the same data into different openHAB Items.
rdie77
(Diego)
February 10, 2022, 7:08pm
10
Hi rossko57
thanks for your explanation.
If I have understood well, I have to use REGEX into HTTP, in order to parsing “|” value, right?
rossko57
(Rossko57)
February 11, 2022, 10:05am
11
That’s a good way to do it, yes.
rdie77
(Diego)
February 25, 2022, 11:31am
12
Hi rossko57
I tried to parse “|” value for HTTP, but it doesn’t work. I checked my REGEX online and it works.
But I would prefer to parse with item object, so I don’t call more times HTTP (sometimes ESP8266 loses the wifi connection)
Could you help me in this way?
Thanks a lot
rossko57
(Rossko57)
February 25, 2022, 11:47am
13
What with? i.e. what have you done so far?
rdie77
(Diego)
February 25, 2022, 12:57pm
14
I tried to parse my temperature value with HTTP item
String ExtGY21 "Value: [%S C/U]" <temperature> ["CurrentTemperature"] {http="<[http://192.168.3.204/GY21.html:80000:REGEX((.*?))]"}
but it didn’t work
I would parse my value after HTTP call, so I’ll have only one call to take all values and after take specific value (temperature or humidity)
rossko57
(Rossko57)
February 25, 2022, 2:01pm
15
There’s nothing there to select the temperature part. Would you not want to select until | character?
Because you are using v1 binding, you will have to set that up as a cache in your HTTP.cfg
rdie77
(Diego)
February 25, 2022, 10:53pm
16
Hi rossko57
thanks a lot for your support
I created for test in my http.cfg
http:test.url=http://192.168.3.206/GY21.html
http:test.updateInterval=60000
and in my item file I tried a few solutions, but nothing work fine
String testHTTP "Value: [%S]" <temperature> { http="<[test:10000:REGEX((%7C.*?))]" }
//String testHTTP "Value: [%S]" <temperature> { http=">[*:POST:test&type=%7C]" }
Output of http is “19.25|58.20”, and I want only “19.25”
Thanks
rossko57
(Rossko57)
February 26, 2022, 12:13am
17
Okay. There is no % or 7 or C in there, so this is not going to work.
REGEX((%7C.*?))
When a REGEX transformation fails, you get the whole original string.
Experimenting in rules is good for transform testing.
val rawtext = "19.25|58.20"
var results = transform("REGEX", "(\\d+.\\d+)\\|.*", rawtext)
logInfo("test", "from " + rawtext + " extract " + results)
This REGEX captures digits from the start, then a decimal point, then more digits until it encounters the | character, then to the end without capture.
Note that d and | need to be escaped with double \
2022-02-26 00:00:44.188 [INFO ] [.eclipse.smarthome.model.script.test] - from 19.25|58.20 extract 19.25
rdie77
(Diego)
February 26, 2022, 7:19am
18
Hi rossko75
great!!thanks for your help
It’s working fine!!
Now in my sietmap I write this to change valuecolor
Text item=testHTTP
Default item=GY21 label="GY21" valuecolor=[testHTTP<=23="blue"]
Two issue for me:
I don’t want to see testHTTP item
GY21 item doesn’t change valuecolor by checking testHTTP item
How can I resolve it?
Thanks
rossko57
(Rossko57)
February 26, 2022, 11:00am
19
rdie77:
I don’t want to see testHTTP item
Then you would remove the widget that you put there to show testHTTP item.
Text item=testHTTP
No, it wouldn’t.
testHTTP<=23
is an arithmetic comparison, but your Item is a String type. If you want to do maths you will need a Number.
rdie77
(Diego)
February 26, 2022, 12:02pm
20
Yes, I want use value item testHTTP only for comparison to change valecolour of other item (item=GY21), but I don’t want show it on basicUI
I changed to number for the item testHTTP and now it works fine