Page 1 of 1

Z-Wave MQTT question

Posted: Tuesday 04 May 2021 10:46
by mgugu
Hello,
I use a web services unit written in node js to centralise common actions of my different domoticz servers.
I need to collect all devices data including idx and node Id when relevant, for that I use mqtt messages delivered by the domoticz servers.
The question concerns the case of zwave devices for which I need to get the node Id for further actions.
I have a Qubino switch including also a thermal sensor, so I get 2 devices sharing the same node Id:
For the switch I get the following mqtt message:

Code: Select all

"dtype" : "Light/Switch",
"hwid" : "7",
"id" : "00004701",
"idx" : 1149,
and for the sensor:

Code: Select all

"dtype" : "Temp",
"hwid" : "7",
"id" : "18177",
"idx" : 1152,
For the switch the node Id is encapsulated in the id field: 47 is the hexa coded node Id
But for the sensor this is is something different, id = 18177 which is the hexa to decimal coded value of 4701
Does somebody know what is the logic behind ?
Thx in advance

Re: Z-Wave MQTT question

Posted: Tuesday 04 May 2021 11:12
by waltervl

Re: Z-Wave MQTT question

Posted: Tuesday 04 May 2021 11:26
by mgugu
Thank you waltervl for the reference. Things are OK for me regarding the domoticz/devices panel since the node Id is coded coherently (4701).
But this is not reflected by the mqtt message in which the node Id is not coded accordingly.

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 12:23
by waltervl
What is the device id of the temp sensor in the device list?
I think you will have to relate that id to the id sent by MQTT (hex translation?)

From https://www.domoticz.com/wiki/Zwave#Z-W ... n_Domoticz
Domoticz DeviceID = 00 00 NODEID INSTANCEID. If this is for example Node 18 (hex 0x12) the ID could be 00 00 12 02.

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 13:11
by mgugu
waltervl wrote: Wednesday 05 May 2021 12:23 What is the device id of the temp sensor in the device list?
The id in device list is 4701, but via MQTT it becomes 18177 which is the decimal conversion of 4701.
OK, it is easy to back convert it but the problem is that the conversion made by MQTT is not systematic for all nodes as is shown in my first examples.
The question is how do I know if I have to back convert or not ?

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 13:24
by waltervl
Strange, I would expect something like 00004702 instead of 4701 as the other device of that node is called 00004701

And what ID is http://DomoIP:DomoPort/json.htm?type=devices&rid=IDX giving when entering both device IDX's?
Result should include following example result:

Code: Select all

	"result": [
		{
			"AddjMulti": 1,
			"AddjMulti2": 1,
			"AddjValue": 0,
			"AddjValue2": 0,
			"BatteryLevel": 255,
			"CustomImage": 0,
			"Data": "On",
			"Description": "Plain text",
			"DimmerType": "none",
			"Favorite": 0,
			"HardwareDisabled": false,
			"HardwareID": 3,
			"HardwareName": "virtual",
			"HardwareType": "Dummy (Does nothing, use for virtual switches only)",
			"HardwareTypeVal": 15,
			"HaveDimmer": true,
			"HaveGroupCmd": true,
			"HaveTimeout": false,
==>			"ID": "00014052",  
			"Image": "Light",
			"IsSubDevice": false,
			"LastUpdate": "2021-02-10 22:47:03",
			"Level": 0,
			"LevelInt": 0,
			"MaxDimLevel": 100,
			"Name": "mySwitch",
			"Notifications": "false",
			"PlanID": "0",
			"PlanIDs": [
				0
			],
			"Protected": false,
			"ShowNotifications": true,
			"SignalLevel": "-",
			"Status": "On",
			"StrParam1": "",
			"StrParam2": "",
			"SubType": "Switch",
			"SwitchType": "On/Off",
			"SwitchTypeVal": 0,
			"Timers": "false",
			"Type": "Light/Switch",
			"TypeImg": "lightbulb",
			"Unit": 1,
			"Used": 1,
			"UsedByCamera": false,
			"User": "Admin (IP: 192.168.192.41)",
			"XOffset": "0",
			"YOffset": "0",
			"idx": "2"
		}
	],

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 14:03
by mgugu
From a JSON point of view, everything is OK:

Code: Select all

{
	"HardwareID" : 7,
	"HardwareName" : "OpenZwave",
	"HardwareType" : "OpenZWave USB",
	"HardwareTypeVal" : 21,
	"HaveTimeout" : false,
	"ID" : "4701",
But trough MQTT I get

Code: Select all

	"dtype" : "Temp",
	"hwid" : "7",
	"id" : "18177",
	"idx" : 1152,
18177 is decimal conversion of 4701
and for dependent zwave device (same node Id) I get:

Code: Select all

	"dtype" : "Light/Switch",
	"hwid" : "7",
	"id" : "00004701",
	"idx" : 1149,
Which is correct
Looks like some mess!

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 18:23
by waltervl
mgugu wrote: Wednesday 05 May 2021 14:03 From a JSON point of view, everything is OK:

Code: Select all

{
	"HardwareID" : 7,
	"HardwareName" : "OpenZwave",
	"HardwareType" : "OpenZWave USB",
	"HardwareTypeVal" : 21,
	"HaveTimeout" : false,
	"ID" : "4701",
This is not completely what I asked
Can you please give the full outcome of
http://DomoIP:DomoPort/json.htm?type=devices&rid=1149
and
http://DomoIP:DomoPort/json.htm?type=devices&rid=1152

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 19:12
by mgugu
Yep:

Code: Select all

{
	"ActTime" : 1620234472,
	"AstrTwilightEnd" : "23:31",
	"AstrTwilightStart" : "04:07",
	"CivTwilightEnd" : "21:49",
	"CivTwilightStart" : "05:49",
	"DayLength" : "14:48",
	"NautTwilightEnd" : "22:36",
	"NautTwilightStart" : "05:02",
	"ServerTime" : "2021-05-05 19:07:52",
	"SunAtSouth" : "13:49",
	"Sunrise" : "06:25",
	"Sunset" : "21:13",
	"app_version" : "2021.1 (build 13243)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 15,
			"Data" : "Off",
			"Description" : "",
			"DimmerType" : "none",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 7,
			"HardwareName" : "OpenZwave",
			"HardwareType" : "OpenZWave USB",
			"HardwareTypeVal" : 21,
			"HaveDimmer" : true,
			"HaveGroupCmd" : true,
			"HaveTimeout" : false,
			"ID" : "00004701",
			"Image" : "Heating",
			"IsSubDevice" : false,
			"LastUpdate" : "2021-05-05 19:00:01",
			"Level" : 0,
			"LevelInt" : 0,
			"MaxDimLevel" : 100,
			"Name" : "Confort",
			"Notifications" : "false",
			"PlanID" : "9",
			"PlanIDs" : 
			[
				9
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"Status" : "Off",
			"StrParam1" : "",
			"StrParam2" : "",
			"SubType" : "Switch",
			"SwitchType" : "On/Off",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "Light/Switch",
			"TypeImg" : "lightbulb",
			"Unit" : 1,
			"Used" : 1,
			"UsedByCamera" : false,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "1149"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Code: Select all

{
	"ActTime" : 1620234546,
	"AstrTwilightEnd" : "23:31",
	"AstrTwilightStart" : "04:07",
	"CivTwilightEnd" : "21:49",
	"CivTwilightStart" : "05:49",
	"DayLength" : "14:48",
	"NautTwilightEnd" : "22:36",
	"NautTwilightStart" : "05:02",
	"ServerTime" : "2021-05-05 19:09:06",
	"SunAtSouth" : "13:49",
	"Sunrise" : "06:25",
	"Sunset" : "21:13",
	"app_version" : "2021.1 (build 13243)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 0,
			"Data" : "21.2 C",
			"Description" : "",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 7,
			"HardwareName" : "OpenZwave",
			"HardwareType" : "OpenZWave USB",
			"HardwareTypeVal" : 21,
			"HaveTimeout" : false,
			"ID" : "4701",
			"LastUpdate" : "2021-05-05 19:08:03",
			"Name" : "T\u00b0RdC2",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "LaCrosse TX3",
			"Temp" : 21.199999999999999,
			"Timers" : "false",
			"Type" : "Temp",
			"TypeImg" : "temperature",
			"Unit" : 1,
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "1152",
			"trend" : 3
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 19:29
by waltervl
Nice, yes you would expect that MQTT would send the text ID's "4701" and "00004701" belonging to the devices, but it does not.
I was hoping you interpreted something wrong but you did not ..... :-)
So I hope someone passes by that can enlighten this unexpected behavior. According the MQTT wiki page it should be similar as the API/Json but it is not for the ID field.
Else check the MQTT source code on github....

Re: Z-Wave MQTT question

Posted: Wednesday 05 May 2021 23:37
by waaren
mgugu wrote: Tuesday 04 May 2021 10:46 Does somebody know what is the logic behind ?
I don't completely understand the logic behind it (Zwave is too complicated for me) but let me try to explain what I understand from what is causing this.

MQTT just sends the DeviceID it finds in that field in the domoticz database in table DeviceStatus.

The /json.htm?type=devices&rid=1149 and other type=devices json calls (which are also used to build the page of the devices tab) apply some logic to the DeviceID if the device is Zwave. It does conditional magic based on the value having leading zero's or not.

Below the code snippet from WebServer.cpp starting at line 9531

Code: Select all

#ifdef WITH_OPENZWAVE
						if (pHardware != nullptr)
						{
							if (pHardware->HwdType == HTYPE_OpenZWave)
							{
								COpenZWave *pZWave = reinterpret_cast<COpenZWave*>(pHardware);
								unsigned long ID;
								std::stringstream s_strid;
								s_strid << std::hex << sd[1];
								s_strid >> ID;
								int nodeID = (ID & 0x0000FF00) >> 8;
								bHaveTimeout = pZWave->HasNodeFailed(nodeID);
							}
						}
#endif

Re: Z-Wave MQTT question

Posted: Thursday 06 May 2021 0:07
by mgugu
OK so the conclusion at the moment is that we cannot rely on MQTT as far as node Id is concerned, only JSON provide reliable results.
I would suggest to developper to harmonize all that in a future release.
Anyway thank you very much Walter and Waaren for spending time on my question.

Re: Z-Wave MQTT question

Posted: Thursday 06 May 2021 0:24
by waaren
mgugu wrote: Thursday 06 May 2021 0:07 I would suggest to developer to harmonize all that in a future release.
Created issue 4814

Re: Z-Wave MQTT question

Posted: Thursday 06 May 2021 7:38
by waltervl
Thank you @waaren!

Re: Z-Wave MQTT question

Posted: Thursday 06 May 2021 16:51
by waaren
mgugu wrote: Thursday 06 May 2021 0:07 I would suggest to developer to harmonize all that in a future release.
@gizmocuz picked up your suggestion. Can you please check build >= 13251 and post your findings on github (issue 4814) ?

Re: Z-Wave MQTT question

Posted: Friday 07 May 2021 1:03
by mgugu
Everyhing is OK now with build 13251. MQTT reflects JSON output regarding Zwave node Id.
Thank you @gizmocuz and @rwaaren for this very quick problem resolution