Page 1 of 14

Python Plugin: MqttMapper

Posted: Tuesday 01 November 2022 23:18
by FlyingDomotic
Do you want to be able to read some MQTT topics and maps them to Domoticz devices, without having to install NodeRed, and/or integrate sensors that don't have HomeAssistant discovery item?

Just create a JSON file like this, and that's it !

Code: Select all

{
    "Car windows": {
        "topic": "volvo/xx-999-xx/binary_sensor/any_window_open/state",
        "type": "244", "subtype": "73", "switchtype": "11",
        "mapping": {"item": "", "default": "1", "values": {"close": "0"}}
    },
    "Car lock": {
        "topic": "volvo/xx-999-xx/lock/lock/state",
        "type": "244", "subtype": "73","switchtype": "11",
        "mapping": {"item": "", "default": "0", "values": {"lock": "1"}}
    },
    "Car engine running": {
        "topic": "volvo/xx-999-xx/binary_sensor/is_engine_running/state",
        "type": "244", "subtype": "73", "switchtype": "8", 
        "mapping": {"item": "", "default": "1", "values": {"off": "0"}
        }
    },
    "Car odometer": {"topic": "volvo/xx-999-xx/sensor/odometer/state",
        "type": "113", "subtype": "0", "switchtype": "3",
        "options": {"ValueQuantity":"Distance", "ValueUnits":"km"},
        "mapping": {"item": ""}
    },
    "Car fuel amount": {"topic": "volvo/xx-999-xx/sensor/fuel_amount/state",
        "type": "243", "subtype": "31", "switchtype": "0",
        "options": {"Custom":"1;L"},
        "mapping": {"item": ""}
    },
    "Beed room temperature": {
        "topic": "beedRoom",
        "type": "80", "subtype": "5", "switchtype": "0",
        "mapping": {"item": "temperature"}
    },
    "Kitchen temperature": {"topic": "zigbee2mqtt/Kitchen",
        "type": "82", "subtype": "5", "switchtype": "0",
        "mapping": {"item": "temperature;humidity"}
    },
    "Boiler power": {
        "topic": "boiler/SENSOR",
        "type": "248", "subtype": "1", "switchtype": "0",
        "mapping": {"item": "ENERGY/Power;ENERGY/Total"}}
}
More details at https://github.com/FlyingDomotic/domoti ... per-plugin

Re: Python Plugin: MqttMapper

Posted: Wednesday 02 November 2022 8:07
by heggink
Nice!

Re: Python Plugin: MqttMapper

Posted: Wednesday 02 November 2022 9:14
by waltervl
Thanks! Added to the Plugin List on Wiki: https://www.domoticz.com/wiki/Plugins

Re: Python Plugin: MqttMapper

Posted: Monday 14 November 2022 11:47
by FlyingDomotic
Version 1.0.0 now supports SET commands from Domoticz to MQTT.

Don't hesitate to drop me a mail/issue should you have any remarks/request.

Re: Python Plugin: MqttMapper

Posted: Thursday 24 November 2022 15:38
by Gravityz
it would be nice if we had some examples of regular devices like

RGBWW light bulbs
WW light bulbs
switches

Re: Python Plugin: MqttMapper

Posted: Thursday 24 November 2022 23:06
by plugge
@FlyingDomotic: Thank you! Just what I needed. Installation of the plugin was smooth. Can't wait to try it.
Maybe a dumb question, but where does the MqttMapper expect to find the file MqttMapper.json, in the domoticz directory?

Re: Python Plugin: MqttMapper

Posted: Friday 25 November 2022 10:52
by waltervl
From the github:
Give JSON configuration file name to be used (located in MqttMapper plugin folder)

Re: Python Plugin: MqttMapper

Posted: Friday 25 November 2022 12:08
by waltervl
Gravityz wrote: Thursday 24 November 2022 15:38 it would be nice if we had some examples of regular devices like

RGBWW light bulbs
WW light bulbs
switches
You can start with giving examples of the mqtt state topics of your requested examples.

Re: Python Plugin: MqttMapper

Posted: Friday 25 November 2022 13:37
by plugge
waltervl wrote: Friday 25 November 2022 10:52 Give JSON configuration file name to be used (located in MqttMapper plugin folder)
:oops: Thank you!

Re: Python Plugin: MqttMapper

Posted: Friday 25 November 2022 17:39
by Gravityz
this is what i have sofar
the lines which are probably not correct are
rgb_command_template
rgb_value_template
brightness_value_template
color_temp_value_template

i do not know if domoticz wants to see value, value_json.value, value.blue etc
without this info it probably does not map things right.

also whatever i do it recognizes the light as RGBWZ or dimmer(if i remove all the RGB and temperature stuff)


Code: Select all

        "unique_id": "OpenBK7231T_17A1C483_light",
        "name": "lsclamp 64",
        "rgb_command_template": "{{ {'red': red, 'green': green, 'blue': blue}|to_json }}",
        "rgb_value_template": "{{ value_json.value.red }},{{ value_json.value.green }},{{ value_json.value.blue }}",
        "rgb_state_topic": "lsclamp/led_basecolor_rgb/get",
        "rgb_command_topic": "cmnd/lsclamp/led_basecolor_rgb",
        "command_topic": "cmnd/lsclamp/led_enableAll",
        "state_topic": "lsclamp/led_enableAll/get",
        "availability_topic": "lsclamp/connected",
        "payload_on": 1,
        "payload_off": 0,
        "brightness_command_topic": "cmnd/lsclamp/led_dimmer",
        "brightness_scale": 100,
        "brightness_value_template": "{{ value }}",
        "color_temp_command_topic": "cmnd/lsclamp/led_temperature",
        "color_temp_state_topic": "lsclamp/led_temperature/get",
        "color_temp_value_template": "{{ value }}"
      }

if i use this it sort of works as a dimmer without colors(not 100%)

Code: Select all

      {
        "unique_id": "OpenBK7231T_17A1C483_light",
        "name": "lsclamp 64",
        "command_topic": "cmnd/lsclamp/led_enableAll",
        "state_topic": "lsclamp/led_enableAll/get",
        "availability_topic": "lsclamp/connected",
        "payload_on": 1,
        "payload_off": 0,
        "brightness_command_topic": "cmnd/lsclamp/led_dimmer",
        "brightness_value_template": "{{ value }}",
        "brightness_scale": 100,
        "brightness_state_topic": "lsclamp/led_dimmer/get",
        "on_command_type": "brightness",
        "state_value_template": "{{ value }}"
      }

waltervl wrote: Friday 25 November 2022 12:08
Gravityz wrote: Thursday 24 November 2022 15:38 it would be nice if we had some examples of regular devices like

RGBWW light bulbs
WW light bulbs
switches
You can start with giving examples of the mqtt state topics of your requested examples.

Re: Python Plugin: MqttMapper

Posted: Friday 25 November 2022 23:31
by waltervl
You are now in the mqttmapper topic so that maps a mqtt state topic to a domoticz command.
So if RGBWW bulb MQTT state topic contains X, update the Domoticz device state with Y.
And the other way around, if you do Y in Domoticz send MQTT payload X

So what are your MQTT state payloads when you change the bulb to various colours and brightness and what should it be in Domoticz?
What you now have noted is way to complex and too much information, and missing the essential state info. Please check the examples in the GitHub readme.

Re: Python Plugin: MqttMapper

Posted: Saturday 26 November 2022 10:56
by Gravityz
ik will try to ask a question in a new topic because my problem is that i fail to understand how MQTT AD works
if i know what MQTT AD needs to receive to create a specific device i probably also understand how the mapper maps A to B.

in a perfect world where MQTT AD recognises every device 100% there is no need for MQTTmapper right.

so either i need to figur out what makes MQTT AD ticks or how MQTT mapper works.
in both cases i know what to send but i do not know what the domortcs end(eg lighbulb) needs to receive

a page about domoticz MQTT AD like the on Home assistant is using
this gives me an idea but since MQTT AD is not 100% HA compatible i need to see what the domoticz MQTT AD logic is

Re: Python Plugin: MqttMapper

Posted: Saturday 26 November 2022 19:02
by waltervl
It could also be that the device interface you are using is not MQTT autodiscover compatible... Indeed better to start a new topic.

Re: Python Plugin: MqttMapper

Posted: Saturday 10 December 2022 19:31
by PBdA
This plugin is very interesting.

I want to control a RISCO alarm interfaced with MQTT by vanackej/risco-mqtt-local
vanackej/risco-mqtt-local is compatible with autodiscover, but with Domoticz only the PIR sensors are recognized.

The alarm status is missing (topic: "riscopanel/alarm/1/status", values: "disarmed, armed_home, armed_away or triggered")
The alarm command is also missing (topic: "riscopanel/alarm/1/set", values: "ARM_AWAY, ARM_HOME, DISARM")

I can recover the status with MqttMapper in a "selector switch" but I would prefer to use "switch contacts" which, contrary to selector switches
can't be modified in Domoticz.

Is it possible with the same topic ("riscopanel/alarm/1/status") to control 2 switch contacts (armed/disarmed and triggered/not triggered) ? I didn't succeed.

Also, I would like to control the alarm with 2 push buttons (arm and disarm) linked to the same topic "riscopanel/alarm/1/set. I didn't use ARM_HOME.

Re: Python Plugin: MqttMapper

Posted: Saturday 17 December 2022 23:41
by FlyingDomotic
As of now, topic is used as key, so only one device could be mapped by topic.
Should you absolutely want to use multiple switches for one topic, you could write the topic in a string, or a switch selector, hidden by a $ at start of name, and test for changes of this string/selector to set what ever you want in a small LUA or Python script.

Re: Python Plugin: MqttMapper

Posted: Sunday 18 December 2022 9:40
by PBdA
Thank you for your reply and especially for your plugin. I didn't know the '$' trick to hide a device.
I add that for a device used only in the direction Domoticz -> MQTT, there is no problem because in this case main topic is not used. It's possible to have 2 devices with same topic in "set" directive by using different main topic.

Re: Python Plugin: MqttMapper

Posted: Sunday 18 December 2022 9:58
by FlyingDomotic
I've to check, but I'm away from my Domoticz config, but probably not, as only the last device will be shown in device list (it will be created for the first one, and then modified for each others).
However, you could still create selector device with all supported values, hiding it if needed, and then changing its value when you press some buttons by some LUA/dzVents script like:

Code: Select all

if button_armaway_pressed then selector=10
if button_arm_pressed then selector=20
if button_disarm_pressed then selector = 30
... supposing your selector is 10 for arm away, 20 for arm and 30 for disarm, with the correct mapping in MqttMapper
Don't hesitate to ask for help, should you need it for implementing this.

Re: Python Plugin: MqttMapper

Posted: Sunday 18 December 2022 10:20
by PBdA
It works directly with my push buttons. From my MqqttMapper.json:

Code: Select all

	"Arme alarme": {
		"topic": "bidon/arm",
		"type": "244", "subtype": "73", "switchtype": "9",
		"set": {"topic": "riscopanel/alarm/1/set", "payload": "#"},
		"mapping": {"item": "", "default": "100", "values": {"ARM_AWAY": "100"}}
	},
	"Désarme alarme": {
		"topic": "bidon/disarm",
		"type": "244", "subtype": "73", "switchtype": "9",
		"set": {"topic": "riscopanel/alarm/1/set", "payload": "#"},
		"mapping": {"item": "", "default": "100", "values": {"DISARM": "100"}}
	}

Re: Python Plugin: MqttMapper

Posted: Sunday 18 December 2022 10:27
by FlyingDomotic
Very smart using fake topics to listen too. I'll keep the idea !

Re: Python Plugin: MqttMapper

Posted: Saturday 14 January 2023 18:26
by Drago
Getting a strange error in Domoticz 2022_2 (Docker)?