Page 1 of 1

MQTT Discovery: get Hardware ID

Posted: Saturday 02 April 2022 9:35
by hestia
Is there any direct way to get the Hardware ID for MQTT Discovery devices with DzVents in order to get the idx (I didn't find the field in DzVents)
Screenshot 2022-04-02 092007.png
Screenshot 2022-04-02 092007.png (31.59 KiB) Viewed 1176 times
I'm currently do it by SQL but maybe not the best way...
The use case is to get the Idx from the MQTT topic (zwavejs2mqtt -> mqtt -> NodeRED -> MQTT -> Dz)
I'm doing this

Code: Select all

local function selectTableDeviceStatus (p_id)
    local _,rc = _u.osCommand('which sqlite3')

    if rc == 0 then
        local f_cmd, f_result
            f_cmd = 'sudo sqlite3  -list -noheader domoticz.db "SELECT ID FROM DeviceStatus WHERE HardwareID = 31 and Used = 1 and Type = 244 and DeviceID LIKE \'' .. p_id .. '%\' ;" '
            f_result = _u.osCommand(f_cmd)
             
            --logWrite(f_cmd)
            --logWrite(f_result)

            f_result = tonumber(f_result)
            if f_result == nil then
                logWrite('selectTableDeviceStatus ' .. p_id .. ' no DeviceID', dz.LOG_ERROR)
                return -1
            else
                logWrite('selectTableDeviceStatus ' .. p_id .. ' ' .. f_result, dz.LOG_DEBUG)
                return f_result
            end
    else
        logWrite(p_table .. ' sqlite3 not available. Please make sure it is installed (sudo apt install sqlite3) and accessible', dz.LOG_ERROR)
        return -1
    end
end
(p_id = 'zwavejs2mqtt_0xe236465e_11-37-0-currentValue' for instance)

Re: MQTT Discovery: get Hardware ID

Posted: Saturday 02 April 2022 9:49
by jvdz
Did you try to call the Domoticz API: IP:port/json.htm?type=devices&rid=IDX
.. and check field ID?

Re: MQTT Discovery: get Hardware ID

Posted: Saturday 02 April 2022 13:05
by hestia
Yes, it is the field.
My purpose is to get the idx (1975) from the ID (zwavejs2mqtt_0xe236465e_11-37-0-currentValue), not the reverse...

Re: MQTT Discovery: get Hardware ID

Posted: Saturday 02 April 2022 14:57
by jvdz
One way would be to do an API call : http://localhost:8080/json.htm?type=devices&used=true
and loop through the returned devices matching the ID's with the one you are searching.

Re: MQTT Discovery: get Hardware ID

Posted: Saturday 02 April 2022 21:03
by hestia
Ok,
I think I'll keep my sql request if nothing out of the box

Code: Select all

SELECT ID FROM DeviceStatus WHERE HardwareID = 31 and Used = 1 and Type = 244 and DeviceID LIKE \'' .. p_id .. '%\'
Thanks again