So, if I correctly understood, value loaded into device "MQTT mapper - T_Outside" is correct. right?
Is there another help we may provide to you?
Python Plugin: MqttMapper
Moderator: leecollings
-
- Posts: 356
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
-
- Posts: 242
- Joined: Friday 12 January 2018 8:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: MqttMapper
Yes, it is correct!
I only wonder how to convert this value to a valid temperature, including if the value is different as I had observed earlier.
I only wonder how to convert this value to a valid temperature, including if the value is different as I had observed earlier.
-
- Posts: 356
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Python Plugin: MqttMapper
First of all, you have to check that virtual device plug-in is loaded into Domoticz:
In the popup windows, give a device name (like "Outside temperature") and set "Sensor type" to "Temperature", then click on "Ok"
Congrats, you've just created a brand new virtual temperature sensor!
Now, goto "Setup/More options/Events", click on "+/LUA/device".
In the script windows, you'll see something like:
Select everything and replace text by:
You may change script name from "Script #1" to something like "Outside temperature".
To save the script, click on "Save".
You can then test that any change made in "MQTT mapper - T_Outside" is properly extracted and reflected into "Outside temperature".
FYI, string.match will return every "0" to "9" and "." characters from "MQTT mapper - T_Outside" data, and commandArray syntax will load this extracted data into "Outside temperature" device.
Don't hesitate to ask questions, should you need more details.
- goto "Setup/Hardware" tab
- check if a line with type "Dummy (Does nothing, use for virtual switches only)" exists
- if not, create one by going into lower part of screen, setting "name" to "Virtual devices", choosing "type" = "Dummy (Does nothing, use for virtual switches only)", and clicking on "Add"
In the popup windows, give a device name (like "Outside temperature") and set "Sensor type" to "Temperature", then click on "Ok"
Congrats, you've just created a brand new virtual temperature sensor!
Now, goto "Setup/More options/Events", click on "+/LUA/device".
In the script windows, you'll see something like:
Code: Select all
--
-- Domoticz passes information to scripts through a number of global tables
--
-- device changed contains state and svalues for the device that changed.
-- devicechanged['yourdevicename'] = state
-- devicechanged['svalues'] = svalues string
--
-- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
-- otherdevices['yourotherdevicename'] = "On"
-- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
-- otherdevices_svalues['yourotherthermometer'] = string of svalues
--
-- uservariables and uservariables_lastupdate are arrays for all user variables:
-- uservariables['yourvariablename'] = 'Test Value'
-- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
--
-- other useful details are contained in the timeofday table
-- timeofday['Nighttime'] = true or false
-- timeofday['SunriseInMinutes'] = number
-- timeofday['Daytime'] = true or false
-- timeofday['SunsetInMinutes'] = number
-- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
--
-- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
-- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
--
-- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
--
commandArray = {}
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
-- if (deviceName=='myDevice') then
-- if deviceValue == "On" then
-- print("Device is On")
-- elseif deviceValue == "Off" then
-- commandArray['a device name'] = "On"
-- commandArray['another device name'] = "Off AFTER 10"
-- commandArray['Scene:MyScene'] = "Off"
-- commandArray['Group:My Group'] = "Off AFTER 30"
-- end
-- end
end
return commandArray
Code: Select all
commandArray = {}
for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='MQTT mapper - T_Outside') then
temperature = string.match(deviceValue, '[0-9%.]+')
print("Outside temperature "..temperature)
commandArray[#commandArray + 1] = {['UpdateDevice']= otherdevices_idx["Outside temperature"]..'||'..temperature}
end
end
return commandArray
To save the script, click on "Save".
You can then test that any change made in "MQTT mapper - T_Outside" is properly extracted and reflected into "Outside temperature".
FYI, string.match will return every "0" to "9" and "." characters from "MQTT mapper - T_Outside" data, and commandArray syntax will load this extracted data into "Outside temperature" device.
Don't hesitate to ask questions, should you need more details.
-
- Posts: 242
- Joined: Friday 12 January 2018 8:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Python Plugin: MqttMapper
I have a lot of experience with domoticz by now, but this was a perfect guideline.
Built a script for the Room temperature and Outside temperature within 15 minutes.
Right now its in the version without the parathesis, but when it changes I'll check if it still works.
Thanks a lot for your help!!
Built a script for the Room temperature and Outside temperature within 15 minutes.
Right now its in the version without the parathesis, but when it changes I'll check if it still works.
Thanks a lot for your help!!
-
- Posts: 22
- Joined: Monday 12 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: Python Plugin: MqttMapper
First of all, thanks for this great plugin. It's a Swiss army knife.
I'm trying to implement a bluetooth (BLE) tracker as a presence tracker in Domoticz with the TheengsGateway as the intermediary. These trackers don't provide an on/off value, but instead just the rssi value. If the rssi element in the json contains a value, the tracker is present (On). If rssi is missing from the message, the tracker is not present (Off).
I'm struggling how to implement this in MQTTMapper. As far as I understood, there is no way to check for the presence of an element in the json.
In pseudocode I'm looking for something like this (which is actually in the payload for Homeassistant auto disovery):
I'm trying to implement a bluetooth (BLE) tracker as a presence tracker in Domoticz with the TheengsGateway as the intermediary. These trackers don't provide an on/off value, but instead just the rssi value. If the rssi element in the json contains a value, the tracker is present (On). If rssi is missing from the message, the tracker is not present (Off).
I'm struggling how to implement this in MQTTMapper. As far as I understood, there is no way to check for the presence of an element in the json.
In pseudocode I'm looking for something like this (which is actually in the payload for Homeassistant auto disovery):
Code: Select all
if value_json.get('rssi') -%}home{%- else -%}not_home{%- endif %}
- waltervl
- Posts: 5851
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Python Plugin: MqttMapper
the TheengsGateway supports the Homeassistant autodiscover protocol that Domoticz also supports. It just could create some sensor automatically. Did you already try that? Although funky value templates with if then else are not supported.vco1 wrote: ↑Thursday 26 June 2025 9:47 First of all, thanks for this great plugin. It's a Swiss army knife.
I'm trying to implement a bluetooth (BLE) tracker as a presence tracker in Domoticz with the TheengsGateway as the intermediary. These trackers don't provide an on/off value, but instead just the rssi value. If the rssi element in the json contains a value, the tracker is present (On). If rssi is missing from the message, the tracker is not present (Off).
I'm struggling how to implement this in MQTTMapper. As far as I understood, there is no way to check for the presence of an element in the json.
In pseudocode I'm looking for something like this (which is actually in the payload for Homeassistant auto disovery):Code: Select all
if value_json.get('rssi') -%}home{%- else -%}not_home{%- endif %}
https://wiki.domoticz.com/MQTT#Add_hard ... Gateway%22
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 22
- Joined: Monday 12 September 2016 9:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: The Netherlands
- Contact:
Re: Python Plugin: MqttMapper
Yes, I did try the autodiscover protocol. That's what I'm using for other sensors (MiPlant). However, DOmoticz doesn't seem to support trackers, like Tile or NUT. So for that I'm using MQTTMapper.waltervl wrote: ↑Thursday 26 June 2025 14:43 the TheengsGateway supports the Homeassistant autodiscover protocol that Domoticz also supports. It just could create some sensor automatically. Did you already try that? Although funky value templates with if then else are not supported.
https://wiki.domoticz.com/MQTT#Add_hard ... Gateway%22
The code is from the HAS Autodiscover payload. I only included that as a reference for the logic I'd like to add to MQTTMapper.
- waltervl
- Posts: 5851
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Python Plugin: MqttMapper
Clear, lets wait for FlyingDomoticz if he nows a rule for
If the rssi element in the json contains a value, the tracker is present (On). If rssi is missing from the message, the tracker is not present (Off).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Who is online
Users browsing this forum: Bing [Bot] and 1 guest