Python Plugin: MqttMapper

Python and python framework

Moderator: leecollings

hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

Yes I had already upgraded the git file and I'm running from the newest domoticz.

But the trick was from FlyingDomotic, it worked.
I will watch my mqtt file it sometimes changes, for now its fixed! Thanks!
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Using

Code: Select all

"item":""
means "load the full message into domoticz device". It's useful when :
  • message contains only one value, in raw format
  • message is something complex, is written "as is" into a domoticz text device, and analyzed by some LUA/dzVents script
If this worked previously, there's a (good) chance that json format/content changed.
JeroenUnimog
Posts: 1
Joined: Wednesday 29 October 2025 23:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by JeroenUnimog »

Very nice plugin!
Reading a MQTT topic with text into Domoticz works fine.
But I can´t get posting a text back into an MQTT topic to work.

MqttMapper.json:

Code: Select all

{
    "Kilometers_EX40": {
        "topic": "house/kms-rijden",
        "type": "243", "subtype":"19","switchtype":"0",
        "mapping":{"item":"svalue"},
        "set": {"topic": "house/kms-rijden/set", "payload": {"svalue":"#"}, "retain": true}
        }
}
The "set" part is not executing.
I also tried "commands" but without succes.
Any suggestions?
Regards, Jeroen
Last edited by JeroenUnimog on Wednesday 29 October 2025 23:36, edited 1 time in total.
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

FlyingDomotic wrote: Tuesday 28 October 2025 18:54 If received data is

Code: Select all

{"value":{"value": 30.0}}
then "item" should be

Code: Select all

"item": "value/value"
Sometimes MQTT Explorer shows the file this way, but sometimes is shows it without all the quotation marks, how can I sent this in Explorer of is there a setting in which I can influence the way MQTT file is written?

This causes my readout to fail
User avatar
waltervl
Posts: 6678
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

The application that writes the MQTT message defines the way the value is sent to MQTT. So you have to check that application. What application is it?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

The messages are from an ebusd application, I will check it out
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

hjzwiers wrote: Friday 31 October 2025 20:41 The messages are from an ebusd application, I will check it out
I am running it from dockge with the following file:

Code: Select all

services:
  ebusd:
    image: john30/ebusd
    container_name: ebusd
    restart: unless-stopped
    ports:
      - 8888:8888
    environment:
      EBUSD_DEVICE: ens:192.168.2.99:9999
      EBUSD_SCANCONFIG: Full
      EBUSD_MQTTHOST: 192.168.2.71
      EBUSD_MQTTPORT: "1883"
      EBUSD_CONFIGLANG: en
      EBUSD_MQTTINT: /etc/ebusd/mqtt-hassio.cfg
      EBUSD_LOGFILE: /var/log/ebusd.log
networks: {}
I added EBUSD_MQTTJSON: "" to the settings, see if it helps
Last edited by hjzwiers on Saturday 01 November 2025 0:00, edited 1 time in total.
User avatar
waltervl
Posts: 6678
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

So if ebusd sometimes sends in the message

Code: Select all

{"value":{"value": 30.0}}
and sometimes

Code: Select all

{value:{value: 30.0}}
Then this seems some bug in ebusd. Do you see this behavior on more messages coming from ebusd?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

No, but I actually only readback from ebusd.

I don't see the exact message now, but if it happens i will write it here

I've also added EBUSD_MQTTJSON: "" to the settings, don't know if that will make it more consistent
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

A message like

Code: Select all

{value:{value: 30.0}}
is definitely NOT a valid JSON message.

As said earlier in this thread, should you receive one like this, you should contact people that wrote code generating the message to ask for a valid content (probably easier to tell than to do).

If you can't fix the problem at source, you may always ask MqttMapper to write it "as is" in a Domoticz text device, and write your own LUA/dzVents script to manually decode all flavor of message.
hjzwiers
Posts: 289
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I think i fixed it with " EBUSD_MQTTJSON: "" " in the settings.

Thanks
roseen
Posts: 12
Joined: Monday 24 September 2018 16:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Stockholm, Sweden
Contact:

Re: Python Plugin: MqttMapper

Post by roseen »

I have a button (this one: https://www.tindie.com/products/plab/home-buttons/) that supports HA Autodiscover, but I haven't got it to work with the Autodiscover Gateway in Domoticz. So I decided to go bare bones and use MqttMapper instead.

However, the button sends the payload "PRESS" everytime it is pressed.
I would like to set up a switch that gets toggled everytime that message is received.

I have a config that can go from "0" to "1" when I press, but then it will be stuck in "1".
Is it even possible to configure MqttMapper to toggle the switch instead of setting a fixed value?
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

As of now, there's no toggle button on Domoticz...

However, what you can do is to create a push-on switch (which indeed is what you have) and write a small script to toggle a virtual switch.

You may eventually find help here if needed.
roseen
Posts: 12
Joined: Monday 24 September 2018 16:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Stockholm, Sweden
Contact:

Re: Python Plugin: MqttMapper

Post by roseen »

FlyingDomotic wrote: Saturday 22 November 2025 1:14 However, what you can do is to create a push-on switch (which indeed is what you have) and write a small script to toggle a virtual switch.
Yes, I was thinking of how the web API has the option to send the value "toggle" to a switch, and was hoping that the same existed in the plugin API.
https://wiki.domoticz.com/Domoticz_API/ ... tch_on/off

Can you think of a better way to do it than a curl call to the web API?
roseen
Posts: 12
Joined: Monday 24 September 2018 16:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Stockholm, Sweden
Contact:

Re: Python Plugin: MqttMapper

Post by roseen »

(If I'm spamming the topic, please say so, and I'll go ask elsewhere)

Is there a way to send a command on an incoming message?
Instead of only when the event is triggered from Domoticz?

I have something that works half way:

Code: Select all

{
        "Home Button 1": {
                "topic": "homebuttons/knapp/button_1",
                "type": "244", "subtype": "73", "switchtype": "0",
                "mapping": {"item": ""},
                "commands": {
                        "<default>": {"topic": "domoticz/in", "payload": {"command": "switchlight", "idx": 28, "switchcmd": "Toggle" }, "retain": true}
                }
        }
}
The command works nicely when I click "Home Button 1" in the Domoticz UI, toggling the switch. Now I would like it to be sent on an incoming mqtt message, basically translating from topic "homebuttons/knapp/button_1" to "domoticz/in"...
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Giving a MqttMapper push on button named "PushOn" and a virtual device named "CommandedDevice", write this dzVents script:

Code: Select all

return {
	on = {devices = {'PushOn'}},
	execute = function(domoticz, device)
	    commanded = domoticz.devices("CommandedDevice")
		if commanded.active then
		    commanded.switchOff()
		else
		    commanded.switchOn()
		end
	end
}
Commanded device state will change each time push on button is pressed.
roseen
Posts: 12
Joined: Monday 24 September 2018 16:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Stockholm, Sweden
Contact:

Re: Python Plugin: MqttMapper

Post by roseen »

FlyingDomotic wrote: Saturday 22 November 2025 14:46 Giving a MqttMapper push on button named "PushOn" and a virtual device named "CommandedDevice", write this dzVents script:
...
That one works perfectly, thanks!
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

We're never protected against chance...
NvBgm
Posts: 27
Joined: Sunday 11 August 2024 15:40
Target OS: Windows
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by NvBgm »

Can anyone help me with the MQTT Mapper?
I've installed the plugin and it works fine. Now I want to import a value from the MQTT broker, which works fine to a certain extent. The correct meter is created.
But I don't get the value; it stays at zero.
In the MQTT Explorer, I see 38 under 'Value'. The value in the MQTT Explorer isn't in JSON format. It should display it with the code below.

Code: Select all

{
    "Waterverbruik": {
        "topic": "p1monitor/watermeter/day/watermeter_consumption_liter",
		"type": "243", "subtype": "33",  "switchtype": "2",
        "mapping": { "item": "" }
    }
}
In the logfile of Domoticz i get:

MqttClient::Subscribe to [{'Topic': 'p1monitor/watermeter/day/watermeter_consumption_liter', 'QoS': 0}]

Look at the end. this is not the value i looking for.. 'QoS': 0
janpep
Posts: 288
Joined: Thursday 14 March 2024 10:11
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: MqttMapper

Post by janpep »

I found this plugin. Using cam2mqtt in docker and this plugin in Domoticz, I managed to pass "AI person detection" from my camera to Domoticz.
Thanks so much!
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest