Page 19 of 19

Re: Python Plugin: MqttMapper

Posted: Thursday 10 July 2025 16:26
by waltervl
@FlyingDomotic your help requested in this topic please viewtopic.php?p=327147#p327147
Error MQTT mapper: Duplicate xxxxxx node/key

Re: Python Plugin: MqttMapper

Posted: Thursday 10 July 2025 21:30
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"
			}
		}
	}
}

Re: Python Plugin: MqttMapper

Posted: Friday 11 July 2025 1:02
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!

Re: Python Plugin: MqttMapper

Posted: Friday 11 July 2025 9:52
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"}}
	}
}

Re: Python Plugin: MqttMapper

Posted: Friday 11 July 2025 11:23
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"
}

Re: Python Plugin: MqttMapper

Posted: Friday 11 July 2025 11:48
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.

Re: Python Plugin: MqttMapper

Posted: Friday 11 July 2025 22:23
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.

Re: Python Plugin: MqttMapper

Posted: Friday 11 July 2025 22:28
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.

Re: Python Plugin: MqttMapper

Posted: Thursday 17 July 2025 20:35
by eddieb
playing around with MqttMapper made me really happy today ...
But,
is it possible to set the device icon in the config.json file ?
same for "Protected" ?
I only found examples of some options like LevelOffHidden

Code: Select all

"options": {"SelectorStyle":"0", "LevelOffHidden": "true", "LevelNames":"Off|normal"},
but where can I find more "options"

Re: Python Plugin: MqttMapper

Posted: Thursday 17 July 2025 21:00
by FlyingDomotic
Icons have their own life in Domoticz.

Some devices (like switches) icons can be set into device parameters.

If you don't want to use default (or use a different) one, you have to do it with a script.

Here's is a script I use to change device icons for a selector:

Code: Select all

return {
	active = true,
    on = {devices = {"mySelector"}},
	execute = function(dz, item)
        local icons = {
			[0] = 140, -- Off
			[10] = 137,-- Auto
			[20] = 138,-- Manuel
			[30] = 139,-- Vide
        }
        item.setIcon(icons[item.level])
    end
}
Before creating it, you have find (or create) incons and install them into Domoticz, to get their id ("setup" > "more options" > "custom icons")

Re: Python Plugin: MqttMapper

Posted: Thursday 17 July 2025 23:00
by waltervl
You see in python plugins that the plugin author sets a specific own custom created icon that is attached to one ore more of the plugin managed devices.

So if the custom icon zip file is attached to the MQTTmapper plugin one could create some config option to add that custom icon to a MQTTmapper managed device.
See for example the omnik inverter plugin. https://github.com/sincze/Domoticz-Omni ... Web-Plugin