It is currently April 25th, 2024, 3:33 pm

SOLVED - Help with regex - I cannot extract info from a json file.

Get help with creating, editing & fixing problems with skins
AcmeUK
Posts: 4
Joined: February 25th, 2020, 12:56 pm

SOLVED - Help with regex - I cannot extract info from a json file.

Post by AcmeUK »

Hi Guys

I am having a problem with extracting information from a json file.

The relevant sections of my code are:-

Code: Select all

[MeasureOffice2]
Measure=Plugin
Plugin=WebParser.dll
URL=#CURRENTPATH#Office2.json
RegExp=(?siU)"mode": (.*), "CalculatedTemperature": "(.*)", "CurrentSetPoint": "(.*)"

[MeasureOffice2Mode]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureOffice2]
StringIndex=1

[MeasureOffice2CalculatedTemperature]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureOffice2]
StringIndex=2

[MeasureOffice2CurrentSetPoint]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureOffice2]
StringIndex=3

[meterTitle]
Meter=String
MeterStyle=styleTitle
; Using MeterStyle=styleTitle will basically "copy" the
; contents of the [styleTitle] section here during runtime.
X=100
Y=12
W=190
H=18
Text=Room Temperature

[meterLabelTemprature]
Meter=String
MeterStyle=styleLeftText
X=10
Y=40
W=190
H=14
Text=Temperature

[meterValueTemperature]
Meter=String
MeterStyle=styleRightText
MeasureName=MeasureOffice2CalculatedTemperature
X=200
Y=0r
; r stands for relative. In this case, the Y position of meterValueCPU is 0 pixels
; below the Y value of the previous meter (i.e it's the same as in meterLabelCPU).
W=190
H=14
Text=%1
; %1 stands for the value of MeasureName.
As you may notice I am modifying as copy of the system.ini skin.
The contents of Office2.json are :-

Code: Select all

{"id": 5, "ScheduleId": 5, "ComfortModeScore": 927, "HeatingRate": 1200, "SmartValveIds": [8], "Name": "Office 2", "Mode": "Auto", "DemandType": "Modulating", "WindowDetectionActive": false, "ControlSequenceOfOperation": "HeatingOnly", "HeatingType": "HydronicRadiator", "CalculatedTemperature": 182, "CurrentSetPoint": 180, "PercentageDemand": 0, "ControlOutputState": "Off", "SetpointOrigin": "FromSchedule", "DisplayedSetPoint": 180, "ScheduledSetPoint": 180, "AwayModeSuppressed": false, "RoundedAlexaTemperature": 180, "EffectiveMode": "Auto", "PercentageDemandForItrv": 0}
When I refresh the skin no value for temperature is displayed.

The regex is one I found in a thread on this forum. I assume that, for my case, it is not valid.

I did try to validate/debug the regex on regex101 but the message 'Your regular expression does not match the subject string.' did not help.

I have never needed to use regex before and I am totally in the dark here.

Can someone shed a bit of light for me?

Thanks
Last edited by AcmeUK on February 28th, 2020, 2:21 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help with regex - I cannot extract info from a json file.

Post by jsmorley »

Code: Select all

MeasureOffice2]
Measure=Plugin
Plugin=WebParser.dll
URL=file://#CURRENTPATH#Office2.json
RegExp=(?siU)"Mode": "(.*)".*"CalculatedTemperature": (.*),.*"CurrentSetPoint": (.*),
1) You need to be sure to use the "protocol" part of the URL, which was missing from yours. In this case it is file://.
2) I have corrected the RegExp to return the three values you are interested in.

It says:

(?siU) set the ? overall expression to s treat linefeeds as any other character, i ignore case, and be U "Ungreedy", or in other words find the "next" match after a .* skip, not the "last" match.

Search for "Mode": " and then (.*) start capturing all characters until it gets to ".

.* skip all characters until it gets to "CalculatedTemperature": .

Start (.*) capturing all characters until it gets to ,.

.* skip all characters until it gets to "CurrentSetPoint": .

Start (.*) capturing all characters until it gets to ,.

Be sure to use About / Log from the context menu to see errors, and About / Skins to see what values are actually being returned by measures. That can help a lot with debugging.
AcmeUK
Posts: 4
Joined: February 25th, 2020, 12:56 pm

Re: SOLVED - Help with regex - I cannot extract info from a json file.

Post by AcmeUK »

Hi jsmorley

That did it.

Many thanks for your help. :)

Bill
Last edited by AcmeUK on February 28th, 2020, 2:21 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: SLOVED - Help with regex - I cannot extract info from a json file.

Post by jsmorley »

Glad to help.