Problem with read raw.Data  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Problem with read raw.Data

Post by djdevil »

Hi, I'm using this script for my RobockS50 but I have a problem with reading the rawdata of the "Cippy - Status" device
section of - Functie mirobo gegevens

and domoticz brings me this error in the log. can you help me thanks! :oops:


Code: Select all

return {
	on = {
		devices = {
			'Cippy - Status',
			'Presenza',
		},
	    timer = {
            'at 10:00 on mon,wed,fri',
            'at 23:59'
        },
	    logging = {
  		    level = domoticz.LOG_INFO,
       },
	},

	execute = function(domoticz, device)
        -- Devices m.b.t. onderhoud
        local cap_main_brush = domoticz.devices('Cippy - Care Main Brush').nValue
        local cap_side_brush = domoticz.devices('Cippy - Care Side Brush').nValue
        local cap_filter = domoticz.devices('Cippy - Care Filter').nValue
        local cap_sensors = domoticz.devices('Cippy - Care Sensors').nValue

        -- Push-notificaties voor onderhoud
        local main_brush = 'La grande spazzola arancione di Cippy deve essere sostituita al più presto! La capacità è solo '..cap_main_brush..'%.'
        local side_brush = 'La piccola spazzola sul lato di Cippy deve essere sostituita al più presto! La capacità è solo'..cap_side_brush..'%.'
        local filter = 'Il filtro di Cippy deve essere sostituito al più presto! La capacità è solo'..cap_filter..'%.'
        local sensors = 'I sensori di Cippy devono essere puliti al più presto! La capacità è solo '..cap_sensors..'%.'

        -- User variables
        local text1 = 'Pulizia non ancora effettuata oggi'
        local text2 = 'Preparo Pulizia'
        local text3 = 'Pulizia in corso'
        local text4 = 'Ritorno alla base'
        local text5 = 'Pulizia effettuata oggi'

        local Cippy = domoticz.devices('Cippy - Status')
        --Cippy.dump()

        -- Notificatie-tabel
        local myNotificationTable = {domoticz.NSS_PROWL} -- table with one or more notification system. Can be one or more of
                                                            -- dz.NSS_GOOGLE_CLOUD_MESSAGING, 
                                                            -- dz.NSS_HTTP, 
                                                            -- dz.NSS_KODI, 
                                                            -- dz.NSS_LOGITECH_MEDIASERVER, 
                                                            -- dz.NSS_NMA,
                                                            -- dz.NSS_PROWL, 
                                                            -- dz.NSS_PUSHALOT, 
                                                            -- dz.NSS_PUSHBULLET, 
                                                            -- dz.NSS_PUSHOVER, 
                                                            -- dz.NSS_PUSHSAFER



     -- Automatisch starten tussen bepaalde tijd en niemand thuis
        if domoticz.variables('CippyState').value == text1 then
            if domoticz.time.matchesRule('at 9:00-16:00 on mon,wed,fri') then
                if domoticz.devices('Presenza').state == 'Off' then
                    domoticz.devices('Cippy - Fan Level').switchSelector(20).silent() -- 10=Laag, 20=normaal, 30=hoog, 40=maximaal, 50=mop
                    domoticz.devices('Cippy - Control').switchSelector(10).silent()
                    domoticz.notify('Cippy info', '🧹 Cippy sta per pulire')
                    domoticz.variables('CippyState').set(text2)
                end
            end
        end


        --Functie mirobo gegevens
        local function mysplit(inputstr, sep)
            if sep == nil then
                sep = "%s"
            end
            local t={} ; i=1
            for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                t[i] = str
                i = i + 1
            end
            return t
        end

        --Mirobo gegevens ophalen
        local handle = io.popen("sudo mirobo --ip 192.168.1.28 --token 3973764b514d43507a55476d616b4f41") --- IP & TOKEN !!!!
        local result = handle:read("*a")
        handle:close()
      domoticz.log('Result:'..result)

        t = mysplit(result,"\n")
            if(t[1] ~= nil) then
                if(t[2] ~= nil and t[4] ~= nil and t[5] ~= nil) then -- 1=Status, 2=Batterij, 3=Fanspeed, 4=Tijd, 5=Oppervlakte
                    -- Informatie
                    local battery    = string.gsub(t[2],"Batteria: ","")
                    local fanspeed   = string.gsub(t[3],"Velocità: ","")
                    local cleantime  = string.gsub(t[4],"Pulizia: ","")
                    local cleanspace = domoticz.utils.round(string.gsub(string.gsub(t[5],"Area Pulita: ","")," m²",""),0)

                    --Stand zuig-ventilator
                    if fanspeed == '38 %' then fanspeed = 'lage'
                        elseif fanspeed == '60 %' then fanspeed = 'Normale'
                        elseif fanspeed == '75 %' then fanspeed = 'Alta'
                        elseif fanspeed == '98 %' then fanspeed = 'Massima'
                        elseif fanspeed == '105 %' then fanspeed = 'lavaggio'
                        else fanspeed = 'onbekende'
                    end
  
        -- User variables bijwerken en notificaties versturen
                if domoticz.variables('CippyState').value ~= text1 then
                    if Cippy.rawData[1] == 'Cleaning' then
                        domoticz.variables('CippyState').set(text3)
                        domoticz.notify('Cippy info', '🧹 Cippy sta effettuando la pulizia')
                    elseif Cippy.rawData[1] == 'Back to home' then
                        domoticz.variables('CippyState').set(text4)
                        domoticz.notify('Cippy info', 'Cippy alla velocità '..fanspeed..' ha pulito '..cleanspace..' m² in '..cleantime..' e ritorna alla stazione di ricarica con una batteria di '..battery..'.')
                    elseif Cippy.rawData[1] == 'Charging' and domoticz.devices('Presenza').state =='Off' then
                        domoticz.variables('CippyState').set(text5)
                        domoticz.notify('Cippy info', '✅  Cippy ha pulito e si ricarica')
                    elseif Cippy.rawData[1] == 'Paused' then
                        domoticz.notify('Cippy info', '😴 Cippy è un po stanco e si prende una pausa')
                    elseif Cippy.rawData[1] == 'Sleeping' then
                        domoticz.notify('Cippy info', '😴 Cippy non ha nulla da fare e si è addormentato. Portala alla base in modo che si possa caricare.')
                    elseif Cippy.rawData[1] == 'Waiting' then
                        domoticz.notify('Cippy info', '❗ Cippy sta aspettando le tue istruzioni')
                    elseif Cippy.rawData[1] == 'In Error' then
                        domoticz.notify('Cippy info', '❗ Cippy ha problemi e ha bisogno di aiuto!')
                    end
                end
            end
        end

Code: Select all

 
 2019-10-18 23:59:02.482 Status: dzVents: Error (2.4.19): An error occured when calling event handler Script #1
2019-10-18 23:59:02.482 Status: dzVents: Error (2.4.19): /home/pi/domoticz/dzVents/runtime/Domoticz.lua:172: attempt to perform arithmetic on local 'x' (a string value)
2019-10-18 23:59:02.483 Status: dzVents: Info: ------ Finished Script #1 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem with read raw.Data

Post by waaren »

djdevil wrote: Saturday 19 October 2019 0:05 Hi, I'm using this script for my RobockS50 but I have a problem with reading the rawdata of the "Cippy - Status" device
and domoticz brings me this error in the log. can you help me thanks! :oops:

Code: Select all

 
2019-10-18 23:59:02.482 Status: dzVents: Error (2.4.19): /home/pi/domoticz/dzVents/runtime/Domoticz.lua:172: attempt to perform arithmetic on 
Please show the complete script. Very hard to guess where the error is when only having a part of the script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Problem with read raw.Data

Post by djdevil »

Yes, I've already posted the entire code, I think the error is here in this part of the code.

Code: Select all

--Functie mirobo gegevens

        local function mysplit(inputstr, sep)
            if sep == nil then
                sep = "%s"
            end
            local t={} ; i=1
            for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                t[i] = str
                i = i + 1
            end
            return t
        end

        --Mirobo gegevens ophalen
        local handle = io.popen("sudo mirobo --ip 192.168.1.28 --token 3973764b514d43507a55476d616b4f41") --- IP & TOKEN !!!!
        local result = handle:read("*a")
        handle:close()
      domoticz.log('Result:'..result)

        t = mysplit(result,"\n")
            if(t[1] ~= nil) then
                if(t[2] ~= nil and t[4] ~= nil and t[5] ~= nil) then -- 1=Status, 2=Batterij, 3=Fanspeed, 4=Tijd, 5=Oppervlakte
                    -- Informatie
                    local battery    = string.gsub(t[2],"Batteria: ","")
                    local fanspeed   = string.gsub(t[3],"Velocità: ","")
                    local cleantime  = string.gsub(t[4],"Pulizia: ","")
                    local cleanspace = domoticz.utils.round(string.gsub(string.gsub(t[5],"Area Pulita: ","")," m²",""),0)

                    --Stand zuig-ventilator
                    if fanspeed == '38 %' then fanspeed = 'lage'
                        elseif fanspeed == '60 %' then fanspeed = 'Normale'
                        elseif fanspeed == '75 %' then fanspeed = 'Alta'
                        elseif fanspeed == '98 %' then fanspeed = 'Massima'
                        elseif fanspeed == '105 %' then fanspeed = 'lavaggio'
                        else fanspeed = 'onbekende'
                    end
  
with code

sudo mirobo --ip 192.168.1.28 --token 3973764b514d43507a55476d616b4f41

i have this data

State: Charging
Battery: 100 %
Fanspeed: 60 %
Cleaning since: 0:04:47
Cleaned area: 5.1425 m²
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem with read raw.Data

Post by waaren »

djdevil wrote: Saturday 19 October 2019 1:13 Yes, I've already posted the entire code, I think the error is here in this part of the code.
Sorry but I miss part of the script in your post. At least I dont't see the ending

Code: Select all

    end 
}
and maybe more. I cannot tell
I expect the error to be because of the domoticz.utils.round statement. You are trying to round a string there. You can only round numbers.
Try to change this from

Code: Select all

local cleanspace = domoticz.utils.round(string.gsub(string.gsub(t[5],"Area Pulita: ","")," m²",""),0)
to

Code: Select all

local cleanspace = domoticz.utils.round(tonumber((string.gsub(string.gsub(t[5],"Area Pulita: ","")," m²","")),0)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Problem with read raw.Data

Post by djdevil »

i try it but now i have this error

Code: Select all

 2019-10-19 11:53:02.355 Status: dzVents: Error (2.4.19): An error occured when calling event handler Script #2
2019-10-19 11:53:02.355 Status: dzVents: Error (2.4.19): ...domoticz/scripts/dzVents/generated_scripts/Script #2.lua:96: bad argument #2 to 'tonumber' (base out of range)
2019-10-19 11:53:02.355 Status: dzVents: Info: ------ Finished Script #2 
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem with read raw.Data

Post by waaren »

djdevil wrote: Saturday 19 October 2019 11:53 i try it but now i have error "bad argument #2 to 'tonumber' (base out of range)"
OK can you change

Code: Select all

local cleanspace = domoticz.utils.round(tonumber((string.gsub(string.gsub(t[5],"Area Pulita: ","")," m²","")),0)
to

Code: Select all

domoticz.log("t[5] = " .. tostring(t[5]), domoticz.LOG_FORCE)
local cleanspace = (t[5]):gsub("Area Pulita: ",""):gsub(" m²","")
cleanspace = tonumber(cleanspace)
cleanspace = domoticz.utils.round(cleanspace,0) 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Problem with read raw.Data

Post by djdevil »

I always get the same error but now in the log I can see the value t5! :|

Code: Select all

 2019-10-19 13:45:00.327 Status: dzVents: Info: ------ Start internal script: Script #2:, trigger: at 13:45
2019-10-19 13:45:02.680 Status: dzVents: !Info: t[5] = Cleaned area: 10.025 m²
2019-10-19 13:45:02.680 Status: dzVents: Error (2.4.19): An error occured when calling event handler Script #2
2019-10-19 13:45:02.680 Status: dzVents: Error (2.4.19): /home/pi/domoticz/dzVents/runtime/Domoticz.lua:172: attempt to perform arithmetic on local 'x' (a nil value)
2019-10-19 13:45:02.680 Status: dzVents: Info: ------ Finished Script #2
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem with read raw.Data

Post by waaren »

djdevil wrote: Saturday 19 October 2019 13:49 I always get the same error but now in the log I can see the value t5! :|
The problem is there !
You try to remove the string "Area Pulita: " but the string is actually "Cleaned area: "
so change

Code: Select all

local cleanspace = (t[5]):gsub("Area Pulita: ",""):gsub(" m²","")
to

Code: Select all

local cleanspace = (t[5]):gsub("Cleaned area: ",""):gsub(" m²","")
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Problem with read raw.Data  [Solved]

Post by djdevil »

you are great! as a fool :? I also translated the variable into Italian! I lost two days on it! I thank you as always! you are the best! Solved :D
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest