Thermostat Mode doesn't work anylonger?  [SOLVED]

Moderator: leecollings

zanna1972
Posts: 5
Joined: Thursday 21 January 2021 20:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Italy
Contact:

Re: Thermostat Mode doesn't work anylonger?

Post by zanna1972 »

Thanks! I ran your script and this is the result:
2021-03-09 08:19:00.274 Status: dzVents: Info: dumpAttributes: ------ Start internal script: Individua json:, trigger: "at 08:19"
2021-03-09 08:19:00.286 Status: dzVents: Debug: dumpAttributes: Processing device-adapter for Termostato bagno (Modalita): Z-Wave mode type device adapter
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): attribute -> value
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): -- dzVents
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): type, subType -> General, Thermostat Mode
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): switchTypeValue -> 0
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): adapters -> {"Z-Wave mode type device adapter"}
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): rawData -> {}
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): hwType -> OpenZWave USB, 21
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): levelNames -> nil
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes: 69: Termostato bagno (Modalita): modes -> {"Off", "Heat", "Resume"}
2021-03-09 08:19:00.286 Status: dzVents: !Info: dumpAttributes:
2021-03-09 08:19:00.286 Status: dzVents: Info: dumpAttributes: ------ Finished Individua json
2021-03-09 08:19:00.286 Error: dzVents: Error: (3.0.2) dumpAttributes: An error occurred when calling event handler Individua json
2021-03-09 08:19:00.286 Error: dzVents: Error: (3.0.2) dumpAttributes: ...icz/scripts/dzVents/generated_scripts/Individua json.lua:37: attempt to call a nil value (field 'osCommand')

As you can see there is an error when this line is executed:
local sqlResult, result = dz.utils.osCommand('sudo ' .. sqlite .. ' ' .. '-header domoticz.db "select * from deviceStatus where id = ' .. dv.idx .. '"')

Do you have some suggestion for me?

Your help is very appreciated
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Thermostat Mode doesn't work anylonger?

Post by waaren »

zanna1972 wrote: Tuesday 09 March 2021 8:22

Code: Select all

2021-03-09 08:19:00.286 Error: dzVents: Error: (3.0.2) dumpAttributes: ...icz/scripts/dzVents/generated_scripts/Individua json.lua:37: attempt to call a nil value (field 'osCommand')
Do you have some suggestion for me?
some of the functions used in the script are not yet available in your domoticz / dzVents version.

Can you try again with this one?

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 17:32', -- change to the time you want to dump the attributes of the device
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'dumpAttributes',
    },

    execute = function(dz)
        local myDevice = dz.devices(1656)         -- your device idx
        
        -- if you don't have sqlite3 yet on your system install it with sudo apt install sqlite3
        local sqlite = '/usr/local/bin/sqlite3'  -- find your sqlite3 location with "which sqlite3" and change here accordingl
               
		local function osCommand(cmd)
			local file = assert ( io.popen(cmd) )
			local output = assert ( file:read('*all') )
			local rc = { file:close() }
			return output, rc[3]
		end
		
		local function stringSplit(text, sep, convertNumber, convertNil)
			if not(text) then return {} end
			local sep = sep or '%s'
			local include = '+'
			if convertNil then include = '*' end
			local t = {}
			for str in string.gmatch(text, "([^" ..sep.. "]" .. include .. ")" ) do
				if convertNil and str == '' then str = convertNil end
				table.insert(t, ( convertNumber and tonumber(str) ) or str)
			end
			return t
		end

        local function dumpAttributes(dv)
            dz.log(dv.idx .. ': ' .. dv.name .. ': attribute       -> value',dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ':                                    -- dzVents',dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': type, subType   -> ' .. dv.deviceType .. ', '.. tostring(dv.deviceSubType),dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': switchTypeValue -> ' .. dv.switchTypeValue ,dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': adapters        -> ' .. dz.utils._.str(dv._adapters),dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': rawData         -> ' .. dz.utils._.str(dv.rawData),dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': hwType          -> ' .. dv.hardwareType .. ', ' .. dv.hardwareTypeValue,dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': levelNames      -> ' .. dz.utils._.str(dv.levelNames),dz.LOG_FORCE)
            dz.log(dv.idx .. ': ' .. dv.name .. ': modes           -> ' .. dz.utils._.str(dv.modes),dz.LOG_FORCE)
        end

        local function dumpDeviceStatus(dv)
            local sqlResult, result = osCommand('sudo ' .. sqlite .. ' ' .. '-header domoticz.db "select * from deviceStatus where id = ' .. dv.idx .. '"')
            if result ~= 0 then 
                dz.log('Result: ' .. result, dz.LOG_ERROR)
            else
                sqlResult = stringSplit(sqlResult,'\n')
                local header = stringSplit(sqlResult[1],'|')
                local values = stringSplit(sqlResult[2],'|')
                dz.log(dv.idx .. ': ' .. dv.name .. ': field           -> value',dz.LOG_FORCE)
                dz.log(dv.idx .. ': ' .. dv.name .. ':                                    -- database',dz.LOG_FORCE)
                for index, attribute in ipairs(header) do
                    dz.log(dv.idx .. ': ' .. dv.name .. ': ' .. dz.utils.rightPad(( attribute or '') ,15) .. ' -> ' .. ( values[index] or 'nil') ,dz.LOG_FORCE)
                end
            end
        end

        dumpAttributes(myDevice)
            dz.log('',dz.LOG_FORCE)
        dumpDeviceStatus(myDevice)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
zanna1972
Posts: 5
Joined: Thursday 21 January 2021 20:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Italy
Contact:

Re: Thermostat Mode doesn't work anylonger?

Post by zanna1972 »

Solved the problem following your suggestion.
Thanks a lot, very appreciated.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest