Python Plugin: MqttMapper

Python and python framework

Moderator: leecollings

User avatar
waltervl
Posts: 5886
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

@FlyingDomotic your help requested in this topic please viewtopic.php?p=327147#p327147
Error MQTT mapper: Duplicate xxxxxx node/key
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Varazir
Posts: 445
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: MqttMapper

Post by Varazir »

Is it just me or more who get confused with the mix of English and French?
It would better to have 2 different readme files.

Second it's hard to follow when we don't have an source output from MQTT.
So you can see how the source looks like and how the JSON output looks like.


I'm thinking using this mod along with What's up Docker MQTT integration,
this is the JSON payload https://gist.github.com/varazir/ecac2f5 ... 2a09cfc057

How it looks like in MQTT Explorer
Image

I'm not sure what to do but something like this

Code: Select all

{
	"Dockge Status": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"type": "244",
		"subtype": "73",
		"switchtype": "11",
		"mapping": {
			"item": "status",
			"default": "1",
			"values": {
				"close": "0"
			}
		}
	},
	"Dockge Update": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"type": "244",
		"subtype": "73",
		"switchtype": "11",
		"mapping": {
			"item": "update_available",
			"default": "false",
			"values": {
				"close": "0"
			}
		}
	}
}
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
FlyingDomotic
Posts: 388
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

waltervl wrote: Thursday 10 July 2025 16:26 @FlyingDomotic your help requested in this topic please viewtopic.php?p=327147#p327147
Error MQTT mapper: Duplicate xxxxxx node/key
Fixed!
FlyingDomotic
Posts: 388
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Varazir wrote: Thursday 10 July 2025 21:30 Is it just me or more who get confused with the mix of English and French?
It would better to have 2 different readme files.

Second it's hard to follow when we don't have an source output from MQTT.
So you can see how the source looks like and how the JSON output looks like.


I'm thinking using this mod along with What's up Docker MQTT integration,
this is the JSON payload https://gist.github.com/varazir/ecac2f5 ... 2a09cfc057

How it looks like in MQTT Explorer
Image

I'm not sure what to do but something like this

Code: Select all

{
	"Dockge Status": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"type": "244",
		"subtype": "73",
		"switchtype": "11",
		"mapping": {
			"item": "status",
			"default": "1",
			"values": {
				"close": "0"
			}
		}
	},
	"Dockge Update": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"type": "244",
		"subtype": "73",
		"switchtype": "11",
		"mapping": {
			"item": "update_available",
			"default": "false",
			"values": {
				"close": "0"
			}
		}
	}
}
Analysis is good.

The only thing that won't work is mapping default and values.

Default value is related to Domoticz device. Here, 244/73/11 is a door switch, having internally 2 values (as per https://wiki.domoticz.com/Developing_a_ ... vice_Types): "Statuses: Open: nValue = 1, Closed: nValue = 0).

So default should be either 0 or 1.

Concerning mapping values, first part of each item is MQTT message content.

So, for "Dockge Status", which seems to have a "status": "running", you should write something like "default": 0, "values": {"running": 1}

For "Dockge Update", which seems false or true, you may write ("default": 1, values: {"false": 0}

An additional remark: You have the same topic more than once (here "wud/container/docker/dockge-dockge-1"). You avoid a duplicate error message, it's a good practice to add a "key" item, that should be unique into file, and probably significant for you.

Here is an example of file that may work:

Code: Select all

{
	"Dockge Status": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"key": "wud/container/docker/dockge-dockge-1-status",
		"type": "244", "subtype": "73", "switchtype": "11",
		"mapping": {"item": "status", "default": "0", "values": {"running": "1"}}
	},
	"Dockge Update": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"key": "wud/container/docker/dockge-dockge-1-update",
		"type": "244", "subtype": "73", "switchtype": "11",
		"mapping": {"item": "update_available", "default": "1", "values": {"false": "0"}}
	}
}
User avatar
Varazir
Posts: 445
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: MqttMapper

Post by Varazir »

FlyingDomotic wrote: Friday 11 July 2025 9:52
Analysis is good.

The only thing that won't work is mapping default and values.

Default value is related to Domoticz device. Here, 244/73/11 is a door switch, having internally 2 values (as per https://wiki.domoticz.com/Developing_a_ ... vice_Types): "Statuses: Open: nValue = 1, Closed: nValue = 0).

So default should be either 0 or 1.

Concerning mapping values, first part of each item is MQTT message content.

So, for "Dockge Status", which seems to have a "status": "running", you should write something like "default": 0, "values": {"running": 1}

For "Dockge Update", which seems false or true, you may write ("default": 1, values: {"false": 0}

An additional remark: You have the same topic more than once (here "wud/container/docker/dockge-dockge-1"). You avoid a duplicate error message, it's a good practice to add a "key" item, that should be unique into file, and probably significant for you.

Here is an example of file that may work:

Code: Select all

{
	"Dockge Status": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"key": "wud/container/docker/dockge-dockge-1-status",
		"type": "244", "subtype": "73", "switchtype": "11",
		"mapping": {"item": "status", "default": "0", "values": {"running": "1"}}
	},
	"Dockge Update": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"key": "wud/container/docker/dockge-dockge-1-update",
		"type": "244", "subtype": "73", "switchtype": "11",
		"mapping": {"item": "update_available", "default": "1", "values": {"false": "0"}}
	}
}
Thanks then I understand better,
The example worked, I need to fix the device I want, wasn't the correct one.

so Item = JSON key, correct ?
What happens if you have more then one of the same key ? lets say like this ?

Code: Select all

{
	"status": "On",
	"running": {
		"status": "Running"
	}
}
"default" is just what you use, nothing to do with the source data, and "values" used to match the value of the key,

So I could have something like this:

Code: Select all

"values":  {
         "false": "0",
          "true": "1"
}
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
Varazir
Posts: 445
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: MqttMapper

Post by Varazir »

This worked as I liked, now I just need to add the others but it's copy and paste, change the name of the array, topic and key

Code: Select all

{
	"Dockge Status": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"key": "wud/container/docker/dockge-dockge-1-status",
		"type": "244",
		"subtype": "73",
		"switchtype": "0",
		"mapping": {
			"item": "status",
			"default": "0",
			"values": {
				"running": "100"
			}
		}
	},
	"Dockge Update": {
		"topic": "wud/container/docker/dockge-dockge-1",
		"key": "wud/container/docker/dockge-dockge-1-update",
		"type": "244",
		"subtype": "73",
		"switchtype": "0",
		"mapping": {
			"item": "update_available",
			"default": "0",
			"values": {
				"false": "0",
				"true": "100"
			}
		}
	}
}
I see it picks up the name of the HW I have set on the name device, something I can change ?
Image

Would be cool if I could define the icon's I like to use as well.
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
FlyingDomotic
Posts: 388
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Varazir wrote: Friday 11 July 2025 11:23 What happens if you have more then one of the same key ? lets say like this ?

Code: Select all

{
	"status": "On",
	"running": {
		"status": "Running"
	}
}
First one "status": "On" is "item": "status", second one "status": "Running" is "item": "running/status"
Varazir wrote: Friday 11 July 2025 11:23 "default" is just what you use, nothing to do with the source data, and "values" used to match the value of the key,

So I could have something like this:

Code: Select all

"values": {
"false": "0",
"true": "1"
}
Default is "if all else fails value", meaning that if item value can be selected into "values", we'll use this default value without sending error.

If there's no default value and item value can't be found into "values", MqttMapper will send an error and not update device.
FlyingDomotic
Posts: 388
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Varazir wrote: Friday 11 July 2025 11:48
I see it picks up the name of the HW I have set on the name device, something I can change ?
Image

Would be cool if I could define the icon's I like to use as well.
Icons that can be changed (meaning not forced by Domoticz like temperature) are generic to any Domoticz device.

You may change them after creating device using "Modify" button, and changing icon. Procedure is not linked to MqttMapper.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest