Python Plugin: MqttMapper

Python and python framework

Moderator: leecollings

Post Reply
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Concerning baro, there's a temperature/humidity/barometer device, with type=84 and sybtype=1.

If you have access to ESP code, and can make a unique json message like

Code: Select all

{"druck":1014, "eco2":500,  "error": 0, "iaqAC":0, "luftfeuchte":59.31, "temperatur":19.81, "voc":0}
then you can easily get data with

Code: Select all

"BME680 Temp": {
	"topic": "BME680_01",
	"key": "BME680_01-temperature",
	"type": "84", "subtype":"1",
	"mapping":{"item":"temperatur;humidity;0;druck;0"}
},
"BME680 Iaq": {
	"topic": "BME680_01",
	"key": "BME680_01-iaq",
	"type": "249", "subtype":"1",
	"mapping":{"item":"iaq"}
}
If it's not possible to make a json complete message, then a small change in plugin will be done to allow putting multiple different topics in one device.
User avatar
waltervl
Posts: 5155
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

For humidity you need to supply 2 values: HUM and HUM status. See https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

You're right ! That's why humidity is followed by a 0 (which in fact should be entered as ~0).

In the same spirit, baro should be followed by tendency.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

In case it's not possible to get all data in one JSON message, I made a change to allow inserting full message content specifying ~* in a multiple item sValue.

In your case, after updating to new plugin version, you can try:

Code: Select all

{
	"BME680 Temperature": {
		"topic": "BME680_01/temperatur",
		"key": "BME680_Temp",
		"type": "84", "subtype":"1",
		"mapping":{"item":"~*;~;~;~;~"},
		"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
	},
	"BME680 Humidity": {
		"topic": "BME680_01/humidity",
		"key": "BME680_Temp",
		"type": "84", "subtype":"1",
		"mapping":{"item":"~;~*;~0;~;~"},
		"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
	},
	"BME680 Pressure": {
		"topic": "BME680_01/druck",
		"key": "BME680_Temp",
		"type": "84", "subtype":"1",
		"mapping":{"item":"~;~;~;~*;~0"},
		"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
	},
	"BME680 Iaq": {
		"topic": "BME680_01/iaq",
		"type": "249", "subtype":"1",
		"mapping":{"item":""}
	}
}
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

Thanks for your reply. I have used your json file from above and got the follwing result. Not really what I exprected because Temperature and Barometer values passed away and Hunidity stay 0. I intend to get four devices in domoticz for temperatur/pressure/humidity/iaq ... if possible. The remaining values like CO2, Iaq accuracy and VOC will follow later on when I understand how to configure the json file
Attachments
Temp-Baro-Humidity.JPG
Temp-Baro-Humidity.JPG (18.07 KiB) Viewed 1038 times
Iaq.JPG
Iaq.JPG (15.12 KiB) Viewed 1038 times
devices.JPG
devices.JPG (21.12 KiB) Viewed 1038 times
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

The way it is setup, there's one device for temperature/humidity/pressure. If you really wish to have 3 different devices, that's another configuration (in fact, your original configuration, taking care of not naming 2 devices identically "BME680 Feuchte").

If you want to keep one device for temperature/humidity/pressure, I made an error in humidity topic name in configuration file. Replace:

Code: Select all

"topic": "BME680_01/humidity",
by:

Code: Select all

"topic": "BME680_01/luftfeuchte",
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

I followed your advice and changed the topic. Sorry to say that nothing has changed.
devices.JPG
devices.JPG (20.19 KiB) Viewed 1017 times
However I have access to the Arduino sketch where the topics are send to the Mqtt broker but I do not understand how to send all data with one json command as recommended.

client.publish(temp_topic, String(temp).c_str(), true);
client.publish(hum_topic, String(hum).c_str(), true);
client.publish(druck_topic, String(druck).c_str(), true);
client.publish(iaq_topic, String(IAQ).c_str(), true);
client.publish(iaq_ac_topic, String(IAQac).c_str(), true);
client.publish(eco2_topic, String(eCO2).c_str(), true);
client.publish(voc_topic, String(voc).c_str(), true);
Mqtt Explorer.JPG
Mqtt Explorer.JPG (8.91 KiB) Viewed 1017 times
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Strange ....

I made a test with the following configuration file:

Code: Select all

{
	"BME680 Temperature": {
		"topic": "BME680_01/temperatur",
		"key": "BME680_Temp",
		"type": "84", "subtype":"1",
		"mapping":{"item":"~*;~;~;~;~"},
		"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
	},
	"BME680 Humidity": {
		"topic": "BME680_01/luftfeuchte",
		"key": "BME680_Temp",
		"type": "84", "subtype":"1",
		"mapping":{"item":"~;~*;~0;~;~"},
		"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
	},
	"BME680 Pressure": {
		"topic": "BME680_01/druck",
		"key": "BME680_Temp",
		"type": "84", "subtype":"1",
		"mapping":{"item":"~;~;~;~*;~0"},
		"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
	},
	"BME680 Iaq": {
		"topic": "BME680_01/iaq",
		"type": "249", "subtype":"1",
		"mapping":{"item":""}
	}
}
I sent the following MQTT messages and saw devices like:
Sans titre.png
Sans titre.png (35.74 KiB) Viewed 997 times
Are you sure you sure:
1) you have exactly the same settings as me?
2) MQTT is properlly updated?

Concerning changes to code, this is not mandatory anymore, since last changes. However, should you really want to do this, I can give you the lines to add.
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

Sorry to say, no changes at all. I am running domoticz on a Rpi3 with bullseye. Domoticz Version is 2024.4 and Mosquitto is 2.0.11. In any case I have deleted the Mqttmapper plugin and reinstalled again to be sure that this is not an issue.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Would it be possible to check (with MQTT EXplorer for example), that you properly receive updates for these topics (in particular, for temp/humidity/pressure) ?
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

Yes Mqtt explorer is responding well. I have changed the the json file again and get this result. Barometer does't appear in the Domoticz Gui
devices.JPG
devices.JPG (34.6 KiB) Viewed 986 times
values.JPG
values.JPG (17.74 KiB) Viewed 986 times
{
"BME680 Temperature": {
"topic": "BME680_01/temperatur",
"key": "BME680_Temp",
"type": "84", "subtype":"1",
"mapping":{"item":"~*;~;~;~;~"},
"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
},
"BME680 Humidity": {
"topic": "BME680_01/luftfeuchte",
"key": "BME680_Temp",
"type": "84", "subtype":"1",
"mapping":{"item":"~;~*;~0;~;~"},
"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
},
"BME680 Pressure": {
"topic": "BME680_01/druck",
"key": "BME680_Temp",
"type": "84", "subtype":"1",
"mapping":{"item":"~;~;~;~*;~0"},
"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
},
"BME680 Temp": {
"topic": "BME680_01/temperatur",
"type": "80", "subtype": "5", "switchtype": "0",
"mapping": {"item": ""}
},
"BME680 Baro": {
"topic": "BME680_01/druck",
"type": "243", "subtype": "26", "switchtype": "0",
"mapping": {"item": ""}
},
"BME680 Iaq": {
"topic": "BME680_01/iaq",
"type": "249", "subtype":"1",
"mapping":{"item":""}
}
}
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Do you have any errors in Domoticz log?
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Did you also update to last version (file /home/pi/domoticz/plugins/MqttMapper/plugin.py version should be "1.0.25"?

If not, go to /home/pi/domoticz/plugins/MqttMapper/ and enter "git pull"
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

If you prefer having 4 different devices (temperature, humidity, pressure and voc), then load last version (1.0.26) of plugin and use the following configuration file:

Code: Select all

{
	"BME680 Temp": {
		"topic": "BME680_01/temperatur",
		"type": "80", "subtype": "5",
		"mapping": {"item": ""}
	},
	"BME680 Humidity": {
		"topic": "BME680_01/luftfeuchte",
		"type": "81", "subtype": "1",
		"mapping": {"item": ""},
		"initial" : {"nvalue":0, "svalue": "0"}
	},
	"BME680 Baro": {
		"topic": "BME680_01/druck",
		"type": "243", "subtype": "26",
		"mapping": {"item": "~*;~0"},
		"initial" : {"svalue": "0;0"}
	},
	"BME680 Iaq": {
		"topic": "BME680_01/iaq",
		"type": "249", "subtype":"1",
		"mapping":{"item":""}
	}
}
FYI, humidity was not updated due to the fact that standalone humidity sensor need an integer value in nValue while other sensors accept float values in sValue. And your device returns a float value, not compatible with humidity sensor. I made a change in 1.0.26 to round float value in this case.
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

I can report improvements on the latest version. Thanks a lot for your initiativ. I prefer to have different devices from this topic because I need the sensor accuracy and error value as well. I had no time to test it but I will come back on this. Pls. continue your work because the missing interface between the mqtt broker and Domoticz is a big disatvantage.
devices.JPG
devices.JPG (34.28 KiB) Viewed 948 times
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

I have tested your json file. The Baro device is not visible in the Domoticz GUI using the type 243 with subtype 26. When is switch to 243 / 9 it's visible but with bar as measuring unit. Why do we have Humidity in the value field? What can we do with the CO2 and VOC values?
devices.JPG
devices.JPG (36.71 KiB) Viewed 920 times
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Baro is shown in "Weather" tab, not in "Utility", with "type 243 with subtype 26".
thaui
Posts: 58
Joined: Sunday 15 March 2015 19:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Hamburg
Contact:

Re: Python Plugin: MqttMapper

Post by thaui »

I have not found out the logic with "mapping" and "Initial". Read several time the github description but found no way to reconfigure the numbers to show Temperature & Humidity with Type 82. What I am missing?

"BME680 Temperature": {
"topic": "BME680_01/temperatur",
"key": "BME680_Temp",
"type": "82", "subtype":"1",
"mapping":{"item":"~*;~;~;~;~"},
"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
},
"BME680 Humidity": {
"topic": "BME680_01/luftfeuchte",
"key": "BME680_Temp",
"type": "82", "subtype":"1",
"mapping":{"item":"~;~*;~0;~;~"},
"initial":{"nvalue":0, "svalue":"0;0;0;0;0"}
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

"Mapping" indicates how to load MQTT data into Domoticz sValue, while "initial" give (initial) nValue and sValue when device is created, before any MQTT value is read.

Configuration you gave should work. You may perhaps delete "BME680_Temp" device, and restart MqttMapper plugin (or Domoticz).

Ensure you have last version of plugin (by "git pull" when in MqttMapper plugin folder (something like /home/pi/domoticz/plugins/MqttMapper/)
hjzwiers
Posts: 163
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I have the two temperatures from MQTT.

I have a question how to get a boolean from the file?

I tried using general but failed, so the variable "topic": "ebusd/global/running" is a boolean

"T_Outside": {
"topic": "ebusd/broadcast/outsidetemp",
"type": "80", "subtype": "5", "switchtype": "0",
"mapping": {"item": "", "multiplier": 0.1}
},

"T_Living": {
"topic": "ebusd/ctlv2/z1RoomTemp",
"type": "80", "subtype": "5", "switchtype": "0",
"mapping": {"item": "", "multiplier": 0.1}
},

"MQTTrunning": {
"topic": "ebusd/global/running",
"type": "243", "subtype": "19", "switchtype": "0",
"mapping": {"item": ""}
}

}
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest