Page 1 of 1
string parsing in dzVents?
Posted: Monday 27 April 2020 15:50
by manjh
This is so basic that I thought I should be able to find a solution, but I have not.
What I want to do is parse a text string into separate parts.
Is there a way in dzVents to do this?
Re: string parsing in dzVents?
Posted: Monday 27 April 2020 17:28
by boum
Hi, I think there are specific additions to Lua in dzVents for string manipulation in domoticz.utils._
See
https://www.domoticz.com/wiki/Lodash_documentation
There are also the lua language string manipulation functions documented
http://lua-users.org/wiki/StringLibraryTutorial and for splitting strings, see
http://lua-users.org/wiki/SplitJoin
Re: string parsing in dzVents?
Posted: Monday 27 April 2020 21:30
by waaren
manjh wrote: Monday 27 April 2020 15:50
This is so basic that I thought I should be able to find a solution, but I have not.
What I want to do is parse a text string into separate parts.
Is there a way in dzVents to do this?
Can you please elaborate a bit on this question It's now too generic to give a conclusive answer.
Maybe domoticz.utils.stringSplit(string, seperator) function is what you are looking for ?
Re: string parsing in dzVents?
Posted: Tuesday 28 April 2020 1:28
by manjh
waaren wrote: Monday 27 April 2020 21:30
manjh wrote: Monday 27 April 2020 15:50
This is so basic that I thought I should be able to find a solution, but I have not.
What I want to do is parse a text string into separate parts.
Is there a way in dzVents to do this?
Can you please elaborate a bit on this question It's now too generic to give a conclusive answer.
Maybe domoticz.utils.stringSplit(string, seperator) function is what you are looking for ?
I want to separate the return text from an "uptime" command in my Raspberry.
It returns this:
Code: Select all
01:26:00 up 7 days, 10:32, 0 users, load average: 0.21, 0.14, 0.10
I want to keep only this part:
So a simple split on the second comma would do it, I think
Re: string parsing in dzVents?
Posted: Tuesday 28 April 2020 7:38
by waaren
manjh wrote: Tuesday 28 April 2020 1:28
01:26:00 up 7 days, 10:32, 0 users, load average: 0.21, 0.14, 0.10
I want to keep only this part:
01:26:00 up 7 days, 10:32
So a simple split on the second comma would do it, I think
Code: Select all
local result = "01:26:00 up 7 days, 10:32, 0 users, load average: 0.21, 0.14, 0.10"
local splittedResult = domoticz.utils.stringSplit(result,',') -- split string into (table) parts with , as separator
domoticz.log(splittedResult[1] .. ',' .. splittedResult[2], domoticz.LOG_FORCE) -- first two parts
Re: string parsing in dzVents?
Posted: Tuesday 28 April 2020 10:11
by manjh
Great... I had to modify the code a little to work:
Code: Select all
local utils = require("Utils")
local splittedResult = utils.stringSplit(uptime,',')
With this, it works fine.
Thanks!

Re: string parsing in dzVents?
Posted: Tuesday 28 April 2020 10:15
by ronaldbro
@manjh, if you're interested in the uptime... May I suggest to look at this plugin
https://github.com/Xorfor/Domoticz-PiMonitor-Plugin. It contains als gives you a device with the uptime and a lot of other info to monitor the health of your pi.
Re: string parsing in dzVents? [Solved]
Posted: Tuesday 28 April 2020 10:16
by waaren
manjh wrote: Tuesday 28 April 2020 10:11
Great... I had to modify the code a little to work:
Code: Select all
local utils = require("Utils")
local splittedResult = utils.stringSplit(uptime,',')
With this, it works fine.
Thanks!
You should never have to require("Utils") in dzVents scripts.
Probably your first parm to execute = function is not domoticz but dz
Then the call become
Code: Select all
local splittedResult = dz.utils.stringSplit(uptime,',')
Re: string parsing in dzVents?
Posted: Tuesday 28 April 2020 10:32
by manjh
I installed the plugin. Very interesting! There's a lot of information here... thanks!