string parsing in dzVents?  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

string parsing in dzVents?

Post 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?
Hans
User avatar
boum
Posts: 136
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: string parsing in dzVents?

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: string parsing in dzVents?

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: string parsing in dzVents?

Post 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:

Code: Select all

01:26:00 up 7 days, 10:32
So a simple split on the second comma would do it, I think
Hans
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: string parsing in dzVents?

Post 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 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: string parsing in dzVents?

Post 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! :D
Hans
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: string parsing in dzVents?

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: string parsing in dzVents?  [Solved]

Post 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! :D
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,',')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: string parsing in dzVents?

Post by manjh »

ronaldbro wrote: Tuesday 28 April 2020 10:15 @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.
I installed the plugin. Very interesting! There's a lot of information here... thanks!
Hans
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest