Find last line in response

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

Moderator: leecollings

Post Reply
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Find last line in response

Post by javalin »

Dear all, I have a big result from a small script execution, how could I delete all the lines except the last one??

Code: Select all

 
2022-02-08 22:57:02.390 867,2022-02-08 16:50:00,-990.0,-990.0,-990.0,-990.0,-990,18.2,11.0,63,156,15,160,22,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 17:00:00,-990.0,-990.0,-990.0,-990.0,-990,17.9,11.5,66,157,15,156,23,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 17:10:00,-990.0,-990.0,-990.0,-990.0,-990,17.7,11.9,69,158,14,154,21,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 17:20:00,-990.0,-990.0,-990.0,-990.0,-990,17.5,12.2,71,156,12,145,19,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 17:30:00,-990.0,-990.0,-990.0,-990.0,-990,17.3,12.4,73,152,12,158,19,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 17:40:00,-990.0,-990.0,-990.0,-990.0,-990,17.0,12.3,74,147,11,172,17,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 17:50:00,-990.0,-990.0,-990.0,-990.0,-990,16.7,12.0,74,148,13,147,20,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 18:00:00,-990.0,-990.0,-990.0,-990.0,-990,16.5,11.9,74,151,11,149,17,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 18:10:00,-990.0,-990.0,-990.0,-990.0,-990,16.1,11.7,75,150,10,144,15,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 18:20:00,-990.0,-990.0,-990.0,-990.0,-990,16.0,11.6,75,151,11,149,18,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 18:30:00,-990.0,-990.0,-990.0,-990.0,-990,15.9,11.5,75,150,10,160,15,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 18:40:00,-990.0,-990.0,-990.0,-990.0,-990,15.6,11.4,76,142,8,123,14,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 18:50:00,-990.0,-990.0,-990.0,-990.0,-990,15.5,11.3,76,141,7,153,13,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 19:00:00,-990.0,-990.0,-990.0,-990.0,-990,15.5,11.3,76,140,8,151,15,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 19:10:00,-990.0,-990.0,-990.0,-990.0,-990,15.5,11.3,76,127,7,140,13,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 19:20:00,-990.0,-990.0,-990.0,-990.0,-990,15.6,11.6,77,117,9,129,13,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 19:30:00,-990.0,-990.0,-990.0,-990.0,-990,15.4,11.4,77,114,9,130,17,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 19:40:00,-990.0,-990.0,-990.0,-990.0,-990,15.4,11.2,76,132,8,115,12,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 19:50:00,-990.0,-990.0,-990.0,-990.0,-990,15.2,11.2,77,137,9,148,13,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 20:00:00,-990.0,-990.0,-990.0,-990.0,-990,14.9,11.3,79,138,7,135,11,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 20:10:00,-990.0,-990.0,-990.0,-990.0,-990,14.8,11.6,81,134,9,148,16,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 20:20:00,-990.0,-990.0,-990.0,-990.0,-990,14.9,11.7,81,138,10,140,17,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 20:30:00,-990.0,-990.0,-990.0,-990.0,-990,14.9,11.7,81,145,11,160,17,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 20:40:00,-990.0,-990.0,-990.0,-990.0,-990,14.7,11.7,82,151,10,164,18,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 20:50:00,-990.0,-990.0,-990.0,-990.0,-990,14.8,11.8,82,145,11,165,19,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 21:00:00,-990.0,-990.0,-990.0,-990.0,-990,14.7,11.7,82,138,10,139,17,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 21:10:00,-990.0,-990.0,-990.0,-990.0,-990,14.7,11.7,82,141,16,135,26,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 21:20:00,-990.0,-990.0,-990.0,-990.0,-990,14.8,11.8,82,140,15,151,23,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 21:30:00,-990.0,-990.0,-990.0,-990.0,-990,14.8,11.8,82,135,14,138,25,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 21:40:00,-990.0,-990.0,-990.0,-990.0,-990,14.6,11.7,83,137,11,133,18,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 21:50:00,-990.0,-990.0,-990.0,-990.0,-990,14.3,11.8,85,138,9,147,18,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 22:00:00,-990.0,-990.0,-990.0,-990.0,-990,14.4,11.9,85,137,13,163,19,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 22:10:00,-990.0,-990.0,-990.0,-990.0,-990,14.3,11.8,85,141,10,126,16,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 22:20:00,-990.0,-990.0,-990.0,-990.0,-990,14.1,11.8,86,138,9,142,13,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 22:30:00,-990.0,-990.0,-990.0,-990.0,-990,13.9,11.8,87,142,10,151,15,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
2022-02-08 22:57:02.390 867,2022-02-08 22:40:00,-990.0,-990.0,-990.0,-990.0,-990,13.9,11.8,87,136,9,130,14,0,0,h1,c1,h2,c2,0.0,0.0,19.5,5.2,&value=||||||||||||||||||||| °
The script:

Code: Select all

local scriptVar = 'EMA'

return {
            on =    { 
                        timer = { 'every minute'},
                        httpResponses = { scriptVar },
                    },
 
       logging =    {   
                        level   =   domoticz.LOG_DEBUG,
                        marker  =   scriptVar,
                    },    

    execute = function(dz, item)
        local EMAurl = 'URL TO USE'
        
        local function getEMAData()
            dz.openURL(
            {
                url = EMAurl,
                callback = scriptVar,
            })
        end

        if item.isHTTPResponse then
            dz.log("Return from EMA \n" .. item.data,dz.LOG_DEBUG)
        else
            getEMAData()
        end
    end
}
Kind regards
User avatar
waltervl
Posts: 5842
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Find last line in response

Post by waltervl »

If item.data is a table you perhaps can do something like

Code: Select all

local result_table = item.data 
local tc = #result_table -- counting lines
domoticz.log('last line = ' .. result_table[tc] )
        
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Re: Find last line in response

Post by javalin »

If item.data is a table you perhaps can do something like
item.data is not a table is a string, basically I would like to delete all lines before last one or last cases of a string and then fill table with values.
User avatar
waltervl
Posts: 5842
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Find last line in response

Post by waltervl »

DzVents is an extension on Lua so for this you will need some Lua functions. Check Google.....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest