roborock dzvents problem  [Solved]

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

Moderator: leecollings

Post Reply
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

roborock dzvents problem

Post by molnaratti »

I've received the following error message since the last beta update (Domoticz2020.2 (build 12086):

2020-05-27 18:27:07.780 Error: dzVents: Error: (3.0.7) An error occurred when calling event handler roborock
2020-05-27 18:27:07.780 Error: dzVents: Error: (3.0.7) /home/pi/domoticz/dzVents/runtime/Utils.lua:119: attempt to compare number with string

Code: Select all

return {
	on = {
		devices = {
			'Svetlana - Status',
			'Atti_telefon',
		},
	    timer = {
            'at 9:28 on mon,tue,wed,thu,fri',
            'at 23:59'
        },
--	    logging = {
--  		    level = domoticz.LOG_INFO,
--        },
	},

	execute = function(domoticz, device)
        -- karbantartási eszközök
        local cap_main_brush = domoticz.devices('Svetlana - Care Main Brush').nValue
        local cap_side_brush = domoticz.devices('Svetlana - Care Side Brush').nValue
        local cap_filter = domoticz.devices('Svetlana - Care Filter').nValue
        local cap_sensors = domoticz.devices('Svetlana - Care Sensors').nValue

        -- Push-üzenenetek az eszközök állapotáról
        local main_brush = 'A porszívó főkeféje hamarosan cserére szorul! A kapacitás csak '..cap_main_brush..'%. Nézd meg az eustocknál'
        local side_brush = 'A porszívó oldalkeféje hamarosan cserére szorul! A kapacitás csak '..cap_side_brush..'%. lehet van a fiókban'
        local filter = 'A porszívó porszűrője hamarosan cserére szorul. A kapacitás már csak '..cap_filter..'%. '
        local sensors = 'A porszívó szenzorok koszosak. Már csak '..cap_sensors..'%.'

        -- User variables
        local text1 = 'ma meg nem volt porszivozas'
        local text2 = 'porszívózás következik'
        local text3 = 'porszívózás'
        local text4 = 'vissza a töltőállomáshoz'
        local text5 = 'ma felporszívózott'

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

        -- Notificatie-tabel
        local myNotificationTable = {domoticz.NSS_TELEGRAM} -- 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



     -- Automatikus indítás az alábbi időpontok közt, ha senki nincs otthon
        if domoticz.variables('SvetlanaState').value == text1 then
            if domoticz.time.matchesRule('at 9:00-18:00 on mon,tue,wed,thu,fri') then
                if domoticz.devices('Atti_telefon').state == 'Off' then
                    domoticz.devices('Svetlana - Fan Level').switchSelector(30).silent() -- 10=csendes, 20=normál, 30=nagy, 40=maximaal, 50=szőnyeg
                    domoticz.devices('Svetlana - Control').switchSelector(10).silent()
                    domoticz.notify('Svetlana info', 'A porszívózás elkezdődött')
                    domoticz.variables('SvetlanaState').set(text2)
                end
            end
        end


        --Funkció adatok
        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

        --funkciók beolvasásáa
        local handle = io.popen("sudo mirobo --ip 192.168.1.194 --token 444f427442686a554d4b7a666e676f46") --- 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
                    -- Információk
                    local battery    = string.gsub(t[2],"Battery: ","")
                    local fanspeed   = string.gsub(t[3],"Fanspeed: ","")
                    local cleantime  = string.gsub(t[4],"Cleaning since: ","")
                    local cleanspace = domoticz.utils.round(string.gsub(string.gsub(t[5],"Cleaned area: ","")," m²",""),0)

                    --Szívóerő helyzete
                    if fanspeed == '38 %' then fanspeed = 'kicsi'
                        elseif fanspeed == '60 %' then fanspeed = 'normal'
                        elseif fanspeed == '75 %' then fanspeed = 'nagy'
                        elseif fanspeed == '98 %' then fanspeed = 'maximum'
                        elseif fanspeed == '105 %' then fanspeed = 'szőnyeg'
                        else fanspeed = 'A'
                    end
  
        -- felhasználói vátozók és értesítések
                if domoticz.variables('SvetlanaState').value ~= text1 then
                    if Svetlana.rawData[1] == 'Cleaning' then
                        domoticz.variables('SvetlanaState').set(text3)
                        domoticz.notify('Svetlana info', 'A porszívózás folyamatban')
                    elseif Svetlana.rawData[1] == 'Back to home' then
                        domoticz.variables('SvetlanaState').set(text4)
                        domoticz.notify('Svetlana info', '_ '..fanspeed..' ház felporszívózva: '..cleanspace..' m². Végeztem '..cleantime..' idő alatt. Visszamegyek a dokkolóállomásra. Az akksiban '..battery..' maradt.')
                    elseif Svetlana.rawData[1] == 'Charging' and domoticz.devices('Atti_telefon').state =='Off' then  --ha nem vagyunk itthon
                        domoticz.variables('SvetlanaState').set(text5)
                        -- domoticz.notify('Svetlana info', '✅  Töltés')
                    elseif Svetlana.rawData[1] == 'Paused' then
                        domoticz.notify('Svetlana info', '😴 a porszivózás szünetel ')
                    elseif Svetlana.rawData[1] == 'Sleeping' then
                        domoticz.notify('Svetlana info', '😴 A porszivó megfáradt, vidd vissza a töltőállomásra.')
                    elseif Svetlana.rawData[1] == 'Waiting' then
                        domoticz.notify('Svetlana info', '❗ A porszivó utasításra vár, vagy áramszünet van.')
                    elseif Svetlana.rawData[1] == 'In Error' then
                        domoticz.notify('Svetlana info', '❗ A porszivónak problémái vannak!')
                    end
                end
            end
        end

    -- Onderhoud-notificaties
        if Svetlana.rawData[1] == 'Back to home' then
            if domoticz.devices('Svetlana - Care Main Brush').nValue < 10 then
                domoticz.notify('Svetlana info', main_brush)
            end
            if domoticz.devices('Svetlana - Care Side Brush').nValue < 10 then
                domoticz.notify('Svetlana info', side_brush)
            end
            if domoticz.devices('Svetlana - Care Filter').nValue < 10 then
                domoticz.notify('Svetlana info', filter)
            end
            if domoticz.devices('Svetlana - Care Sensors').nValue < 15 then
                domoticz.notify('Svetlana info', sensors)
            end
        end

        -- A nap végén alaphelyzetbe áll
        if domoticz.time.matchesRule('at 23:59') then
            domoticz.variables('SvetlanaState').set(text1)
        end

	end
}
Unfortunately I can't find the error, it has worked normally so far. Would anyone help?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: roborock dzvents problem

Post by waaren »

molnaratti wrote: Wednesday 27 May 2020 19:22 I've received the following error message since the last beta update (Domoticz2020.2 (build 12086):

2020-05-27 18:27:07.780 Error: dzVents: Error: (3.0.7) An error occurred when calling event handler roborock
2020-05-27 18:27:07.780 Error: dzVents: Error: (3.0.7) /home/pi/domoticz/dzVents/runtime/Utils.lua:119: attempt to compare number with string

Unfortunately I can't find the error, it has worked normally so far. Would anyone help?
You are feeding domoticz.utils.round a string variable. Can you try again after changing line 93 from

Code: Select all

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

Code: Select all

                    local cleanspace = domoticz.utils.round(tonumber(string.gsub(string.gsub(t[5],"Cleaned area: ","")," m²","")),0)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: roborock dzvents problem

Post by molnaratti »

thanks for the reply, helped with the amendment. He was replaced by another.
Are there so many changes in the code, or is the script just not right? It's okay either, but in this case I'll stay on the stable branch.

2020-05-28 08:22:17.745 Error: dzVents: Error: (3.0.7) An error occurred when calling event handler roborock
2020-05-28 08:22:17.746 Error: dzVents: Error: (3.0.7) .../domoticz/scripts/dzVents/generated_scripts/roborock.lua:93: bad argument #2 to 'tonumber' (base out of range)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: roborock dzvents problem

Post by waaren »

molnaratti wrote: Thursday 28 May 2020 12:58 thanks for the reply, helped with the amendment. He was replaced by another.
I got the brackets wrong
can you try with

Code: Select all

local cleanspace = domoticz.utils.round((tonumber(string.gsub(string.gsub(t[5],"Cleaned area: ","")," m²",""))),0)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: roborock dzvents problem

Post by molnaratti »

I replaced it with the modified line.
Unfortunately, it doesn't work.
2020-05-29 08:07:03.639 Error: dzVents: Error: (3.0.7) An error occurred when calling event handler roborock
2020-05-29 08:07:03.639 Error: dzVents: Error: (3.0.7) .../domoticz/scripts/dzVents/generated_scripts/roborock.lua:93: bad argument #2 to 'tonumber' (base out of range)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: roborock dzvents problem

Post by waaren »

molnaratti wrote: Friday 29 May 2020 8:10 I replaced it with the modified line.
Unfortunately, it doesn't work.
2020-05-29 08:07:03.639 Error: dzVents: Error: (3.0.7) An error occurred when calling event handler roborock
2020-05-29 08:07:03.639 Error: dzVents: Error: (3.0.7) .../domoticz/scripts/dzVents/generated_scripts/roborock.lua:93: bad argument #2 to 'tonumber' (base out of range)
OK. trying a different method:
Can you try this one

Code: Select all

                    local cleanspace = math.floor(t[5]:match('[%d%.]+') + 0.5 )
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: roborock dzvents problem  [Solved]

Post by molnaratti »

You are brilliant! Works, thank you very much :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest