Parsing text

Need some help: I have a pellet oven that I am trying to improve my integration to. I have a python tool with which I can query status on various elements in the oven controls (through UDP) - and it returns a long text output like the one shown below;

operating_data/time=23/10-20 09:19:28
operating_data/boiler_temp=17.1
operating_data/smoke_temp=165.3
operating_data/return_temp=999.9
operating_data/dhw_temp=177.8
operating_data/external_temp=0.0
operating_data/t6_temp=0.0
operating_data/t7_temp=0.0
operating_data/distance=999
operating_data/photo_level=100
operating_data/shaft_temp=36.8
operating_data/milli_ampere=30
operating_data/oxygen=20.1
operating_data/flow1=0
operating_data/flow2=0
operating_data/flow3=0
operating_data/flow4=0
operating_data/power_pct=0
operating_data/power_kw=0.0
operating_data/oxygen_ref=0.0
operating_data/boiler_ref=20.0
operating_data/mean_out_temp=0.0
operating_data/dhw_ref=0.0
operating_data/forward_ref=0.0
operating_data/sun2_temp=0.0
operating_data/sun_dhw_temp=0.0
operating_data/sun_surplus_temp=0.0
operating_data/pressure=0.00
operating_data/air_flow=0
operating_data/sun_temp=0.0
operating_data/house_valve_state=2
operating_data/chill_out=0.0
operating_data/sun_pumpspeed=0
operating_data/sun_power_kw=0.0
operating_data/cloud_level=0
operating_data/forward_temp=0.0
operating_data/back_pressure=0
operating_data/t1_temp=0
operating_data/air_quality=0
operating_data/feed_low=2000
operating_data/feed_medium=270
operating_data/feed_high=350
operating_data/content=0
operating_data/state=20
operating_data/substate=0
operating_data/boiler_pump_state=0
operating_data/dhw_valve_state=0
operating_data/house_pump_state=0
operating_data/sun_pump_state=0
operating_data/sun_surplus_state=0
operating_data/ashbox_minutes=0.0
operating_data/ashbox_contact=0.0
operating_data/internet_uptime=100
operating_data/off_on_alarm=2
operating_data/contact2=1
operating_data/NA=1
operating_data/NA=0
operating_data/NA=1
operating_data/corr_medium=0
operating_data/NA=0
operating_data/NA=23
operating_data/compressor_clean=0.0
operating_data/fan_speed=0.0

I would like to convert this into JSON or similar - to be able to pick the field data I need and update OpenHab fields accordingly. The shown text output contain much more than what I need - but it is more efficient to get it all in one go - and then do the item handling in OH - instead of calling the UDP-API once for all the fields I need.

Any ideas how to do this in OH ?

When I call the UDP API for the oven (in Python), I simply run a “Thing” in OH which executes the Python command. The text string is the run-output of that.

Forget about trying to convert it to JSON. You can just extract the data you want using the REGEX transformation.

For example, to get the boiler_temp use .*boiler_temp=(.*)\n.*. To get the oxygen use .*oxygen=(.*)\n.*.

2 Likes

You can pipe the output to e.g. commands like:

sed -e 's#.*/##' | sed -e 's/^/"/'| sed -e 's/=/":"/' | sed -e 's/$/",/' | tr -s "\n" " " | sed -e 's/^/{/' | sed -e 's/,$/}/'

The output would look like this based on your example data:


{"10-20 09:19:28", "boiler_temp":"17.1", "smoke_temp":"165.3", "return_temp":"999.9", "dhw_temp":"177.8", "external_temp":"0.0", "t6_temp":"0.0", "t7_temp":"0.0", "distance":"999", "photo_level":"100", "shaft_temp":"36.8", "milli_ampere":"30", "oxygen":"20.1", "flow1":"0", "flow2":"0", "flow3":"0", "flow4":"0", "power_pct":"0", "power_kw":"0.0", "oxygen_ref":"0.0", "boiler_ref":"20.0", "mean_out_temp":"0.0", "dhw_ref":"0.0", "forward_ref":"0.0", "sun2_temp":"0.0", "sun_dhw_temp":"0.0", "sun_surplus_temp":"0.0", "pressure":"0.00", "air_flow":"0", "sun_temp":"0.0", "house_valve_state":"2", "chill_out":"0.0", "sun_pumpspeed":"0", "sun_power_kw":"0.0", "cloud_level":"0", "forward_temp":"0.0", "back_pressure":"0", "t1_temp":"0", "air_quality":"0", "feed_low":"2000", "feed_medium":"270", "feed_high":"350", "content":"0", "state":"20", "substate":"0", "boiler_pump_state":"0", "dhw_valve_state":"0", "house_pump_state":"0", "sun_pump_state":"0", "sun_surplus_state":"0", "ashbox_minutes":"0.0", "ashbox_contact":"0.0", "internet_uptime":"100", "off_on_alarm":"2", "contact2":"1", "NA":"1", "NA":"0", "NA":"1", "corr_medium":"0", "NA":"0", "NA":"23", "compressor_clean":"0.0", "fan_speed":"0.0"}

Unfortunately the date format breaks this.

Create a copy of your python tool and let python return the output in JSON format.

I actually got it done, using @rlkoshak REGEX suggestion. Now I am looking at the final part, which is parsing a log-output I can read out from the oven. It comes as one string with content like this (content is multiple lines);

201024,173459,1,0,2,5, 
201024,172158,1,0,0,2, 
201024,172153,1,0,6,0, 
201024,172133,1,0,28,6, 
201024,171724,1,0,6,28, 

From a webpage where I can read the log as well, I believe I can make sense of the entries - and the first part is a timestamp in the format YYMMDD,HHMMSS - and the latter part is an informational code which I can translate.

I am getting the field every 1 minute. Log entries are added as lines at the top.
I would like to create some rule which could work with this; I was thinking to store the latest log entry - and then parse the updated field for new lines since that and “do something with them” - i.e. send me a telegram message for important alerts or similar.
Any ideas to do this ?

I tried to create a REGEX to give me the first line in the string - but cannot get it working - as I struggle understanding the syntax for strings. I would then continue to get a REGEX to give me the second, and the third line in seperate fields as well - and compare on those.
Suggestions to the REGEX syntax to do that ?

OK - I have now been playing around with strings and things :wink: - and have a working solution. I need to polish it off a bit - and will then share. Thanks for the input.