Re: Python Plugin: MqttMapper
Posted: Monday 29 April 2024 0:34
Few words to explain how it works.
MQTT topics are organized around topics. A topic can have sub-topics, which in turn can have sub-topics...
A topic (as well as a sub-topic) can have a value.
This value could be raw, or formatted as JSON.
When using MQTT Explorer, topics are displayed on the left side, sub-topics folded just under them.When clicking on a topic.sub-topic, value (content) is displayed on the right. It's possible to display it raw and even in JSON or XML format, should value been of this structure.
With that, MqttMapper needs to get the tree specification (topic/sub-topic/...) on "topic" content.
If data is raw, meaning to be inserted as it is, use ("item":""). On the other side, if data is JSON formatted, you should specify the JSON path into "Item".
One of the problems to fix, is how to use the same topic multiple times, as Domoticz plug-in need a unique key, and topic is used as this key. In this case, specifying "Key":"xxx" don't use topic as internal key, but the specified key, allowing the same topic to be used multiple times in the same configuration file. As key is not used to anything else but having a unique value, you can put whatever you want here, provided this is not used elsewhere in configuration file, either in "topic" or in "key" values.
That said, you're right, I was wrong, you have to use "glowmarkt/elecconsumptiontoday" as topic, and an empty "Item". And as every topic is unique, you can remove "key".
Concerning the incremental counter, idea is to send permanently deltas, that will be added. This is useful for things that report consumption for a period (minute, hour...) and reset it to zero just after sending it. In your case, unless you use it daily, just before it's reset, this is definitively not the right type.
Concerning electrical counters, internal values are generally in Wh, but display in kWh. Details are available at https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s.
Concerning names, you may also rename it after creation (for example to remove plug-in name automatically added by Domoticz), to make it looking as humanly understandable device name, having nothing related to it's creator plug-in.
Lastly, to be sure, what kind of counter did you choose or "Counter" device? Script may have to be adapted depending on your choice. Currently, script is written for Custom counter (both for MqttMapper device AND virtual "counter").
I tested the script with manual values, and it was working. I'll redo tests deeper, to see if it's working as well as I think.
MQTT topics are organized around topics. A topic can have sub-topics, which in turn can have sub-topics...
A topic (as well as a sub-topic) can have a value.
This value could be raw, or formatted as JSON.
When using MQTT Explorer, topics are displayed on the left side, sub-topics folded just under them.When clicking on a topic.sub-topic, value (content) is displayed on the right. It's possible to display it raw and even in JSON or XML format, should value been of this structure.
With that, MqttMapper needs to get the tree specification (topic/sub-topic/...) on "topic" content.
If data is raw, meaning to be inserted as it is, use ("item":""). On the other side, if data is JSON formatted, you should specify the JSON path into "Item".
One of the problems to fix, is how to use the same topic multiple times, as Domoticz plug-in need a unique key, and topic is used as this key. In this case, specifying "Key":"xxx" don't use topic as internal key, but the specified key, allowing the same topic to be used multiple times in the same configuration file. As key is not used to anything else but having a unique value, you can put whatever you want here, provided this is not used elsewhere in configuration file, either in "topic" or in "key" values.
That said, you're right, I was wrong, you have to use "glowmarkt/elecconsumptiontoday" as topic, and an empty "Item". And as every topic is unique, you can remove "key".
Concerning the incremental counter, idea is to send permanently deltas, that will be added. This is useful for things that report consumption for a period (minute, hour...) and reset it to zero just after sending it. In your case, unless you use it daily, just before it's reset, this is definitively not the right type.
Concerning electrical counters, internal values are generally in Wh, but display in kWh. Details are available at https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s.
Concerning names, you may also rename it after creation (for example to remove plug-in name automatically added by Domoticz), to make it looking as humanly understandable device name, having nothing related to it's creator plug-in.
Lastly, to be sure, what kind of counter did you choose or "Counter" device? Script may have to be adapted depending on your choice. Currently, script is written for Custom counter (both for MqttMapper device AND virtual "counter").
I tested the script with manual values, and it was working. I'll redo tests deeper, to see if it's working as well as I think.