Python Plugin: MqttMapper

Python and python framework

Moderator: leecollings

tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: Python Plugin: MqttMapper

Post by tiga »

thank you....looks like it did the job.

now i have to bepatient and see if there is a change when the bypass changes.
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Nothing protects against chance!
sheepishalbum
Posts: 2
Joined: Monday 15 July 2024 6:50
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by sheepishalbum »

Hi everyone!

Is there a way to have the script refresh the incoming values from MQTT at the rate they come in and not every 60 seconds like now?
I have Domoticz paired with a BMS and this BMS sends MQTT data every 5 seconds to Domoticz, but the script updates the data every minute.
FlyingDomotic
Posts: 322
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, plugin is triggered as soon as MQTT sends data (so every 5 seconds in your case).

If you write a script to do something, you may use a "device change" trigger instead of a "timer trigger". This means that script will be activated each time device changes (in this case, specify device which receive MQTT change as trigger), instead of every minute.

Here's an example for LUA script:

Code: Select all

commandArray = {}

-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
	if (deviceName=='myDomoticzMqttDevice') then
		<put here commands you want to be executed each time 'myDomoticzMqttDevice' is changed>
	end
end
... and one for dzVents script:

Code: Select all

return {
	on = {devices = {'myDomoticzMqttDevice'}},
	logging = {level = domoticz.LOG_DEBUG, marker = 'template'},
	execute = function(domoticz, device)
		<put here commands you want to be executed each time 'myDomoticzMqttDevice' is changed>
	end
}
Change 'myDomoticzMqttDevice' by your Domoticz MQTT device name (those given in your MqttMapper.jspn file).
sheepishalbum
Posts: 2
Joined: Monday 15 July 2024 6:50
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by sheepishalbum »

FlyingDomotic wrote: Monday 15 July 2024 11:11 As of now, plugin is triggered as soon as MQTT sends data (so every 5 seconds in your case).[...]
Thank you so much for your quick help - it works! :)
Thank you also for the amazing domoticz plugin!!!
FlyingDomotic
Posts: 322
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 already told: Nothing protects against chance!
rron
Posts: 246
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: Python Plugin: MqttMapper

Post by rron »

I have started a topic in utility but it looks that mqttmapper can give me a better solution. My smartevse open source electric car
Loader can communicate via mqtt. But in I am missing the payload and therefore I can’t integrate with domoticz. Mqttmapper is already installed but how canI proceed from there. Is it possible?



https://www.domoticz.com/forum/viewtopi ... 68#p318968
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

thaui
Posts: 59
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 »

It`s nice to see that the project MqttMapper is under development and it's a great tool to get Mqtt messages integrated to Domoticz. I am using this plugin since several months but I did a mistake. I was updating the plugin and now the devices in Domoticz are showing only "Zero" values. It was a very simple setup in the MqttMapper.json file.

"BME680_1 Iaq": {
"topic": "BME680_01/iaq",
"type": "249", "subtype":"1",
"mapping":{"item":""}
},
What I am doing wrong and where is the hint? Data are available in Mqtt Explorer. Any help is welcome
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Should be fixed in last version. Sorry about that!
thaui
Posts: 59
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 »

How can the MqttMapper be updated after changing the MqttMapper.json e.g. after adding a new device. Updating the Idx under hardware is not possible. Until now I deleted the Idx and re-entered it again. But in this case I get every time new devices in the database. Also activating/deactivating is not reading the changed json file.
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

thaui wrote: Wednesday 21 August 2024 17:28 How can the MqttMapper be updated after changing the MqttMapper.json e.g. after adding a new device. Updating the Idx under hardware is not possible. Until now I deleted the Idx and re-entered it again. But in this case I get every time new devices in the database. Also activating/deactivating is not reading the changed json file.
Just restart MqttMapper plug-in, either selecting it on "Hardware" tab and clicking on "Update", or restarting Domoticz.
thaui
Posts: 59
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 »

that's exactly what I ment. With restart Domoticz it works but selecting it on "Hardware" tab and clicking on "Update" nothing happend at all. I am on RPI3 with the latest stable release. By the way if you read this email. I am fighting to read P1meter values from a tasmota device.
P1meter topic.JPG
P1meter topic.JPG (35.48 KiB) Viewed 1200 times
I want to get "export_total_kwh","total_kwh" and "curr_w". No chance to get value to Domoticz
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

They're 2 classical things that may cause issues:
1) published data is not marked as "retain". In this case, MqttMapper won't be updated until value changes. It's generally a good idea to flag topics "retain", as readers staring after last update could see last value.
2) you made changes into device type/subtype/switchtype/options not allowed by Domoticz. In this case, you have to delete device and restart plug-in in order for a new one to be crated with last settings.
hjzwiers
Posts: 184
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

My MQTT mapper stopped working, the signals running and signal are failing. In MQTT explorer they are both true.
It used to work fine. The temperature readouts are fine. What changed?

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

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

"MQTTrunning": {
"topic": "ebusd/global/running",
"type": "244", "subtype": "73", "switchtype": "0",
"mapping": {"item": "", "default": "0", "values": {"True": "1"}}
},
"MQTTsignal": {
"topic": "ebusd/global/signal",
"type": "244", "subtype": "73", "switchtype": "0",
"mapping": {"item": "", "default": "0", "values": {"True": "1"}}
}
}
FlyingDomotic
Posts: 322
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 get content concerned topics (probably ebusd/global/running)? the way this is coded, value is on if topic is "True", off else.

In addition when something stops working, try to figure out what changed recently (an update of code/firmware could easily be cause of this kind of problem). Did you changed something recently?
hjzwiers
Posts: 184
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

Well I needed to reinstall the complete system due to a docker crash.

I simply don't know what is going wrong with this and have no clue, from your reaction you don't either .... I thought maby you changed something in the code of MQTT mapper

My MQTT mapper stopped working, the signals running and signal are failing, in MQTT explorer they are both true. It used to work fine. The temperature readouts are fine, but i needed to change the multiplier (from 0.1 to 1)

Image
Attachments
Doc1.docx
(204.11 KiB) Downloaded 25 times
Last edited by hjzwiers on Friday 23 August 2024 10:28, edited 1 time in total.
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Running MqttMapper with debug and sending me Domoticz log in PM may help ;-)

Meantime, would it be possible to get a copy of ebusd topics?
hjzwiers
Posts: 184
Joined: Friday 12 January 2018 8:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by hjzwiers »

I sent a screenshot of MQTT explorer, here is the relevant data:

During startup the logging is totally filled with MQTT auto discovery .........

2024-08-23 11:15:22.097 MQTT mapper: Sending 2 bytes of data
2024-08-23 11:15:22.097 MQTT mapper: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
2024-08-23 11:15:22.147 MQTT mapper: Received 2 bytes of data
2024-08-23 11:15:22.147 MQTT mapper: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю

2024-08-23 11:33:08.489 MQTT mapper: Received 33 bytes of data
2024-08-23 11:33:08.489 MQTT mapper: 30 1f 00 16 65 62 75 73 64 2f 63 74 6c 76 32 2f 7a 31 52 6f 0...ebusd/ctlv2/z1Ro
2024-08-23 11:33:08.489 MQTT mapper: 6f 6d 54 65 6d 70 32 33 2e 37 38 37 35 .. .. .. .. .. .. .. omTemp23.7875
2024-08-23 11:33:08.490 MQTT mapper: onMQTTPublish found ebusd/ctlv2/z1RoomTemp, Device 'MQTT mapper - T_Living', message '23.7875'
2024-08-23 11:33:08.490 MQTT mapper: Setting MQTT mapper - T_Living to 24/23.7875
2024-08-23 11:33:08.490 (MQTT mapper - T_Living) Updating device from 24:'23.725' to have values 24:'23.7875'.

(there is a small box with I think a question mark in the c0 00 but it is not displayed)

I removed the part behind "default": "0" and it is working! I don't know why though ...........

"MQTTrunning": {
"topic": "ebusd/global/running",
"type": "244", "subtype": "73", "switchtype": "0",
"mapping": {"item": "", "default": "0"}
FlyingDomotic
Posts: 322
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Python Plugin: MqttMapper

Post by FlyingDomotic »

Thanks for the log.

I'm greatly interested by MqttMapper initialization messages, as they'll contains (among others) current topics values.

In addition, I'll write a small tool which will dump on scree values of used topics, to help debugging. As soon written, I'll tell you.

Stay tuned!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest