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:

Python Plugin: MqttMapper

Post 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
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by heggink »

Nice!
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
waltervl
Posts: 5152
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

Thanks! Added to the Plugin List on Wiki: https://www.domoticz.com/wiki/Plugins
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 »

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.
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Python Plugin: MqttMapper

Post by Gravityz »

it would be nice if we had some examples of regular devices like

RGBWW light bulbs
WW light bulbs
switches
Last edited by Gravityz on Friday 25 November 2022 8:21, edited 1 time in total.
plugge

Re: Python Plugin: MqttMapper

Post 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?
User avatar
waltervl
Posts: 5152
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post by waltervl »

From the github:
Give JSON configuration file name to be used (located in MqttMapper plugin folder)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5152
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
plugge

Re: Python Plugin: MqttMapper

Post 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!
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Python Plugin: MqttMapper

Post 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.
User avatar
waltervl
Posts: 5152
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Gravityz
Posts: 583
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Python Plugin: MqttMapper

Post 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
User avatar
waltervl
Posts: 5152
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: MqttMapper

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
PBdA
Posts: 15
Joined: Monday 14 December 2015 16:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5893
Location: Colomiers, France
Contact:

Re: Python Plugin: MqttMapper

Post 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.
PBdA
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 »

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.
PBdA
Posts: 15
Joined: Monday 14 December 2015 16:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5893
Location: Colomiers, France
Contact:

Re: Python Plugin: MqttMapper

Post 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.
PBdA
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 »

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.
PBdA
Posts: 15
Joined: Monday 14 December 2015 16:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5893
Location: Colomiers, France
Contact:

Re: Python Plugin: MqttMapper

Post 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"}}
	}
PBdA
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 »

Very smart using fake topics to listen too. I'll keep the idea !
Drago
Posts: 1
Joined: Tuesday 13 December 2022 12:45
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: MqttMapper

Post by Drago »

Getting a strange error in Domoticz 2022_2 (Docker)?
Attachments
Screenshot from 2023-01-14 18-25-21.png
Screenshot from 2023-01-14 18-25-21.png (155.23 KiB) Viewed 5663 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest