string parsing in dzVents? [Solved]
Moderator: leecollings
-
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?
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?
What I want to do is parse a text string into separate parts.
Is there a way in dzVents to do this?
Hans
- 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?
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: string parsing in dzVents?
Can you please elaborate a bit on this question It's now too generic to give a conclusive answer.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?
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
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?
I want to separate the return text from an "uptime" command in my Raspberry.waaren wrote: Monday 27 April 2020 21:30Can you please elaborate a bit on this question It's now too generic to give a conclusive answer.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?
Maybe domoticz.utils.stringSplit(string, seperator) function is what you are looking for ?
It returns this:
Code: Select all
01:26:00 up 7 days, 10:32, 0 users, load average: 0.21, 0.14, 0.10Code: Select all
01:26:00 up 7 days, 10:32Hans
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: string parsing in dzVents?
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
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?
Great... I had to modify the code a little to work:
With this, it works fine.
Thanks!
Code: Select all
local utils = require("Utils")
local splittedResult = utils.stringSplit(uptime,',')Thanks!
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?
@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.
- 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]
You should never have to require("Utils") in dzVents scripts.manjh wrote: Tuesday 28 April 2020 10:11 Great... I had to modify the code a little to work:With this, it works fine.Code: Select all
local utils = require("Utils") local splittedResult = utils.stringSplit(uptime,',')
Thanks!![]()
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
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?
I installed the plugin. Very interesting! There's a lot of information here... thanks!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.
Hans
Who is online
Users browsing this forum: No registered users and 1 guest