wipwap
(wip wap)
October 29, 2018, 10:21pm
1
Hi,
I have a local webside giving me some values:
AH0648EY:Consumption_Tarif8_OBIS_1.8.8:
AH0648EY:Consumption_Tarif9_OBIS_1.8.9:
AH0648EY:Consumption_CalculatedPower_OBIS_1.99.0:0.0000
AH0648EY:Consumption_Power_OBIS_1.7.0:
AH0648EY:Delivery_Total_OBIS_2.8.0:
AH0648EY:Delivery_Tarif1_OBIS_2.8.1:
Now I want to get that value (marked bold) in a minute delay as a String.
Means: all that follows after “AH0648EY:Consumption_CalculatedPower_OBIS_1.99.0:” till the end of that line
What would be the right regex expression?
Thanks for any help
wipwap
Not really an RegEx expert, but the following is working:
(?<=AH0648EY:Consumption_CalculatedPower_OBIS_1.99.0:)\d+.\d+
try that with regex101.com
Of course the string must be the same. if the numbers change, you can replace them with \d
wipwap
(wip wap)
October 29, 2018, 10:46pm
3
Hi Sascha,
thx for the quick reply.
Whe I put this in my items file:
String KWhEinspeisung “Value:[%s]” { http="<[http://192.168.1.102/plugins/smartmeter/index.php:1000:REGEX(?<=AH0648EY:Consumption_CalculatedPower_OBIS_1.99.0:)\d+.\d+ ]" }
I get the following error:
018-10-29 23:44:36.433 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘cyberstoeckli.items’ has errors, therefore ignoring it: [211,45]: mismatched character ‘d’ expecting set null
[211,164]: mismatched input ‘+’ expecting RULE_STRING
[211,170]: mismatched character ‘<EOF>’ expecting ‘"’
What am I missing? Do I have to excape sth?
thx
wipwap
(wip wap)
October 29, 2018, 10:57pm
4
I checked your regex with notepad++. Works.
But: When I put this in my items file:
String KWhEinspeisung { http="<[http://192.168.1.102/plugins/smartmeter/index.php:1000:REGEX((?<=AAH0648EY:Consumption_CalculatedPower_OBIS_1.99.0:)\\d+.\\d+)]" }
I only get null als value…
wipwap
(wip wap)
October 30, 2018, 11:21am
5
I still did not solve my problem. The html source of the webside ist like this:
AH0648EY:Last_Update:2018-10-30 12:16:27
AH0648EY:Last_UpdateLoxEpoche:310133787
AH0648EY:Consumption_Total_OBIS_1.8.0:022842.106
AH0648EY:Consumption_Tarif1_OBIS_1.8.1:012052.140
AH0648EY:Consumption_Tarif2_OBIS_1.8.2:010789.966
AH0648EY:Consumption_Tarif3_OBIS_1.8.3:
AH0648EY:Consumption_Tarif4_OBIS_1.8.4:
AH0648EY:Consumption_Tarif5_OBIS_1.8.5:
AH0648EY:Consumption_Tarif6_OBIS_1.8.6:
AH0648EY:Consumption_Tarif7_OBIS_1.8.7:
AH0648EY:Consumption_Tarif8_OBIS_1.8.8:
AH0648EY:Consumption_Tarif9_OBIS_1.8.9:
AH0648EY:Consumption_CalculatedPower_OBIS_1.99.0:0.0000
AH0648EY:Consumption_Power_OBIS_1.7.0:
AH0648EY:Delivery_Total_OBIS_2.8.0:000505.684
AH0648EY:Delivery_Tarif1_OBIS_2.8.1:000505.684
AH0648EY:Delivery_Tarif2_OBIS_2.8.2:000000.000
AH0648EY:Delivery_Tarif3_OBIS_2.8.3:
AH0648EY:Delivery_Tarif4_OBIS_2.8.4:
AH0648EY:Delivery_Tarif5_OBIS_2.8.5:
AH0648EY:Delivery_Tarif6_OBIS_2.8.6:
AH0648EY:Delivery_Tarif7_OBIS_2.8.7:
AH0648EY:Delivery_Tarif8_OBIS_2.8.8:
AH0648EY:Delivery_Tarif9_OBIS_2.8.9:
AH0648EY:Delivery_CalculatedPower_OBIS_2.99.0:0.4966
AH0648EY:Delivery_Power_OBIS_2.7.0:
AH0648EY:Total_Power_OBIS_15.7.0:
AH0648EY:Total_Power_OBIS_16.7.0:
#EOF
In my Items file I have the following line:
String Loxoneweb "Loxone: [%s]" { http="<[http://192.168.1.102/plugins/smartmeter/index.php:6000:REGEX((.*))]" }
in the openhab_log I can see, when the side is read. All values are displayed.
I would like to write a rule, that extracts one value. The number behind that string: “AH0648EY:Delivery_Total_OBIS_2.8.0:”.
the following statement does not work:
val newVal = transform("REGEX", "(?<=AH0648EY:Delivery_Total_OBIS_2.8.0:)\\d+\\.\\d+", Loxoneweb.state.toString )
newVal is always null. Someone else any Idea? I dont know what I am doing wrong.
wipwap
(wip wap)
October 30, 2018, 2:23pm
6
Problem (auf unschöne Art) selber gelöst mit diversen Substring Operationen. Beispiel:
val newVal = Loxoneweb.state.toString
LoxoneReadTime.postUpdate(newVal.substring(newVal.indexOf('AH0648EY:Last_Update:')+"AH0648EY:Last_Update:".length,newVal.indexOf('AH0648EY:Last_UpdateLoxEpoche:')-1))
Einspeisung_Total.postUpdate(newVal.substring(newVal.indexOf('AH0648EY:Delivery_Total_OBIS_2.8.0:')+"AH0648EY:Delivery_Total_OBIS_2.8.0:".length,newVal.indexOf('AH0648EY:Delivery_Tarif1_OBIS_2.8.1:')-1))
rlkoshak
(Rich Koshak)
October 30, 2018, 6:02pm
7
Unlike the way regex101.com works, in OH you must have a REGEX that matches the entire String and use parens to identify the part you want to return.
".*AH0648EY:Consumption_CalculatedPower_OBIS_\d.\d\d.\d:(\d+.\d+).*"
Note the addition of the .* at the beginning and end. This will match the rest of the String. Also note that the parens are around the Number as that is the part you want returned.
1 Like
wipwap
(wip wap)
October 30, 2018, 6:34pm
8
Hi Rikoshak
that looks more elegant but: Do I have to double escape the \ like \ ?
Yes I do. It works perfectly.
thx