MQTT Discovery: get Hardware ID Topic is solved

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

Post Reply
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

MQTT Discovery: get Hardware ID

Post 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 1163 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)
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Discovery: get Hardware ID

Post by jvdz »

Did you try to call the Domoticz API: IP:port/json.htm?type=devices&rid=IDX
.. and check field ID?
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: MQTT Discovery: get Hardware ID

Post 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...
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Discovery: get Hardware ID

Post 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.
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: MQTT Discovery: get Hardware ID

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest