Skip to content

Tested Configurations

JD Smith edited this page Jun 22, 2024 · 239 revisions

Please click one of the following links to quickly jump to the top of any device category.

Bridges

Bulbs and Lights

Dimmers and Switches

Garage Door Openers

Heaters and Coolers

Lock Mechanism

Outlets and Plugs

Security System

Sensors: Air Quality and Carbon Dioxide

Sensors: Contact and Motion

Sensors: Humidity and Temperature

Sensors: Leak

Sensors: Smoke

Switches

Thermostats

Window Coverings

BRIDGES

Sonoff RF Bridge 433

Configuration for Sonoff RF Bridge 433 with Tasmota firmware https://www.itead.cc/wiki/Sonoff_RF_Bridge_433 and more specifically for very chip accessors cooperating with the bridge:

SECURI D026, the smallest overall sensor I have found https://pl.aliexpress.com/item/Door-Window-Sensor-House-Alarm-433mhz-G90b-Home-Security-Burglar-Sensor-PIR-Door-Magnetic-Wireless-Alarm/32888865480.html?spm=a2g17.10010108.1000016.1.42b06346xpZ08y&isOrigTitle=true two state (open/close) sensor, low battery and tempered info:

{
    "accessory": "mqttthing",
    "type": "contactSensor",
    "name": "Sensor_1",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics":
    {
        "getContactSensorState": {
    	    "topic": "tele/DVES_B2AE5C/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'open_code' ) ? 1 : null || ( JSON.parse(message).RfReceived.Data == 'close_code' ) ? 0  : null);"
            },
"getStatusTampered": {
    	    "topic": "tele/DVES_B2AE5C/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'tempered_code' ) ? 1 : null );"
    	    },
        "getStatusLowBattery": {
    	    "topic": "tele/DVES_B2AE5C/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'battery_low_code' ) ? 1 : null );"
    	    }
    },
	    "integerValue": true,
            "logMqtt": false
    },  

i.e. the open_code, close_code, is catch from sonoff rf 433 Tasmota firmware console who look like

22:53:50 MQT: tele/DVES_B2AE5C/RESULT = {"RfReceived":{"Sync":9540,"Low":340,"High":910,"Data":"7CF1EE","RfKey":"None"}}
22:53:55 MQT: tele/DVES_B2AE5C/RESULT = {"RfReceived":{"Sync":9430,"Low":310,"High":940,"Data":"7CF1E7","RfKey":"None"}}

open is 7CF1EE and close 7CF1E7 and DVES_B2AE5C is topic name set in bridge

DIGOO DG-HOSA HOSA 433 mhz https://www.aliexpress.com/i/32828235142.html leak detection sensor, open code is triggered after circuit short by water a close state is generated by button on sensor case (after break leak water :) )

configuration is similar to above but change sensor type

"type": "leakSensor",
"getLeakDetected":

DIGOO DG-HOSA HOSA https://pl.aliexpress.com/item/DIGOO-DG-HOSA-Wireless-Infrared-PIR-Detector-Sensor-For-433MHz-Home-Security-Alarm-System-Kits/32819986075.html

like above but change sensor type and off after period time (this is one state sensor)

"type": "motionSensor",
"getMotionDetected":{
    	    "topic": "tele/DVES_B2AE5C/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'trigger_code' ) ? 1 : null);"
    	    }

"turnOffAfterms": "6000",

Notice: I've provided links to products not for advertising, but the things I bought are cheap and work reliably in my home

Thanks to lulek2007


For the Sonoff Motion Sensor, with Sonoss RF Bridge (flashed to Tasmota):

"accessories": [
        {
            "accessory": "mqttthing",
            "type": "motionSensor",
            "name": "mBerging",
            "url": "mqtt://0.0.0.0:1883",
            "username": "",
            "password": "",
            "caption": "",
            "topics": {
                "getMotionDetected": {
                    "topic": "tele/tasmota_XXXXX/RESULT",
                    "apply": "return( ( JSON.parse(message).RfReceived.Data == '123456' ) ? 1 : 0);"
                }
            },
            "integerValue": "true",
            "turnOffAfterms": "6000"
        }
    ],
  • Change the URL in your MQTT broker's IP address
  • Change the tasmota_XXXXX in your TasmatoID
  • Change the 123456 with the code you can find in the "Data" part of the MQTT message:
{"Time":"2020-04-29T15:33:19","RfReceived":
   {"Sync":12530,"Low":440,"High":1250,"Data":"**123456**","RfKey":"None"}
} 

BULBS AND LIGHTS

Sonoff Tasmota ZigBee (Zigbee2Tasmota)

Example configuration for Sonoff Basic ZBR3 (ZigBee) with Sonoff ZigBee Bridge Tasmota (ZigBee2Tasmota)

        {
            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "testzigbee",
            "url": "mqtt://ipaddres",
            "integerValue": "true",
            "topics": {
                "getOn": {
                    "topic": "tele/sonoffBridgeTopic/SENSOR",
                    "apply": "return JSON.parse(message).ZbReceived['0xAB2F'].Power;"
                },
                "setOn": {
                    "topic": "cmnd/sonoffBridgeTopic/ZbSend",
                    "apply": "return '{\"device\":\"0xAB2F\", \"send\":{\"Power\":' + message + '}}'"
                }
            }
        }

0xAB2F is ZigBee device id taken from your ZigBee Bridge

Thanks to bartoszwas

Tuya Switch (Zigbee2Tasmota)

Example configuration for Tuya ZigBee Switch (ZigBee) with Sonoff ZigBee Bridge Tasmota (ZigBee2Tasmota)

        {
            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "testzigbee",
            "url": "mqtt://ipaddres",
            "integerValue": "true",
            "topics": {
                "getOn": {
                    "topic": "tele/sonoffBridgeTopic/SENSOR",
                    "apply": "return JSON.parse(message).ZbReceived['0xAB2F'].Power;"
                },
                "setOn": {
                    "topic": "cmnd/sonoffBridgeTopic/ZbSend",
                    "apply": "return '{\"device\":\"0xF422\", \"Write\":{\"Power\":' + message + '}}'"
                }
            }
        }

0xAB2F is ZigBee device id taken from your ZigBee Bridge

Thanks to bartoszwas

IKEA TRADFRI LED Bulb Dimmable

Configuration for IKEA TRADFRI LED bulbs, tested with:

  • IKEA TRADFRI LED bulb E12/E14/E17 400 lumen, dimmable warm white, chandelier opal
  • IKEA TRADFRI LED bulb E27 1000 lumen, dimmable, opal white

The bulbs were connected to an USB Zigbee sniffer (CC2531) and communicate with the mqtt server via zigbee2mqtt.

    {
		"accessory": "mqttthing",
		"type": "lightbulb",
		"name": "Wohnzimer-Stehlampe",
		"onValue": "ON",
		"offValue": "OFF",
		"topics": {
			"getOn": {
				"topic": "zigbee2mqtt/0x000d6ffffed3dd42",
				"apply": "return JSON.parse(message).state"
			}, 
			"setOn": "zigbee2mqtt/0x000d6ffffed3dd42/set",
			"getBrightness": {
				"topic": "zigbee2mqtt/0x000d6ffffed3dd42",
				"apply": "return Math.round(JSON.parse(message).brightness / 2.55)"
			}, 
			"setBrightness": {
				"topic": "zigbee2mqtt/0x000d6ffffed3dd42/set",
				"apply": "return JSON.stringify({brightness: Math.round(message * 2.55)})"
			}
		}
	}

Thanks to dylexrocks

IKEA TRADFI LED Bulb Dimmable with Colour Temperature Adjustment

https://www.ikea.com/gb/en/p/tradfri-led-bulb-e27-806-lumen-wireless-dimmable-white-spectrum-white-spectrum-globe-clear-30408470/

    {
        "type": "lightbulb-ColTemp",
        "name": "ColTemp",
        "topics": {
            "getOnline": "IsOnLine",
            "getOn": {
                "topic": "zigbee2mqtt/<id>",
                "apply": "return JSON.parse(message).state"
            },
            "setOn": "zigbee2mqtt/<id>/set",
            "getBrightness": {
                "topic": "zigbee2mqtt/<id>",
                "apply": "return Math.round(JSON.parse(message).brightness / 2.55)"
            },
            "setBrightness": {
                "topic": "zigbee2mqtt/<id>/set",
                "apply": "return JSON.stringify({brightness: Math.round(message * 2.55)})"
            },
            "getColorTemperature": {
                "topic": "zigbee2mqtt/<id>",
                "apply": "return Math.round(JSON.parse(message).color_temp)"
            },
            "setColorTemperature": {
                "topic": "zigbee2mqtt/<id>/set",
                "apply": "return JSON.stringify({color_temp: message})"
            }
        },
        "onlineValue": "ON",
        "offlineValue": "ON",
        "onValue": "ON",
        "offValue": "OFF",
        "accessory": "mqttthing"
    }

Thanks to VirtualPubwash (#296)

Mirabella Genio LED Bulb Dimmable Colour Changing Temp

Configuration for Mirabella Genio Colour Changing LED Bulb. Flashed with Tasmota and loaded with the following template:

{"NAME":"GenioBulbWCD","GPIO":[0,0,0,0,37,40,0,0,38,41,39,0,0],"FLAG":0,"BASE":18}
{
		"accessory": "mqttthing",
		"type": "lightbulb",
		"name": "LEDLight",
		"url": "mqtt://mqttbroker",
		"username": "DVES_USER",
		"password": "123456",
		"topics": {
			"setOn": "cmnd/DVES_8FC32E_fb/power",
			"getOn": "stat/DVES_8FC32E_fb/POWER",
			"getOnline": {
				"topic": "tele/sonoff/LWT",
				"apply": "return message == 'Online' ? 'ON' : 'OFF';"
			},"getBrightness": "nodered/DVES_8FC32E_fb/dimmer/get",
        "setBrightness": "cmnd/DVES_8FC32E_fb/Dimmer",
        "getColorTemperature": "nodered/DVES_8FC32E_fb/colortemp/get",
        "setColorTemperature": "cmnd/DVES_8FC32E_fb/CT"
		},
		"integerValue": false,
		"onValue": "ON",
		"offValue": "OFF",
		"startPub": {
			"cmnd/DVES_8FC32E_fb/power": "",
			"stat/DVES_8FC32E_fb/POWER": ""
		},
		"logMqtt": true
	}

Thanks Jamie Collins

Mirabella Genio WiFi LED Strip Light

Configuration for Mirabella Genio WiFi LED Strip Light. Flashed with Tasmota and loaded with the following template:

{"NAME":"MirabellaStrip","GPIO":[32,0,0,0,416,419,0,0,417,0,418,0,0,0],"FLAG":0,"BASE":18}
{
            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "Lightstrip 1",
            "url": "mqtt://mqttbroker",
            "username": "user",
            "password": "pass",
            "topics": {
                "setOn": "cmnd/lightstrip1/power",
                "getOn": "stat/lightstrip1/POWER",
                "getOnline": {
                    "topic": "tele/lightstrip1/LWT",
                    "apply": "return message == 'Online' ? 'ON' : 'OFF';"
                },
                "getRGBW": "stat/lightstrip1/Color",
                "setRGBW": "cmnd/lightstrip1/Color"
            },
            "integerValue": false,
            "hex": "true",
            "onValue": "ON",
            "offValue": "OFF",
            "startPub": {
                "cmnd/lightstrip1/power": "",
                "stat/lightstrip1/POWER": ""
            },
            "logMqtt": true
        }

Note: in console Set fade 1 and speed 4 for nice smooth transitions between colours and on/off state

OSRAM LIGHTIFY LED Classic B40 Tunable White

Configuration for OSRAM LIGHTIFY LED Classic B40 tunable white.

The bulbs were connected to an USB Zigbee sniffer (CC2531) and communicate with the mqtt server via zigbee2mqtt.

{
            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "Schlafzimmer-links",
            "topics": {
                "getOn": {
                    "topic": "zigbee2mqtt/bulb/ct/0x7cb03eaa00ae1fd7",
                    "apply": "return JSON.parse(message).state;"
                },
                "setOn": "zigbee2mqtt/bulb/ct/0x7cb03eaa00ae1fd7/set",
                "getBrightness": {
                    "topic": "zigbee2mqtt/bulb/ct/0x7cb03eaa00ae1fd7",
                    "apply": "return Math.round(JSON.parse(message).brightness / 2.54)"
                },
                "setBrightness": {
                    "topic": "zigbee2mqtt/bulb/ct/0x7cb03eaa00ae1fd7/set",
                    "apply": "return JSON.stringify({brightness: Math.round(message * 2.54)})"
                },
                "getColorTemperature": {
                    "topic": "zigbee2mqtt/bulb/ct/0x7cb03eaa00ae1fd7",
                    "apply": "return Math.round(140 + (JSON.parse(message).color_temp - 153) * 360 / 217)"
                },
                "setColorTemperature": {
                    "topic": "zigbee2mqtt/bulb/ct/0x7cb03eaa00ae1fd7/set",
                    "apply": "return JSON.stringify({color_temp: Math.round(153 + (message - 140) * 217 / 360)})"
                }
            },
            "onValue": "ON",
            "offValue": "OFF"
        }

Thanks to dylexrocks

Philips Hue GO Bulb HSV Color Representation

The tested configuration uses a javascript conversion to transform the HSV output structure [hue, saturation, brightness] of the homebridge-mqttthing plugin into the appropriate zigbee2mqtt message structure. (http://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html)

The bulb is connected to an USB Zigbee sniffer (CC2531) and communicate with the mqtt server via zigbee2mqtt.

      {
        "accessory": "mqttthing",
        "type": "lightbulb",
        "name": "HUE Go",
        "topics": {
        "getOn": {
                "topic": "zigbee2mqtt/<deviceID>",
                "apply": "return JSON.parse(message).state"
        }, 
        "setOn": "zigbee2mqtt/<deviceID>/set", 
        "setHSV": {
                "topic": "zigbee2mqtt/<deviceID>/set",
                "apply": "return JSON.stringify({transition: 2, brightness: Math.round(message.substr(message.lastIndexOf(',')+1,message.length)* 2.55), color: {hue: message.substr(0,message.indexOf(',')), saturation: message.substr(message.indexOf(',')+1,(message.lastIndexOf(',')-message.indexOf(','))-1)}})"
        }
      },
       "onValue": "ON",
       "offValue": "OFF",
      },

Replace <deviceID> with your paired device ID.

thanks to alexair777

Philips Hue Filament Bulb (Brightness only bulb)

This configuration is based on the Hue GO bulb config to parse data however I changed alexair777's js code a bit (http://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html).

The bulb is connected to Homebridge via CC2531 and zigbee2mqtt.

            {
            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "Hue Filament",
            "onValue": "ON",
            "offValue": "OFF",
            "topics": {
                "getOn": {
                    "topic": "zigbee2mqtt/<deviceID>",
                    "apply": "return JSON.parse(message).state"
                },
                "setOn": {
                    "topic": "zigbee2mqtt/<deviceID>/set",
                    "apply": "return JSON.stringify({transition: String(0.5), state: String(message)})"
                },
                "getBrightness": {
                    "topic": "zigbee2mqtt/<deviceID>",
                    "apply": "return Math.round(JSON.parse(message).brightness / 2.54)"
                },
                "setBrightness": {
                    "topic": "zigbee2mqtt/<deviceID>/set",
                    "apply": "return JSON.stringify({transition: String(0.5), brightness: String(Math.round(message * 2.54))})"
                }
            }
        },

Replace <deviceID> with your paired device ID.

Globe 34207 800lm RGBCCT Bulb

For Tasmota devices, ensure to use the template from here. These are typically sold at Costco in a 3-pack, and are easily flashable using Tuya Convert (start_flash.sh).

        {
            "accessory": "mqttthing",
            "type": "lightbulb",
            "name": "Bulb",
            "caption": "Bulb",
            "topics": {
                "getOn": "stat/<deviceID>/POWER",
                "setOn": "cmnd/<deviceID>/power",
                "getHSV": {
                    "topic": "stat/<deviceID>/RESULT",
                    "apply": "return JSON.parse(message).HSBColor;"
                },
                "setHSV": "cmnd/<deviceID>/HSBColor",
                "getRGBWW": {
                    "topic": "stat/<deviceID>/RESULT",
                    "apply": "return JSON.parse(message).Channel;"
                },
                "setRGBWW": "cmnd/<deviceID>/channel",
                "getWhite": {
                    "topic": "stat/<deviceID>/RESULT",
                    "apply": "return JSON.parse(message).White;"
                },
                "setWhite": "cmnd/<deviceID>/white",
                "getColorTemperature": {
                    "topic": "stat/<deviceID>/RESULT",
                    "apply": "return JSON.parse(message).CT;"
                },
                "setColorTemperature": "cmnd/<deviceID>/CT"
            },
            "startPub": {
                "cmnd/<deviceID>/dimmer": "",
                "cmnd/<deviceID>/power": ""
            },
            "integerValue": "false",
            "onValue": "ON",
            "offValue": "OFF",
            "logMqtt": true,
            "manufacturer": "Globe",
            "model": "34207",
            "serialNumber": "XXXXXXX1"
        },

Deta Grid Connect Smart 10W LED Downlight

For Tasmota flashed Deta Grid Connect Smart 10W RGB LED Downlights. Template used is here. These are now found at bunnings and useful for any home DIY Smart home installations.

Please note that this uses RGBWW and the WW are reversed. Therefore in home.app when selecting a warm white color, the globe will produce a cool white, and vice versa. I have put in a request for a tickbox to be enabled in the plugin to allow the swapping of order of WW.

{
            "type": "lightbulb",
            "name": "<whatever you want the globe called>",
            "mqttPubOptions": {
                "retain": true
            },
            "topics": {
                "getRGBWW": "stat/<topic>/Color",
                "setRGBWW": "cmnd/<topic>/Color",
                "getOn": "stat/<topic>/POWER",
                "setOn": "cmnd/<topic>/POWER",
                "getBrightness": "stat/<topic>/Dimmer",
                "setBrightness": "cmnd/<topic>/Dimmer",
                "getColorTemperature": "stat/<topic>/CT",
                "setColorTemperature": "cmnd/<topic>/CT"
            },
            "onValue": "ON",
            "offValue": "OFF",
            "hex": true,
            "whiteMix": true,
            "accessory": "mqttthing"
        }

Config supplied by Dave Reid (DRPAU)

DIMMERS AND SWITCHES

IKEA TRADFRI Shortcut button (StatelessProgrammableSwitch)

This switch is connected to a Deconz usb devices and communicates with the mqtt server via zigbee2mqtt. The switch has 4 action values: on (= single press), off, brightness_move_up (= long press start), brightness_move_down (= long press stop). This config will expose single press and double press to homekit.

{
    "type": "statelessProgrammableSwitch",
    "name": "NAME",
    "topics": {
        "getSwitch": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).action;"
        },
        "getBatteryLevel": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).battery;"
        }
    },
    "switchValues": [
        "on",
        "off",
        "brightness_move_up"
    ],
    "restrictSwitchValues": [
        0,
        2
    ],
    "accessory": "mqttthing"
}

IKEA TRADFRI Switch (wireless dimmer)

The switch is connected to a Zigbee CC2538 and communicates with the mqtt server via zigbee2mqtt. It’s recommended to set legacy: false in the configuration.yaml to use the action event (instead of deprecated click event) (see zigbee2mqtt.io/devices/E1743.html)

{
    "accessory": "mqttthing",
    "type": "switch",
    "name": "IKEA Switch",
    "onValue": "on",
    "offValue": "off",
    "topics": {
        "getOn": {
            "topic": "zigbee2mqtt/0xec1bbdfffe9a3948",
            "apply": "return JSON.parse(message).action;"
        },
        "setOn": "zigbee2mqtt/0xec1bbdfffe9a3948/set",
        "getBatteryLevel": {
            "topic": "zigbee2mqtt/0xec1bbdfffe9a3948",
            "apply": "return JSON.parse(message).battery;"
        }
    },
    "integerValue": false,
    "logMqtt": true
}

CE Smart Wifi Smart Dimmer

This are the settings using my CE Smart Wifi Dimmer model WF-500D. I replaced the stock Tuya firmware with Sonoff-Tasmota following the instructions here. https://github.com/SynAckFin/TuyOTA/wiki/Walkthrough

Once I had my device configured, I set the full topic to include the device name as part of the topic, ie %prefix%/%topic%-0685/.

{
    "accessory": "mqttthing",
    "type": "lightbulb",
    "name": "Beside Stairs",
    "topics": {
        "getOn": "stat/sonoff-0685/POWER",
        "setOn": "cmnd/sonoff-0685/power",
        "getBrightness": {
            "topic": "stat/sonoff-0685/RESULT",
            "apply": "return JSON.parse(message).Dimmer;"
        },
        "setBrightness": "cmnd/sonoff-0685/dimmer"
    },
   "onValue": "ON",
   "offValue": "OFF",
   "startPub": {
        "cmnd/sonoff-0685/dimmer": "",
        "cmnd/sonoff-0685/power": ""
    }
}

Thanks to NorthernMan54

Deta 1-Gang WiFi Switch

Purchase these at Bunnings Warehouse in Australia.

To Configure:

  • Replace the stock Tuya firmware (it's branded as "GridConnect") by flashing using Tasmota v8.3.1
  • Configure the switch using the 1-Gang template here
  • Set the MQTT details such as username/password, topic, and client id.

Once the switch is configured, add the following MQTTthing config to your HomeBridge config:

{
    "type": "switch",
    "name": "Main Light Switch",
    "url": "mqtt://<homebridge IP or FQDN>:1883",
    "username": "<username>",
    "password": "<password>",
    "topics": {
        "getOnline": {
            "topic": "tele/<topic>/LWT",
            "apply": "return message == 'Online' ? 'ON' : 'OFF';"
        },
        "getOn": "stat/<topic>/POWER",
        "setOn": "cmnd/<topic>/POWER"
    },
    "integerValue": false,
    "onValue": "ON",
    "offValue": "OFF",
    "startPub": {
        "cmnd/<topic>/POWER": "",
        "stat/<topic>/POWER": ""
    },
    "accessory": "mqttthing"
}

Feit Smart WiFi Dimmer

Purchase these at Costco or Menards Online.

Replace the stock Tuya firmware with compiled ESPHome firmware – Tasmota is unstable and difficult to get TuyaMCU comms working properly.

Configuree the ESPHome yaml file with the following before compiling and uploading firmware:

esphome:
  name: esphome_dimmer_1
  platform: ESP8266
  board: esp8285

wifi:
  ssid: "<YOUR WIFI SSID>"
  password: "<YOUR WIFI PASSWORD>"
  manual_ip:
    # populate IP here to force manual DCHP
    static_ip: #.#.#.#
    # populate the gateway address for network
    gateway: #.#.#.#
    subnet: 255.255.255.0
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "esphome_dimmer_1"
    password: "<YOUR BACKUP HOTSPOT PASSWORD>"

captive_portal:

api:

ota:

web_server:
  port: 80

uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600

mqtt:
  # populate your MQTT broker IP here
  broker: #.#.#.#
  topic_prefix: "esphome_dimmer_1"

# enable TuyaMCU communication
tuya:

# Make the light
light:
  - platform: "tuya"
    name: "esphome_dimmer_1"
    dimmer_datapoint: 2
    switch_datapoint: 1
    min_value: 10
    max_value: 1000

Once device is flashed/configured, add the following MQTTthing config to your homebridge config:

{
    "accessory": "mqttthing",
    "type": "lightbulb",
    "name": "Feit Dimmable WiFi Switch",
    "manufacturer": "Feit",
    "model": "WiFi Switch",
    "firmwareRevision": "ESPHome 1.14.3",
    "topics": {
        "getOn": {
            "topic": "esphome_dimmer_1/light/esphome_dimmer_1/state",
            "apply": "return JSON.parse(message).state;"
        },
        "setOn": {
            "topic": "esphome_dimmer_1/light/esphome_dimmer_1/command",
            "apply": "return JSON.stringify({state: message});"
        },
        "getBrightness": {
            "topic": "esphome_dimmer_1/light/esphome_dimmer_1/state",
            "apply": "return Math.round(JSON.parse(message).brightness / 2.55);"
        },
        "setBrightness": {
            "topic": "esphome_dimmer_1/light/esphome_dimmer_1/command",
            "apply": "return JSON.stringify({brightness: Math.round(message * 2.55)});"
        }
    },
    "onValue": "ON",
    "offValue": "OFF"
}

Fibaro Walli Dimmer

  • Z-Wave model FGWDEU-111
  • tested with Open-ZWave version 1.6-880, open-zwave-mqtt 2.02, homebridge-mqttthing 1.0.45
  • replace occurrences of "node6" with your own Z-Wave node number
{
    "accessory": "mqttthing",
    "type": "lightbulb",
    "name": "Strahler",
    "topics": {
        "getOn": {
            "topic": "node6/switch_multilevel/1/target_value",
            "apply": "return message > 0 ? '255' : '0';"
        },
        "setOn": "node6/switch_multilevel/1/level/set",
        "setBrightness": {
            "topic": "node6/switch_multilevel/1/level/set",
            "apply": "return message == '100' ? '255' : message;"
        },
        "getBrightness": "node6/switch_multilevel/1/target_value"
    },
    "onValue": "255",
    "offValue": "0"
}

Shelly1 Switch

This is an example configuration of the Shelly1 switch https://shelly-api-docs.shelly.cloud/#shelly1

Insert the name of your device in place "shelly1-259DD6"

{
    "accessory": "mqttthing",
    "type": "switch",
    "name": "LED lamp",
    "topics":{
        "getOn":"shellies/shelly1-259DD6/relay/0",
        "setOn":"shellies/shelly1-259DD6/relay/0/command",
        "getOnline":"shellies/shelly1-259DD6/online" 
    },
    "onValue": "on",
    "offValue": "off",
    "onlineValue": "true",
    "logMqtt": true
}

Thanks to lulek2007

Shelly Plus 1

This is an example configuration of the Shelly Plus 1 stateless switch https://shelly-api-docs.shelly.cloud/gen2/

Insert the name of your device in place "shellyplus1-a8032abdf060"

{
  "type": "lightbulb-OnOff",
  "name": "YOUR-ACCESSORY-NAME",
  "url": "ADDRESS OR HOSTNAME TO MQTT SERVER",
  "logMqtt": true,
  "topics": {
      "getOn": {
                    "topic": "shellyplus1-a8032abdf060/status/switch:0",
                    "apply": "return JSON.parse(message).output;"
                },
       "setOn": {
                    "topic": "shellyplus1-a8032abdf060/rpc",
                    "apply": "return JSON.stringify({id: 123, src: 'user_1', method: 'Switch.Set', params: {id: 0, on: message}});"
                }
            },
       "accessory": "mqttthing"
}

Working example with homebridge 1.3.8 running on synology with oznu/homebridge docker image. Listening topic is set to /events/rpc according to Shelly Gen 2 Device API. Mqttthing version 1.1.38. Replace items tagged by < > with your values.

        {
            "type": "switch",
            "name": "Doorbell",
            "url": "<ipaddress:1883>",
            "username": "<user>",
            "password": "<password>",
            "topics": {
                "getOn": {
                    "topic": "<shelly-id>/events/rpc",
                    "apply": "return JSON.parse(message).params[\"switch:0\"].output;"
                },
                "setOn": {
                    "topic": "<shelly-id>/rpc",
                    "apply": "return JSON.stringify({id: 123, src: 'user_1', method: 'Switch.Set', params: {id: 0, on: message}});"
                }
            },
            "manufacturer": "Shelly",
            "model": "Shelly 1 Plus",
            "serialNumber": "<I usually insert device mac address>",
            "firmwareRevision": "shellyOS",
            "accessory": "mqttthing"
        }

ShellyButton1

This is an example configuration of the ShellyButton1 stateless switch https://shelly-api-docs.shelly.cloud/#shelly-button1

Insert the name of your device in place "shellybutton1-A4CF12F45331"

   {
    "accessory": "mqttthing",
    "type": "statelessProgrammableSwitch",
    "name": "Przycisk wentylator łazienka",
    "url": "mqtt://xxx.xxx.xxx.xxx",
    "username": "xxxxxxx",
    "password": "xxxxxxx",
    "topics":
    {

    "getSwitch": {
    "topic": "shellies/shellybutton1-A4CF12F45331/input_event/0",
            "apply": "return JSON.parse(message).event"

    }
    },
     "switchValues": [
                "S",
                "SS",
                "L"
            ],
     "logMqtt": true
    },

Thanks to lulek2007

Shelly Dimmer/SL

This is an example configuration of the Shelly Dimmer https://shelly-api-docs.shelly.cloud/#shelly-dimmer-sl-overview

Insert the name of your device in place "shellydimmer-XXXXXX"

{
    "accessory": "mqttthing",
    "username": "USERNAME",
    "password": "PASSWORD",
    "type": "lightbulb",
    "name": "Fancy Name",
    "url": "mqtt://192.168.188.30:1883",
    "topics": {
        "getOn": "shellies/shellydimmer-XXXXXX/light/0",
        "setOn": "shellies/shellydimmer-XXXXXX/light/0/command",
        "getBrightness": {
            "topic": "shellies/shellydimmer-XXXXXX/light/0/status",
            "apply": "return (JSON.parse(message).ison ? JSON.parse(message).brightness : 0);"
        },
        "setBrightness": {
            "topic": "shellies/shellydimmer-XXXXXX/light/0/set",
            "apply": "return JSON.stringify({ turn:\"on\", brightness: parseInt(message)})"
        }
    },
    "onValue": "on",
    "offValue": "off"
}

Shelly Dimmer 2

This is an example configuration of the Shelly Dimmer 2, supporting dimming with nice fade transition: https://shelly-api-docs.shelly.cloud/gen1/#shelly-dimmer-1-2-mqtt

Set transition up to 5000ms. Insert the name of your device in place "shelly-xxx".

{
    "accessory": "mqttthing",
    "type": "lightbulb-Dimmable",
    "name": "Shelly Dimmer 2",
    "url": "mqtt://192.168.0.200:1883",
    "logMqtt": false,
    "topics": {
        "getBrightness": {
            "topic": "shellies/shelly-xxx/light/0/status",
            "apply": "const response = JSON.parse(message); return (response.ison == true) ? response.brightness : 0;"
        },
        "setBrightness": {
            "topic": "shellies/shelly-xxx/light/0/set",
            "apply": "const response = (message == 0) ? { 'turn': 'off', 'transition': 4000 } : { 'turn': 'on', 'brightness': message, 'transition': 4000 }; return JSON.stringify(response)"
        }
    }
}

Shelly RGBW2 Color

This is an example configuration of the Shelly RGBW2 Color, supporting dimming with nice fade transition: https://shelly-api-docs.shelly.cloud/gen1/#shelly-rgbw2-color-mqtt

Set transition up to 5000ms. Insert the name of your device in place "shelly-xxx".


    "accessory": "mqttthing",
    "type": "lightbulb",
    "name": "Shelly RGBW2",
    "url": "mqtt://192.168.0.200:1883",
    "logMqtt": false,
    "topics": {
        "getOn": "shellies/shelly-xxx/color/0",
        "setOn": "shellies/shelly-xxx/color/0/command",
        "getRGBW": {
            "topic": "shellies/shelly-xxx/color/0/status",
            "apply": "const response = JSON.parse(message); return response.red.toString() + ',' + response.green.toString() + ',' + response.blue.toString() + ',' + response.white.toString();"
        },
        "setRGBW": {
            "topic": "shellies/shelly-xxx/color/0/set",
            "apply": "if (message == '0,0,0,0') { return JSON.stringify({ 'turn': 'off', 'transition': 3000 }); } else { const splitMessage = message.split(','); return JSON.stringify({ 'turn': 'on', 'red': splitMessage[0], 'green': splitMessage[1], 'blue': splitMessage[2], 'white': splitMessage[3], 'gain': 100, 'transition': 4000 }) }"
        }
    },
    "onValue": "on",
    "offValue": "off",
    "adaptiveLighting": false,
    "optimizePublishing": true,
    "debounceRecvms": 250
}

Sonoff Basic Switch

Example configuration for Sonoff Basic switch, Tasmota firmware and configured topic is "DVES_DFDFE5"

{
    "accessory": "mqttthing",
    "type": "switch",
    "name": "Oświetlenie kuchnia reflektorki",
	"url": "mqtt://localhost",
	"username": "admin",
	"password": "123456",
    "topics": {
        "setOn": "cmnd/DVES_DFDFE5/power",    
        "getOn": "stat/DVES_DFDFE5/POWER",    
        "getOnline": {
            "topic": "tele/DVES_DFDFE5/LWT",
            "apply": "return message == 'Online' ? 'ON' : 'OFF';"
        }
    },
    "integerValue": false,
    "onValue": "ON",
    "offValue": "OFF",
    "startPub": {
        "cmnd/DVES_DFDFE5/power": "",
        "stat/DVES_DFDFE5/POWER": ""
    },
    "logMqtt": true
}

Thanks to lulek 2007

Sonoff Dual Switch

Example configuration for Sonoff Dual Switch, Tasmota firmware and configured topic is "DVES_86D89F"

{
    "accessory": "mqttthing",
    "type": "outlet",
    "name": "Gniazdo 1 kuchnia",
	"url": "mqtt://localhost",
	"username": "admin",
	"password": "123456",
    "topics": {
        "setOn": "cmnd/DVES_86D89F/power1",    
        "getOn": "stat/DVES_86D89F/POWER1",    
        "getOnline": {
            "topic": "tele/DVES_86D89F/LWT",
            "apply": "return message == 'Online' ? 'ON' : 'OFF';"
        }
    },
    "integerValue": false,
    "onValue": "ON",
    "offValue": "OFF",
    "startPub": {
        "cmnd/DVES_86D89F/power1": "",
        "stat/DVES_86D89F/POWER1": ""
    },
    "logMqtt": true
},
{
    "accessory": "mqttthing",
    "type": "outlet",
    "name": "Gniazdo 2 kuchnia",
	"url": "mqtt://localhost",
	"username": "admin",
	"password": "123456",
    "topics": {
        "setOn": "cmnd/DVES_86D89F/power2",    
        "getOn": "stat/DVES_86D89F/POWER2",    
        "getOnline": {
            "topic": "tele/DVES_86D89F/LWT",
            "apply": "return message == 'Online' ? 'ON' : 'OFF';"
        }
    },
    "integerValue": false,
    "onValue": "ON",
    "offValue": "OFF",
    "startPub": {
        "cmnd/DVES_86D89F/power2": "",
        "stat/DVES_86D89F/POWER2": ""
    },
    "logMqtt": true
}

Thanks to lulek 2007

Sonoff POW Switch

Example configuration for Sonoff POW with Tasmota firmware working with EVE APP

{
    "accessory": "mqttthing",
    "type": "outlet",
    "name": "Main Lights",
    "url": "mqtt://localhost",
    "mqttOptions": {
        "keepalive": 30
    },
    "mqttPubOptions": {
        "retain": true
    },
    "topics": {
        "getOn": "stat/sonoff-0456/POWER",
        "setOn": "cmnd/sonoff-0456/power",
        "getOnline": "tele/sonoff-0456/LWT",
        "getWatts": {
            "topic": "tele/sonoff-0456/SENSOR",
            "apply": "return JSON.parse(message).ENERGY.Power;"
        },
        "getVolts": {
            "topic": "tele/sonoff-0456/SENSOR",
            "apply": "return JSON.parse(message).ENERGY.Voltage;"
        },
        "getAmperes": {
            "topic": "tele/sonoff-0456/SENSOR",
            "apply": "return JSON.parse(message).ENERGY.Current;"
        }
    },
    "history": "true",
    "logMqtt": true,
    "onValue": "ON",
    "offValue": "OFF",
    "onlineValue": "Online",
    "startPub": {
        "cmnd/sonoff-0456/power": ""
    },
    "manufacturer": "ITEAD",
    "model": "Sonoff POW",
    "serialNumber": "XXXXXXXX"
}

Thanks to deon-wentzel

Zigbee OnOff Controller

Example configuration for the Zigbee OnOff Controller (In/Out: AC 85–265V, Maxload: 250V/10A).

{
    "accessory": "mqttthing",
    "type": "switch",
    "name": "OnOffController",
    "onValue": "ON",
    "offValue": "OFF",
    "topics": {
        "getOn": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).state"
        },
        "setOn": "zigbee2mqtt/ID/set"
    }
}

Konke Multi Function Button

Model: 2AJZ4KPKEY (Single, Double and Long Click)

{
            "accessory": "mqttthing",
            "type": "statelessProgrammableSwitch",
            "name": "Konke Switch",
            "url": "mqtt://127.0.0.1",
            "logMqtt": true,
            "topics": {
                "getSwitch": {
                    "topic": "zigbee2mqtt/DeviceID",
                    "apply": "return JSON.parse(message).click"
                },
                "getBatteryLevel": {
                    "topic": "zigbee2mqtt/DeviceID",
                    "apply": "return JSON.parse(message).battery"
                }
            },
            "switchValues": [
                "single",
                "double",
                "long"
            ]
        }

Thanks to Jacob Nite! Posted by Noppie

Sonoff Basic Switch (espEasy firmware, configured for openHAB syntax MQTT)

in espEasy, section "Controllers", openHAB MQTT

Controller Subscribe: %sysname%/#
Controller Publish: %sysname%/%tskname%/%valname%

in espEasy, section "Rules"

 on button#switch do
  if [button#switch]=1
   gpio,12,1
   delay 500
   gpio,12,0
  else
   gpio,12,0
  endif
 endon

 on relay#switch do
  if [relay#switch]=1 //change this [relay#switch]=0 for LED off when relay is closed
   gpio,13,0 //or pwm,13,700
  else
   gpio,13,1 //or pwm,13,10
  endif
 endon 

on MQTT#Disconnected do
delay 6000
Reboot
endon 

When turned "On", then after 2000 ms goes "Off"

configuration at Homebridge

    "accessories": [
        {
            "type": "switch",
            "name": "Gate opener",
            "url": "mqtt://192.168.10.20:1883",
            "username": "user",
            "password": "123456",
            "logMqtt": true,
            "topics": {
                "getOnline": "twESP21/status/LWT",
                "getOn": "twESP21/Relay/Switch",
                "setOn": "twESP21/GPIO/12"
            },
            "startPub": [
                {
                    "topic": "twESP21/homebridge",
                    "message": "Starting_up"
                }
            ],
            "onlineValue": "Connected",
            "integerValue": true,
            "onValue": "1",
            "offValue": "0",
            "turnOffAfterms": 2000,
            "accessory": "mqttthing"
        }
    ],

posted by tymotim

Xiaomi MiJia Mini Button Switch

{
    "accessory": "mqttthing",
    "type": "statelessProgrammableSwitch",
    "name": "Mini Switch",
    "topics": {
        "getSwitch": {
            "topic": "zigbee2mqtt/<ID>",
            "apply": "return JSON.parse(message).click"
        },
        "getBatteryLevel": {
            "topic": "zigbee2mqtt/<ID>",
            "apply": "return JSON.parse(message).battery"
        }
    },
    "switchValues": [
        "single",
        "double",
        "long"
    ]
}

Philips Hue Switch (4 Buttons Remote without the "hue" logo)

Connected to zigbee2mqtt.

    "accessories": [
        {
            "accessory": "mqttthing",
            "type": "statelessProgrammableSwitch",
            "url": "http://192.168.86.190:1883",
            "topics": {
                "getSwitch": [
                    {
                        "topic": "zigbee2mqtt/0x00178801020d430f",
                        "apply": "var action = JSON.parse(message).action; var counter = JSON.parse(message).counter; if (action == \"on-press\") {if (counter == 1) {return \"1\"} else {return \"2\"}} else if (action == \"on-hold\") {return \"L\"};"
                    },
                    {
                        "topic": "zigbee2mqtt/0x00178801020d430f",
                        "apply": "var action = JSON.parse(message).action; var counter = JSON.parse(message).counter; if (action == \"up-press\") {if (counter == 1) {return \"1\"} else {return \"2\"}} else if (action == \"up-hold\") {return \"L\"};"
                    },
                    {
                        "topic": "zigbee2mqtt/0x00178801020d430f",
                        "apply": "var action = JSON.parse(message).action; var counter = JSON.parse(message).counter; if (action == \"down-press\") {if (counter == 1) {return \"1\"} else {return \"2\"}} else if (action == \"down-hold\") {return \"L\"};"
                    },
                    {
                        "topic": "zigbee2mqtt/0x00178801020d430f",
                        "apply": "var action = JSON.parse(message).action; var counter = JSON.parse(message).counter; if (action == \"off-press\") {if (counter == 1) {return \"1\"} else {return \"2\"}} else if (action == \"off-hold\") {return \"L\"};"
                    }
                ],
                "getBatteryLevel": {
                    "topic": "zigbee2mqtt/0x00178801020d430f",
                    "apply": "return JSON.parse(message).battery"
                }
            },
            "name": "Hue RZ Taster Bett",
            "confirmationPeriodms": 1000
        }
    ]

posted by Ron Polenthon

Tuya Zigbee Smart Dimmer

There are a few models, this configuration is tested with the touch version switch https://www.zigbee2mqtt.io/devices/TS0601_dimmer.html

{
	"type": "lightbulb-White",
	"name": "Tuya Zigbee Smart Dimmer",
	"topics": {
		"getOnline": "IsOnLine",
		"getOn": {
			"topic": "zigbee2mqtt/<DeviceID>",
			"apply": "return JSON.parse(message).state"
		},
		"setOn": "zigbee2mqtt/<DeviceID>/set",
		"getBrightness": {
			"topic": "zigbee2mqtt/<DeviceID>",
			"apply": "return Math.round(JSON.parse(message).brightness / 2.55)"
		},
		"setBrightness": {
			"topic": "zigbee2mqtt/<DeviceID>/set",
			"apply": "return JSON.stringify({brightness: Math.round(message * 2.55)})"
		}
	},
	"onlineValue": "ON",
	"offlineValue": "ON",
	"onValue": "ON",
	"offValue": "OFF",
	"accessory": "mqttthing"
}

posted by Gal Zilberman

Tuya Smart Light Switch - 2 gang

This configuration is for the TuYa TS0012 switch, You need to configure each button seperately

{
	"type": "switch",
	"name": "Right Button",
	"mqttOptions": {
		"keepalive": 30
	},
	"topics": {
		"getOn": {
			"topic": "zigbee2mqtt/<DeviceID>",
			"apply": "return JSON.parse(message).state_right"
		},
		"setOn": "zigbee2mqtt/<DeviceID>/right/set"
	},
	"onValue": "ON",
	"offValue": "OFF",
	"accessory": "mqttthing"
},
{
	"accessory": "mqttthing",
	"type": "switch",
	"name": "Left Button",
	"onValue": "ON",
	"offValue": "OFF",
	"mqttOptions": {
		"keepalive": 30
	},
	"topics": {
		"getOn": {
			"topic": "zigbee2mqtt/<DeviceID>",
			"apply": "return JSON.parse(message).state_left"
		},
		"setOn": "zigbee2mqtt/<DeviceID>/left/set"
	}
}

posted by Gal Zilberman

GARAGE DOOR OPENERS

SONOFF SV running tasmota with 2 reed switches 2 topics

  • Overview

This is a configuration example for the Sonoff SV running tasmota with 2 reed switches on its GPIOs. It is based on the use of two topics one reporting the current state (required by mqttthing getCurrentDoorState) and the target state (required by mqttthing getTargetDoorState).

It supports HomeKit and manual actions and the five states (open, closed, opening, closing, stopped). It is based on a garage door motor operated by a pulse button and/or RF remote. For these motors, multiple presses of the button between fully open or closed states will cycle between ...up/stop/down/stop/up/.... If you have a different motor this example may not work. For these motors a Sonoff Relay is connected to the garage motor terminals to trigger operation, the reed switches are placed to detect the door OPEN and CLOSED position.

  • Configuring sonoff with tasmota

Follow youtube videos on configuring tasmota and reed switches. Assign Switch2 to the GPIO of the reed switch for the closed state and Switch3 to the GPIO of the reed switch for the opened state. Make sure switchtopic is not configured or the rules won't trigger SwitchTopic 0, configure a topic for the relay garagerelay. Check your switch modes Switchmode2 2 and Switchmode3 2. Set a plusetime so the Sonoff relay emulates a push-button Pulsetime 12 (which means 1.2 seconds).

Tasmota switch transitions are compared to internal values [1,0] not [on,off] reported by console. The basic logic is:

When Switch#2 switches to 1, the door is closed, we can publish 'C' as current and 'C' as target. When Switch#2 switches to 0, the door is opening, we can publish 'o' as current and 'O' as target. When Switch#3 switches to 1, the door is fully open, we can publish 'O' as current and 'O' as target. When Switch#3 switches to 0, the door is closing, we can publish 'c' as current and 'C' as target. When Switch#2 and Switch#3 remain in 0 for too long, the door has stopped, we can publish 'S' as current and 'C' as target.

Create two rules to implement the logic, the var1 and var2 topics are used to report the current and target states to Mqttthing accessory:

Rule1 on System#Boot do backlog var1 stat/garagedoor/current; var2 stat/garagedoor/target endon on switch2#state=1 do backlog ruletimer1 0; publish2 %var2% C; publish2 %var1% C endon on switch3#state=1 do backlog ruletimer1 0; publish2 %var2% O; publish2 %var1% O endon

Rule2 on switch2#state=0 do backlog ruletimer1 20; publish2 %var2% O; publish2 %var1% o endon on switch3#state=0 do backlog ruletimer1 20; publish2 %var2% C; publish2 %var1% c endon on Rules#timer=1 do backlog publish2 %var2% C; publish2 %var1% S endon

Notes: In the rules, timer1 is there to detect a stopped status and publish2 is used to send retained messages to the broker (otherwise Mqttthing will be lost on homebridge restart). On timer1 expiration, rule2 publishes 'C' as target state, changing this to 'O' will change the behaviour of the home app icon. Enable the rules rule1 1 and rule2 1 and reboot so the topics are stored in memory after system reboot.

Test the correct behaviour with an MQTT client like Mqttbox. This is to validate the correct publication to the topics before homebridge integration.

  • Configuring the mqtthing accessory

Copy the below and replace where instructed. logMqtt and history can be set to false; model/manufacturer/serial/firmware can be omitted.

It is recommended to leave logMqtt to true and monitor the homebridge console to check everything is working.

The apply function of setTargetDoorState will prevent Siri or HomeKit from opening an already opened door or closing and already closed door. In the example, when nothing is to be done, nothing will be sent return undefined. By replacing return undefined by return 'OFF' will tell Mqttthing send an Mqtt message that will have no effect; might be useful for debugging.

    {
        "type": "garageDoorOpener",
        "name": "Garage Door",
        "url": "broker_ip_address:1883",
        "username": "your_mqtt-username",
        "password": "your_password",
        "logMqtt": true,
        "topics": {
            "getTargetDoorState": "stat/garagedoor/target",
            "getCurrentDoorState": {
                "topic": "stat/garagedoor/current",
                "apply": "if(message=='C' || message=='O') state.global.doorPosition=message; return message;"
            },
            "setTargetDoorState": {
                "topic": "cmnd/garagerelay/POWER",
                "apply": "if (state.global.doorPosition==message) return undefined; return 'ON'"
            }
        },
        "history": true,
        "manufacturer": "Sonoff",
        "model": "Sonoff SV",
        "serialNumber": "mac_address_or_reference",
        "firmwareRevision": "8.5.0",
        "accessory": "mqttthing"
    },

When everything is working backup the tasmota configuration!

Posted by ceraz68, special thanks to jdtsmith

SONOFF SV running tasmota with 2 reed switches 1 topic

  • Overview

This is a configuration example for the Sonoff SV running tasmota with 2 reed switches on its GPIOs. It is based on the use of a single topic reporting the current state.

It supports HomeKit and manual actions and the five states (open, closed, opening, closing, stopped). It is based on a garage door motor operated by a pulse button and/or RF remote. For these motors, multiple presses of the button between fully open or closed states will cycle between ...up/stop/down/stop/up/.... If you have a different motor this example may not work. For these motors a Sonoff Relay is connected to the garage motor terminals to trigger operation, the reed switches are placed to detect the door OPEN and CLOSED position.

  • Configuring sonoff with tasmota

Follow youtube videos on configuring tasmota and reed switches. Assign Switch2 to the GPIO of the reed switch for the closed state and Switch3 to the GPIO of the reed switch for the opened state. Make sure switchtopic is not configured or the rules won't trigger SwitchTopic 0, configure a topic for the relay garagerelay. Check your switch modes Switchmode2 2 and Switchmode3 2. Set a plusetime so the Sonoff relay emulates a push-button Pulsetime 12 (which means 1.2 seconds).

Tasmota switch transitions are compared to internal values [1,0] not [on,off] reported by console. The basic logic is:

When Switch#2 switches to 1, the door is closed, we can publish 'C'. When Switch#2 switches to 0, the door is opening, we can publish 'o'. When Switch#3 switches to 1, the door is fully open, we can publish 'O'. When Switch#3 switches to 0, the door is closing, we can publish 'c'. When Switch#2 and Switch#3 remain in 0 for too long, the door has stopped, we can publish 'S'.

Create two rules to implement the logic, the var1 topic is used to report the current state to Mqttthing accessory:

Rule1 on System#Boot do var1 stat/garagedoor/current endon on switch2#state=1 do backlog ruletimer1 0; publish2 %var1% C endon on switch3#state=1 do backlog ruletimer1 0; publish2 %var1% O endon

Rule2 on switch2#state=0 do backlog ruletimer1 20; publish2 %var1% o endon on switch3#state=0 do backlog ruletimer1 20; publish2 %var1% c endon on Rules#timer=1 do publish2 %var1% S endon

Notes: In the rules, timer1 is there to detect a stopped status and publish2 is used to send retained messages to the broker (otherwise Mqttthing will be lost on homebridge restart). Enable the rules rule1 1 and rule2 1 and reboot so the topic is stored in memory after system reboot.

Test the correct behaviour with an MQTT client like Mqttbox. This is to validate the correct publication to the topics before homebridge integration.

  • Configuring the mqtthing accessory

Copy the below and replace where instructed. logMqtt and history can be set to false; model/manufacturer/serial/firmware can be omitted.

It is recommended to leave logMqtt to true and monitor the homebridge console to check everything is working.

The apply function of setTargetDoorState will prevent Siri or HomeKit from opening an already opened door or closing and already closed door. In the example, when nothing is to be done, nothing will be sent return undefined. By replacing return undefined by return 'OFF' will tell Mqttthing send an Mqtt message that will have no effect; might be useful for debugging.

An apply function needs to be configured to convert values [o, c, S] for getTargetDoorState as it only understands ['O', 'C']. Converting 'S' to 'O' will change the icon on the home app.

    {
        "type": "garageDoorOpener",
        "name": "Garage Door",
        "url": "broker_ip_address:1883",
        "username": "your_mqtt_username",
        "password": "your_password",
        "logMqtt": true,
        "topics": {
            "getTargetDoorState": {
                "topic": "stat/garagedoor/current",
                "apply": "if(message=='o') message='O'; if(message=='c' || message=='S') message='C'; return message;"
            },
            "getCurrentDoorState": {
                "topic": "stat/garagedoor/current",
                "apply": "if(message=='C' || message=='O') state.global.doorPosition=message; return message;"
            },
            "setTargetDoorState": {
                "topic": "cmnd/garagerelay/POWER",
                "apply": "if (state.global.doorPosition==message) return undefined; return 'ON'"
            }
        },
        "history": true,
        "manufacturer": "Sonoff",
        "model": "Sonoff SV",
        "serialNumber": "mac_address_or_reference",
        "firmwareRevision": "8.5.0",
        "accessory": "mqttthing"
    },

When everything is working backup the tasmota configuration!

Posted by ceraz68, special thanks to jdtsmith

Shelly1 Plus with Reed Switch at Bottom of Door

This setup with a Shelly1 Plus works well. Configure the Shelly relay with a timer (0.5s works for me), and the input as "Detached". With only one reed switch, you cannot see closing begin if initiated from the garage button/car remote. We use a CODEC to simulate this:

Place this as garage.js alongside your config.json (e.g. in /var/lib/homebridge/):

module.exports = {
  init: function(params) {
    var state = "c"; // probably a good guess
    let {log, notify} = params;
    return {
      encode( message, info, output ) {
	if (info.property.endsWith("targetDoorState")) {
	  if (state.toUpperCase() == message) {
	    log(`ignoring topic [${info.topic}], property [${info.property}] with message [${message}]: already set`);
	    return undefined;
	  }
	  log(`encode topic [${info.topic}], property [${info.property}] with message [${message}]`);
          return "on";
	} else {
	  return undefined;
	}
      },
      
      decode( message, info, output ) {
	let closed = JSON.parse(message).state; // reed switch closed
	if (info.property.endsWith("targetDoorState")) {
	  state = closed?"C":"O";
	} else {
	  if (closed) { // it actually already closed, we pretend it's very fast
	    setTimeout(()=>{notify(output('C'))}, 5e2);
	  } else {
	    setTimeout(()=>{notify(output('O'))}, 13e3);
	  }
	  state = closed?"c":"o";
	}
	log(`set saved state to [${state}]`);
	return state;
      }
    }
  }
}

and configure as (substituting your topic base name for shellies/shellyplus1-garage):

{
            "accessory": "mqttthing",
            "type": "garageDoorOpener",
            "name": "ShellyGarage",
            "logMqtt": true,
            "topics": {
                "setTargetDoorState": "shellies/shellyplus1-garage/command/switch:0",
                "getTargetDoorState": "shellies/shellyplus1-garage/status/input:0",
                "getCurrentDoorState": "shellies/shellyplus1-garage/status/input:0"
            },
            "codec": "garage.js"
        },

Tested with Shelly firmware 20240522-112837/1.3.2-g34c651b.

Shelly1 Came ZA3 Door Opener

A Simple Door Opener wired on a Came ZA3 board.

Connect SW to the E3 pin to get the door status and detach the SW input from the relay. In this case, the ZA3 is configured with an automatic closing timer, so we do not need to send a closure request

If you have a ShellySwitch2.5 you could use the E pin as SW2 to notice the Opening/Closing status

     {
            "accessory": "mqttthing",
            "name": "ZA3 Door",
            "type": "garageDoorOpener",
            "url": "url",
            "username": "username",
            "password": "password",
            "topics": {
                "getTargetDoorState": {
                    "topic": "shellies/shelly1-C45BBE56XXXX/input/0",
                    "apply": "if (message == 1) { return 'o';} return 'C';"
                },
                "getCurrentDoorState": {
                    "topic": "shellies/shelly1-C45BBE56XXXX/input/0",
                    "apply": "if (message == 1) { return 'O';} return 'C';"
                },
                "setTargetDoorState": {
                    "topic": "shellies/shelly1-C45BBE56XXXX/relay/0/command",
                    "apply": "if (message == 'O') {return 'on'} ; return 'off';"
                }
            },
            "doorCurrentValues": [
                "O",
                "C",
                "o",
                "c",
                "S"
            ],
            "doorTargetValues": [
                "O",
                "C"
            ],
            "logMqtt": true
        }

Ferme-de-Pommerieux

ShellySwitch25 Roller Shutter

  • Connect SW1 to the close wire and SW2 to the open wire of your shutter roller.
  • Set ShellySwitch25 device type in Roller Shutter Mode and the open/close working time to a reasonable value.
  • Calibrate your roller Shutter with the Shelly

download this Shelly25roller.js codec and install it in your home bridge config directory

       {
             
            "name": "Shelly25Roller",
            "accessory": "mqttthing",
            "url": "url",
            "username": "user",
            "password": "passwd",
            "type": "garageDoorOpener",
            "codec": "Shelly25Roller.js",
            "Shelly25Roller": {
            	"setState": {
            		"Target": {
            			"topic": "shellies/shellyswitch25-84CCA89FXXXX/roller/0/command",
            			"open": "open",
            			"close": "close",
            			"stop": "stop"
            			}
            	},
            	"getState": {
            		"Target": {
            		   "topic": "shellies/shellyswitch25-84CCA89FXXXX/roller/0/command",
            			"open": "open",
            			"close": "close"
            			},
            		"Current": {
            			"topic": "shellies/shellyswitch25-84CCA89FXXXX/roller/0",
            			"INACTIVE": "stop"
            			},
            		"Obstruction": {
            			"topic": "shellies/shellyswitch25-84CCA89FXXXX/roller/0/stop_reason",
            			"INACTIVE": "normal"
            			},
            		"Lock": {
            			"topic": "shellies/shellyswitch25-84CCA89FXXXX/roller/0/pos",
            			"ACTIVE": 0, // requires calibration
            			"INACTIVE": 100 // requires calibration
            			}
            	}
            },
            "logMqtt": true
    }

Ferme-de-Pommerieux

Heaters-and-Coolers

Tasmota based IR Blaster

Air Conditioners and Heat Pumps can be controlled with a Tasmota based MQTT IR Blaster. In this case, it is configured for a Mitsubishi HVAC, but could be almost any supported device. This code does not update fan speed, but should be easy to add. This code uses apply functionality without needing to use a CODEC.

        {
            "type": "heaterCooler",
            "name": "HVAC",
            "url": "mqtt://localhost:1883",
            "username": "user",
            "password": "pass",
            "logMqtt": true,
            "topics": {
                "setActive": {
                    "topic": "cmnd/tasmota_98D849/IRhvac",
                    "apply": "state.global.HVAC = state.global.HVAC || {}; state.global.HVAC.Power = message; state.global.HVAC.Protocol = 'MITSUBISHI112'; state.global.HVAC.FanSpeed = 3; return (JSON.stringify(state.global.HVAC));"
                },
                "getActive": "<topic used to report 'active' state>",
                "getCurrentHeaterCoolerState": "<topic used to report 'current heater/cooler state'>",
                "setTargetHeaterCoolerState": {
                    "topic": "cmnd/tasmota_98D849/IRhvac",
                    "apply": "state.global.HVAC = state.global.HVAC || {}; state.global.HVAC.Mode = message; return (JSON.stringify(state.global.HVAC));"
                },
                "getTargetHeaterCoolerState": "<topic used to report 'target heater/cooler state'>",
                "getCurrentTemperature": "<topic used to report 'current temperature'>",
                "setCoolingThresholdTemperature": {
                    "topic": "cmnd/tasmota_98D849/IRhvac",
                    "apply": "state.global.HVAC = state.global.HVAC || {}; state.global.HVAC.Temp = message; return (JSON.stringify(state.global.HVAC));"
                },
                "getCoolingThresholdTemperature": "<topic used to report 'cooling threshold temperature'>",
                "setHeatingThresholdTemperature": {
                    "topic": "cmnd/tasmota_98D849/IRhvac",
                    "apply": "state.global.HVAC = state.global.HVAC || {}; state.global.HVAC.Temp = message; return (JSON.stringify(state.global.HVAC));"
                },
                "getHeatingThresholdTemperature": "<topic used to report 'heating threshold temperature'>",
                "setTemperatureDisplayUnits": "<topic used to control 'temperature display units'>",
                "getTemperatureDisplayUnits": "<topic used to report 'temperature display units'>",
                "setRotationMode": "<topic used to control 'rotation mode' (optional)>",
                "getRotationMode": "<topic used to report 'rotation mode' (optional)>",
                "setSwingMode": "<topic used to control 'swing mode' (optional)>",
                "getSwingMode": "<topic used to report 'swing mode' (optional)>",
                "setRotationSpeed": {
                    "topic": "cmnd/tasmota_98D849/IRhvac",
                    "apply": "state.global.HVAC = state.global.HVAC || {}; state.global.HVAC.FanSpeed = 3; return (JSON.stringify(state.global.HVAC));"
                },
                "getRotationSpeed": "<topic used to report 'rotation speed' (optional)>"
            },
            "accessory": "mqttthing",
            "minTemperature": 16,
            "maxTemperature": 30,
            "restrictHeaterCoolerState": [
                1,
                2
            ]

Posted by vk2tds

LOCK MECHANISM

ShellyPro4PM as a Lock Mechanism with a Fence Energizer

Analyzing the consumption of a fence energizer helps to find out what state the energizer is in: Running, Standby, Fault. The apower and aenergy.by_minute data of a ShellyXXPM are used to verify if the energizer is using enough power to secure the fence.

Note : You need to enable Generic status update over MQTT on the ShellyPro4PM

Lock Mechanism states:

LockTargetState could be:

  • Unsecured: 'U': false
  • Secured: 'S': true

LockCurrentState could be:

  • Unsecured: 'U': output == off
  • Jammed: 'J': output == true and aenergy.by_minute[1] < 420 and apower > 26 : this occurs when the energizer is in standby mode (user remote control)
  • Secured: 'S': output == true and aenergy.by_minute[1] > 420
  • Unknown: '?': output == true and aenergy.by_minute[1] < 420 and apower < 26 : this occurs when the energizer is in fault

Note: These values ​​are for a 63000RS Speedrite equipped with an additional cooling system. If HomeKit reports too many blocked / secure state change, decrease the minimum apower value.

Configuration:

        {
            "type": "lockMechanism",
            "name": "Electric Fence",
            "url": "url",
            "username": "username",
            "password": "password",
            "logMqtt": false,
            "topics": {
                "getLockTargetState": {
                    "topic": "shellypro4pm-84cca87fXXXX/status/switch:0",
                    "apply": "function Target_State(is_on) { if (is_on === true) { return 'S';} else {return 'U';}}; return Target_State(JSON.parse(message).output);"
                },
                "getLockCurrentState": {
                    "topic": "shellypro4pm-84cca87fXXXX/status/switch:0",
                    "apply": "function Current_State(Wm, W, is_on) { if (is_on === false) { return 'U';} else if ((W >= 26.5)&&(Wm <= 420)&&(is_on === true)) {return 'J';} else if (W <= 26.5) {return '?';} else {return 'S';}}; let WmArray = JSON.parse(message).aenergy.by_minute; return Current_State(WmArray[1], JSON.parse(message).apower, JSON.parse(message).output);"
                },
                "setLockTargetState": {
                    "topic": "shellypro4pm-84cca87fXXXX/rpc",
                    "apply": "function m_m(value) { if (value === 'S') {return true;} else if ( value === 'U') { return false;} else if ( value === 'J') { return false;} else if ( value === '?') { return false;} else {return value;}}; let message_m = m_m(message); return JSON.stringify({id: 123, src: 'user_1', method: 'Switch.Set', params: {id: 0, on: message_m}});"
                }
        },

You could also add:

  • a leak sensor to be probe when the energizer consumes less than 420W.min to report an issue in Homekit
  • a light sensor to report an approximative idea of the electric chock sent by the energizer
  • a contact sensor to be probe when the energizer is in FullPowerMode (Speedrite 63000RS)
    {
    "accessory": "mqttthing",
    "type": "custom",
    "name": "Some adds"
    "services": [
        {
            "type": "leakSensor",
            "name": "Speedrite 63000 RS Error",
            "topics": {
                "getLeakDetected": {
                    "topic": "shellypro4pm-84cca87fXXXX/status/switch:0",
                    "apply": "let WmArray = JSON.parse(message).aenergy.by_minute; if (WmArray[1] <= 420) { return true;} else {return false;}"
                }
            }
        },
        {
            "accessory": "mqttthing",
            "type": "lightSensor",
            "name": "Speedrite 63000 RS",
            "topics": {
                "getCurrentAmbientLightLevel": {
                    "topic": "shellypro4pm-84cca87fXXXX/status/switch:0",
                    //The value returned by .aenergy.by_minutes[1 or 2] must be multiplied by 60 to be in Joules.
                    //Then I assume the energizer send 1 pulse every 2.6s, witch means 23 pulses per minute.
                    //The energizer lost a minimum of 420J per minutes in standby mode, and it lost again 782J in full-service
                    //The lost in full-service is calculated as it: (97J stocked - 63J max output)*23 = 782J per minutes
                    //The formula is then (aenergy.by_minutes[1]*60-(420+782)/60/23
                    //But, this also include the power the energizer needs to charge it's capacitor, I need to calibrate it:
                    // Minimum is 31 (no load), maximum in short circuit is 62, the formula becomes ((aenergy.by_minutes[1]*60-(420+782)/60/23-31)/31*63
                    //A funny thing about this rough calculation is that the values found are not far from the measurements made with a joule-meter,
                    //and the results in heavy load is around 60J which is less than the maximum output power of this energizer (63J).
                    "apply": "let WmArray = JSON.parse(message).aenergy.by_minute; state.global.Fence_Pulse_power = Math.ceil(((((WmArray[1]*60-(420+782))/60/23)-31)/31)*63); if (Pulse_power < 0.0001) Pulse_power = 0.0001; return Pulse_power;"
                }
            }
        },
        {
            "accessory": "mqttthing",
            "type": "contactSensor",
            "name": "Speedrite 63000 RS FullPOWER",
            "topics": {
                "getContactSensorState": {
                    "topic": "shellypro4pm-84cca87fXXXX/status/switch:0",
                    // same as upper, however the output power must exceed the 80% of the maximum output power
                            "apply": "let WmArray = JSON.parse(message).aenergy.by_minute; if (((((WmArray[1]*60-(420+782))/60/23)-31)/31) >= 0.8) { return true;} else {return false;}"

                }
            }
        }
    ]
}

Ferme-de-Pommerieux

SECURITY SYSTEM

ShellyUni as a Security System with a Bosch AMAX 4000

The control of a BOSH AMAX security system requires to be able to control the arming and to know when the system is armed and possibly when an intrusion is detected. This requires adding a new zone in the AMAX to allow a safety key switch and configuring an output relay which will be activated when the system will be armed. In order not to block the security system, we must add a pulse switch which will change the state of the system at each pulse and allow control from the keypad.

Connect your Shelly to the AMAX as it :

  • input0 to probe the ARMED/DISAMED relay
  • input1 to probe the triggered relay
  • one I/O to the Zone of the safety key switch (take care to set Auto-OFF to 1s)

you need to add this ShellyAMAX codec to /var/lib/homebridge

   
{
            "name": "AMAX",
            "accessory": "mqttthing",
            "url": "url",
            "username": "user",
            "password": "passed",
            "type": "securitySystem",
            "codec": "ShellyAMAX.js",
            "ShellyGen": 1,
            "AMAX": {
                "ArmingDelay": 90,
                "setState": {
                    "Armed": {
                        "name": "shellies/shellyuni-XX",
                        "id": 0,
                        "ACTIVE": "on"
                    },
                    "Disarmed": {
                        "name": "shellies/shellyuni-XX",
                        "id": 0,
                        "ACTIVE": "on"
                    }
                },
                "getState": {
                    "Armed": {
                        "name": "shellies/shellyuni-XX",
                        "id": 0,
                        "ACTIVE": 0
                    },
                    "Triggered": {
                        "name": "shellies/shellyuni-XX",
                        "id": 1,
                        "ACTIVE": 0
                    },
                    "AltTriggered": {
                        "name": "shellies/shellyuni-XX", // set to null if you don't use an alternate sensor
                        "id": 1,
                        "ACTIVE": 0
                    }
                }
            },
            "targetStateValues": [
                "SA",
                "AA",
                "NA",
                "D"
            ],
            "currentStateValues": [
                "SA",
                "AA",
                "NA",
                "D",
                "T"
            ],
            "restrictTargetState": [
                1,
                3
            ],
            "logMqtt": true
        }   

OUTLETS AND PLUGS

GOSUND SP111 V1.1 / Blitzwolf BW-SHP2

Configuration for GOSUND SP111 plug.

 {
            "type": "outlet",
            "name": "stecki3",
            "username": "home",
            "password": "000",
            "mqttPubOptions": {
                "retain": true
            },
            "topics": {
                "getInUse": "tele/stecki3/STATE",
                "getOn": "stat/stecki3/POWER",
                "setOn": "cmnd/stecki3/POWER",
                "getWatts": {
                    "topic": "tele/stecki3/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Power;"
                },
                "getVolts": {
                    "topic": "tele/stecki3/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Voltage;"
                },
                "getAmperes": {
                    "topic": "tele/stecki3/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Current;"
                }
            },
            "history": "true",
            "onValue": "ON",
            "offValue": "OFF",
            "startPub": [
                {
                    "topic": "cmnd/stecki3/POWER",
                    "message": "ON"
                },
                {
                    "topic": "stat/stecki3/POWER",
                    "message": ""
                }
            ],
            "mqttOptions": {
                "keepalive": 30
            },
            "logMqtt": true,
            "onlineValue": "Online",
            "manufacturer": "Gosund",
            "model": "SP111 1.1",
            "serialNumber": "192.168.178.40",
            "accessory": "mqttthing"
        }

Innr SmartPlug SP 120

Configuration for Innr SmartPlug SP 120. Tested with zigbee2mqtt as bridge.

{
    "accessory": "mqttthing",
    "type": "outlet",
    "name": "Lichterkette",
    "topics": {
        "getOn": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).state"
        },
        "setOn": "zigbee2mqtt/ID/set",
        "getInUse": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).state"
        },
        "getWatts": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).power"
        },
        "getVolts": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).voltage"
        },
        "getAmperes": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).current"
        }
    },
    "onValue": "ON",
    "offValue": "OFF",
    "history": "true"
}

This configuration sets the "outlet in use" property to true, if the outlet is on and to false if the outlet is off. To set the "outlet in use" property based on energy consumption, replace getInUse in the configuration with the following value. This snipped sets "outlet in use" to true if the energy consumption is greater then 10 Watt. You can replace the "10" with your own value.

"getInUse": {
    "topic": "zigbee2mqtt/ID",
    "apply": "return (JSON.parse(message).power > 10) ? 'ON' : 'OFF'"
},

TGWF115APM TOPGREENER energy monitoring plug

  "accessories": [
        {
            "type": "outlet",
            "name": "TGWF115APM",
            "logMqtt": true,
            "history": "true",
            "onValue": "ON",
            "offValue": "OFF",
            "startCmd": "cmnd/TGWF115APM/POWER1",
            "startParameter": "",
            "integerValue": "false",
            "mqttOptions": {
                "keepalive": 30
            },
            "mqttPubOptions": {
                "retain": false
            },
            "topics": {
                "getWatts": {
                    "topic": "tele/TGWF115APM/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Power;"
                },
                "getVolts": {
                    "topic": "tele/TGWF115APM/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Voltage;"
                },
                "getAmperes": {
                    "topic": "tele/TGWF115APM/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Current;"
                },
                "getTotalConsumption": {
                    "topic": "tele/TGWF115APM/SENSOR",
                    "apply": "return JSON.parse(message).ENERGY.Total;"
                },
                "getInUse": {
                    "topic": "tele/TGWF115APM/SENSOR",
                    "apply": "return (JSON.parse(message).ENERGY.Power > 2) ? 'ON' : 'OFF'"
                },
                "getOn": "stat/TGWF115APM/POWER",
                "setOn": "cmnd/TGWF115APM/POWER"
            },
            "accessory": "mqttthing"

Everything working in Eve app on Tasmota 8.50 for this TOPGREENER energy monitoring plug

SENSORS: AIR QUALITY AND CARBON DIOXIDE

Sonoff Tasmota CCS881

Sonoff-Tasmota CO2 & Air Quality Sensor with CCS881. Edit your in Tasmota configured mqtt topic, this example uses: wemos-d1-mini-wz.

Carbon Dioxide

{
    "accessory": "mqttthing",
    "type": "carbonDioxideSensor",
    "name": "CO2 CCS811",
    "logMqtt": "true",
    "topics": {
        "getCarbonDioxideDetected": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return (JSON.parse(message).CCS811.eCO2 <= 1100 ? 'NORMAL' : 'ABNORMAL');"
        },
        "getCarbonDioxideLevel": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).CCS811.eCO2;"
        }
    },
    "carbonDioxideDetectedValues": [ "NORMAL", "ABNORMAL" ]
}

Air Quality Sensor

{
    "accessory": "mqttthing",
    "type": "airQualitySensor",
    "name": "Luftqualität CCS811",
    "serviceNames": {
        "temperature": "Temperatur BME280",
        "humidity":    "Luftfeuchtigkeit BME280"
    },
    "logMqtt": "true",
    "topics": {
        "getAirQuality": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "eco2 = JSON.parse(message).CCS811.eCO2; return (eco2 > 2000 ? 'POOR' : eco2 > 1600 ? 'INFERIOR' : eco2 > 1100 ? 'FAIR' : eco2 > 700 ? 'GOOD' : eco2 <= 700 ? 'EXCELLENT' : 'UNKNOWN');"
        },
        "getAirQualityPPM": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).CCS811.eCO2;"
        },
        "getCurrentTemperature": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).BME280.Temperature;"
        },
        "getCurrentRelativeHumidity": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).BME280.Humidity;"
        },
        "getCarbonDioxideLevel": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).CCS811.eCO2;"
        }
    },
    "airQualityValues": [ "UNKNOWN", "EXCELLENT", "GOOD", "FAIR", "INFERIOR", "POOR" ],
    "history": "true"
}

Thanks to @nicoh88

Ikea Vindriktning

mp2.5 sensor mod with esp8266 board running Tasmota find your specific topic in the console behind the correct readings

Air Quality Sensor mp2.5 Ikea mod esp8266

{
            "type": "airQualitySensor",
            "name": "pm 2.5",
            "url": "0.0.0.0:1883",
            "username": "....",
            "password": "....",
            "mqttOptions": {
                "keepalive": 30
            },
            "mqttPubOptions": {
                "retain": false
            },
            "logMqtt": false,
            "optimizePublishing": true,
            "topics": {
                "getAirQuality": {
                    "topic": "tele/tasmota/SENSOR",
                    "apply": "return (JSON.parse(message).VINDRIKTNING['PM2.5'] > 86 ? 'POOR' : JSON.parse(message).VINDRIKTNING['PM2.5']          > 55? 'INFERIOR' : JSON.parse(message).VINDRIKTNING['PM2.5'] > 12 ? 'FAIR' : JSON.parse(message).VINDRIKTNING['PM2.5'] > 4 ? 'GOOD' : JSON.parse(message).VINDRIKTNING['PM2.5'] <= 3 ? 'EXCELLENT' : 'UNKNOWN');"
                },
                "getOnline": "tele/tasmota/LWT",
                "getPM2_5Density": "tele/tasmota/SENSOR$.VINDRIKTNING..*"
            },
            "confirmationPeriodms": 500,
            "integerValue": true,
            "airQualityValues": [
                "UNKNOWN",
                "EXCELLENT",
                "GOOD",
                "FAIR",
                "INFERIOR",
                "POOR"
            ],
            "accessory": "mqttthing"
        }

thanks to @ItzAPranko

Sensirion SPS30

Air Quality Sensor (PM2.5 and PM10) with Tasmota-based controller

Below Tasmota MQTT topic is set to SPS30.

        {
            "accessory": "mqttthing",
            "type": "airQualitySensor",
            "name": "SPS30",
            "url": "mqtt://127.0.0.1:1883",
            "mqttOptions": {
                "keepalive": 30
            },
            "mqttPubOptions": {
                "retain": false
            },
            "logMqtt": false,
            "optimizePublishing": true,
            "topics": {
                "getAirQuality": {
                    "topic": "tele/SPS30/SENSOR",
                    "apply": "pm25 = JSON.parse(message).SPS30.PM2_5; return (pm25 > 86 ? 'POOR' : pm25 > 55? 'INFERIOR' : pm25 > 12 ? 'FAIR' : pm25 > 4 ? 'GOOD' : pm25 <= 3 ? 'EXCELLENT' : 'UNKNOWN');"
                },
                "getOnline": "tele/SPS30/LWT",
                "getPM10Density": "tele/SPS30/SENSOR$.SPS30.PM10",
                "getPM2_5Density": "tele/SPS30/SENSOR$.SPS30.PM2_5"
            },
            "confirmationPeriodms": 500,
            "integerValue": true,
            "airQualityValues": [
                "UNKNOWN",
                "EXCELLENT",
                "GOOD",
                "FAIR",
                "INFERIOR",
                "POOR"
            ],
            "startPub": [
                {
                    "topic": "cmnd/SPS30/teleperiod",
                    "message": ""
                }
            ]
        }

SENSORS: CONTACT AND MOTION

IKEA TRADFRI Motion Sensor

Configuration for IKEA TRADFRI Motion Sensor - Occupancy.

The sensor is connected to an USB Zigbee sniffer (CC2531) and communicate with the mqtt server via zigbee2mqtt.

{
    "accessory": "mqttthing",
    "type": "occupancySensor",
    "name": "IKEA motion sensor",
    "topics": {
        "getOccupancyDetected": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).occupancy;"
        },
        "getBatteryLevel": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).battery;"
        }
    },
    "integerValue": true,
    "logMqtt": true
}

Replace <deviceID> with your paired device ID.

thanks to danielmarcinkowski, based on alexair777's intergration with Philips Hue Motion Sensor

Philips Hue Motion Sensor

Configuration for Philips Hue Motion Sensor - Occupancy, Temperature and Light Intensity Sensor.

The tested configuration uses a javascript function to transform the zigbee2mqtt received message structure into the appropriate get message structure of the homebridge-mqttthing plugin. Philips measured light level is transferred through the formula:

Math.pow(10, (measuredValue - 1)/10000) -> lux

The sensor is connected to an USB Zigbee sniffer (CC2531) and communicate with the mqtt server via zigbee2mqtt.

{
    "accessory": "mqttthing",
    "type": "occupancySensor",
    "name": "PHILIPS Occupancy",
    "topics": {
    "getOccupancyDetected": {
    "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).occupancy;"
            },
    "getBatteryLevel": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).battery;"
            }  
    }, 
    "integerValue": true,
    "logMqtt": true
},
{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "PHILIPS Temperature",
    "topics": {
    "getCurrentTemperature": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).temperature;"
            },
    "getBatteryLevel": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).battery;"
            }   
    }, 
    "logMqtt": true
},
{
    "accessory": "mqttthing",
    "type": "lightSensor",
    "name": "PHILIPS Light Intensity",
    "topics": {
    "getCurrentAmbientLightLevel": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return Math.pow(10, (JSON.parse(message).illuminance - 1)/10000);"
            } ,
    "getBatteryLevel": {
            "topic": "zigbee2mqtt/<deviceID>",
            "apply": "return JSON.parse(message).battery;"
            }  
    }, 
    "logMqtt": true
}

Replace <deviceID> with your paired device ID.

thanks to alexair777

Xiaomi Contact Sensor

This is for the original version (Mijia), but it will probably work with the Aqara version as well.

{
    "accessory": "mqttthing",
    "type": "contactSensor",
    "history": true,
    "name": "Door sensor",
    "topics": {
        "getContactSensorState": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return !(JSON.parse(message).contact);"
        },
        "getStatusLowBattery": {
            "topic": "zigbee2mqtt/ID",
            "apply": "if (JSON.parse(message).battery < 20) return 1; else return 0;"
        },
        "getBatteryLevel": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return JSON.parse(message).battery;"
        }
    },
    "integerValue": true
}

LSC Smart Connect Movement Sensor

Cheap battery-powered PIR sensor (Tuya based) from Action.

Device reflashed with Tasmota (v8.1.0) with configured WiFi, MQTT and setted configuration:

module 54

backlog TuyaMcu 11,1; TuyaMcu 51,51; TuyaMcu 12,3

rule1 ON Wifi#Connected DO backlog serialsend5 55 AA 00 01 00 00 00; delay 10; serialsend5 55 AA 00 02 00 01 04 06; delay 3; serialsend5 55 AA 00 05 00 01 00 05; ENDON

rule2 ON TuyaReceived#Data=55aa000200000155aa0005000501040001000f DO POWER ON; delay 1; DO POWER OFF ENDON

restart 1

Rule3 ON TuyaReceived#Data=55AA00050005030400010213 DO publish2 stat/%topic%/BATT high ENDON ON TuyaReceived#Data=55AA00050005030400010114 DO publish2 stat/%topic%/BATT medium ENDON ON TuyaReceived#Data=55AA00050005030400010015 DO publish2 stat/%topic%/BATT low ENDON

Rule3 1

mqttthing configuration:

        {
            "accessory": "mqttthing",
            "type": "motionSensor",
            "name": "lsc pir sensor",
            "url": "mqtt://IP_ADDRESS",
            "username": "USER_NAME",
            "password": "PASSWORD",
            "caption": "lsc pir sensor",
            "topics": {
                "getMotionDetected": "stat/tasmota/POWER2"
            },
            "integerValue": false,
            "onValue": "ON",
            "offValue": "OFF",
            "turnOffAfterms": "90000",
            "history": false
        }

Remember to update the above configuration with your values for: IP_ADDRESS, USER_NAME, PASSWORD and DEVICE_NAME.

TurnOffAfterms is set to 90000 because device is controlled by MCU's timmer.

Wyze Contact Sensor

The sensor is connected to the USB dongle Wyze includes in their sensor kit to a device running ha-gosesne app. Once ha-gosenseapp is installed, you can use hostname.local:8080/sensors to find the device ID.

{
	"accessory": "mqttthing",
	"type": "contactSensor",
	"name": "Window Sensor",
	"url": "192.168.1.10:1883",
	"username": "admin",
	"password": "asdf1234",
	"logMqtt": true,
	"topics": {
	    "getContactSensorState": {
	        "topic": "gosense/<deviceID>",
	        "apply": "return JSON.parse( message ).properties.state;"
	    }
	},
	"integerValue": true,
	"onValue": "1",
	"offValue": "0"
}

Xiaomi Aqara (occupancy and illuminance) (Xiaomi RTCGQ11LM)

Pairing # Press and hold the reset button on the device for +- 5 seconds (until the blue light starts blinking). After this the device will automatically join. If this doesn’t work, try with a single short button press.

{
            "type": "occupancySensor",
            "name": "Sensor occupancy1",
            "url": "mqtt://IP_mqtt:1883",
            "accessory": "mqttthing",
            "logMqtt": true,
            "topics": {
                "getOccupancyDetected": {
                    "topic": "zigbee2mqtt/<ID>",
                    "apply": "return JSON.parse(message).occupancy;"
                },
                "getStatusLowBattery": {
                    "topic": "zigbee2mqtt/<ID>",
                    "apply": "if (JSON.parse(message).battery < 20) return 1; else return 0;"
                },
                "getBatteryLevel": {
                    "topic": "zigbee2mqtt/<ID>",
                    "apply": "return JSON.parse(message).battery;"
                }
            },
            "integerValue": true
        }

Tuya TS0601 Smart Human presence sensor

Occupancy and Light Sensors I managed to get 2 occupany zones by setting it according to distance

https://www.zigbee2mqtt.io/devices/TS0601_smart_human_presence_sensor.html

{
	"type": "occupancySensor",
	"name": "TuYa TS0601 Smart Human Presence Sensor",
	"topics": {
		"getOccupancyDetected": {
			"topic": "zigbee2mqtt/<deviceID>",
			"apply": "return JSON.parse(message).presence;"
		}
	},
	"accessory": "mqttthing"
},
        {
            "type": "lightSensor",
            "name": "TuYa TS0601 Smart Human Presence Sensor lux",
            "logMqtt": false,
            "topics": {
                "getCurrentAmbientLightLevel": {
                    "topic": "zigbee2mqtt/<deviceID>",
                    "apply": "return Math.round (JSON.parse(message).illuminance_lux);"
                }
            },
            "accessory": "mqttthing"
        },
{
            "type": "occupancySensor",
            "name": "Kitchen Presence Sensor",
            "logMqtt": false,
            "topics": {
                "getOccupancyDetected": {
                    "topic": "zigbee2mqtt/<deviceID>",
                    "apply": "if (JSON.parse(message).target_distance > 0) { return JSON.parse(message).target_distance < 2.5 ? 'true' : 'false'; } else { return 'false'; }"
                }
            },
            "accessory": "mqttthing"
        },
        {
            "type": "occupancySensor",
            "name": "Living Room Presence Sensor",
            "logMqtt": false,
            "topics": {
                "getOccupancyDetected": {
                    "topic": "zigbee2mqtt/<deviceID>",
                    "apply": "return JSON.parse(message).target_distance > 2.5 ? 'true' : 'false';"
                }
            },
            "accessory": "mqttthing"
        }

posted by Gal Zilberman

SENSORS: HUMIDITY AND TEMPERATURE

Shelly HT Humidity Temperature Sensor

example of a shelly HT configuration https://shelly-api-docs.shelly.cloud/#shelly-h-amp-t

Insert the name of your device in place "shellyht-22C5C7"

 {
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "Temperature",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getCurrentTemperature": "shellies/shellyht-22C5C7/sensor/temperature",
	    "getOnline": "shellies/shellyht-22C5C7/online",
        "getBatteryLevel": "shellies/shellyht-22C5C7/sensor/battery",
        "getChargingState": ""
    },
    "logMqtt": false
},
{
    "accessory": "mqttthing",
    "type": "humiditySensor",
    "name": "Humidity",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getCurrentRelativeHumidity": "shellies/shellyht-22C5C7/sensor/humidity",
	    "getOnline": "shellies/shellyht-22C5C7/online",
        "getBatteryLevel": "shellies/shellyht-22C5C7/sensor/battery",
        "getChargingState": ""
    },
    "logMqtt": false
}

because the sensor sends data to the broker MQTT within a set time or after changing the temperature or humidity, (shell HT is powered by battery and periodically online) set MQTT on shelly HT:

Check Clean Session and Retain, Max QoS 1

Will Topic: shellies/shellyht-22C5C7/online Will Message: true

and in MQTT broker like mosquito in mosquito.conf

autosave_interval 1800
autosave_on_changes false
persistence true
persistence_file mosquitto.db
persistence_location /mosquitto/data/path/ etc.

Thanks to lulek2007

Sonoff SC Environmental Station

Sonoff SC environmental station and Tasmota upload firmware https://www.itead.cc/sonoff-sc.html

This station is some difficult to support in mqttthing because light intensity is not in lux, environmental sound level is not supported natively in Home app (but in elegato eve app working), and Air Quality now is not supported.
but my proposal to temporary workaround.

{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "Temperatura",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getCurrentTemperature": {
    	    "topic": "tele/DVES_FD1AFD/SENSOR",
            "apply": "return JSON.parse(message).SonoffSC.Temperature;",
            "logMqtt": false
        }    
    }
},
{
    "accessory": "mqttthing",
    "type": "humiditySensor",
    "name": "Wilgotność",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getCurrentRelativeHumidity": {
    	    "topic": "tele/DVES_FD1AFD/SENSOR",
            "apply": "return JSON.parse(message).SonoffSC.Humidity;"
        }
    }
},
{
    "accessory": "mqttthing",
    "type": "lightSensor",
    "name": "Oświetlenie",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getCurrentAmbientLightLevel": {
    	    "topic": "tele/DVES_FD1AFD/SENSOR",
            "apply": "return Math.round( JSON.parse(message).SonoffSC.Light * 100 );"
        }
    }
},
{
    "accessory": "mqttthing",
    "type": "speaker",
    "name": "Hałas",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getVolume": {
    	    "topic": "tele/DVES_FD1AFD/SENSOR",
            "apply": "return JSON.parse(message).SonoffSC.Noise;"
        }
    }
},
{
    "accessory": "mqttthing",
    "type": "humiditySensor",
    "name": "Jakość powietrza",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics": {
        "getCurrentRelativeHumidity": {
    	    "topic": "tele/DVES_FD1AFD/SENSOR",
            "apply": "return JSON.parse(message).SonoffSC.AirQuality;"
        }
    }
}

Thanks to lulek2007

Sonoff Tasmota Temperature

Example configuration for most Sonoffs with Tasmota firmware.

{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "YourName",
    "url": "mqtt://broker's IP",
    "username": "username",
    "password": "password",
    "topics": {
        "getCurrentTemperature": {
            "topic": "tele/YourName/SENSOR",
            "apply": "return JSON.parse(message).DS18B20.Temperature;"
        }
    }
}

Thanks to bartoszwas

Sonoff Tasmota SI7021

Example configuration for Sonoff-Tasmota with SI7021 - Temperature and Humidity. Edit your in Tasmota configured mqtt topic, my is Sonoff Basic with Tasmota.

{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "TEST-TEMP-EXT",
    "url": "mqtt://Your IP address server",
    "username": "",
    "password": "",
    "topic": "tele/Spot_Erable/SENSOR",
    "caption": "",
    "sensorPropertyName": "SI7021",
    "topics": {
        "getCurrentTemperature": {
            "topic": "tele/Spot_Erable/SENSOR",
            "apply": "return JSON.parse(message)[\"SI7021\"].Temperature;"  
                },
        "getStatusFault": "",
        "getStatusTampered": "",
        "getStatusLowBattery": ""
            },
    "history": ""
},
{
    "accessory": "mqttthing",
    "type": "humiditySensor",
    "name": "TEST-Humidity_EXT",
    "url": "mqtt://Your IP address server",
    "username": "",
    "password": "",
    "topic": "tele/Spot_Erable/SENSOR",
    "caption": "",
    "sensorPropertyName": "SI7021",
    "topics": {
        "getCurrentRelativeHumidity": {
            "topic": "tele/Spot_Erable/SENSOR",
            "apply": "return JSON.parse(message)[\"SI7021\"].Humidity;"  
                },
        "getStatusFault": "",
        "getStatusTampered": "",
        "getStatusLowBattery": ""
            },
    "history": ""
}

Sonoff Tasmota BME280

Example configuration for Sonoff-Tasmota with BME280 - Temperature, Humidity & Air Pressure. Edit your in Tasmota configured mqtt topic, my is wemos-d1-mini-wz.

{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "Temperatur BME280",
    "logMqtt": "true",
    "topics": {
        "getCurrentTemperature": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).BME280.Temperature;"
        }
    },
    "history": "true"
},
{
    "accessory": "mqttthing",
    "type": "humiditySensor",
    "name": "Luftfeuchtigkeit BME280",
    "logMqtt": "true",
    "topics": {
        "getCurrentRelativeHumidity": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).BME280.Humidity;"
        }
    },
    "history": "true"
},
{
    "accessory": "mqttthing",
    "type": "airPressureSensor",
    "name": "Luftdruck BME280",
    "logMqtt": "true",
    "topics": {
        "getAirPressure": {
            "topic": "tele/wemos-d1-mini-wz/SENSOR",
            "apply": "return JSON.parse(message).BME280.Pressure;"
        }
    },
    "history": "true"
}

Thanks to @nicoh88

Sonoff Tasmota 2xDS18B20

Example configuration for Sonoff TH16 with Tasmota firmware and two DS18B20 Temperature.

{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "TEST-THP-IN",
    "url": "Your IP address server",
    "username": "username",
    "password": "password",
    "topics": {
        "getCurrentTemperature": {
            "topic": "tele/thermopompe/SENSOR",
            "apply": "return JSON.parse(message)[\"DS18B20-1\"].Temperature;"
        }
    }
},             
{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "TEST-THP-OUT",
    "url": "Your IP address server",
    "username": "username",
    "password": "password",
    "topics": {
        "getCurrentTemperature": {
            "topic": "tele/thermopompe/SENSOR",
            "apply": "return JSON.parse(message)[\"DS18B20-2\"].Temperature;"
        }
    }
}     

Xiaomi Temperature & Humidity sensor

This is for the Mijia sensor (the round one), but I suspect it'll work for the Aqara as well. You'll need to configure one accessory for temperature and one for humidity.

{
    "accessory": "mqttthing",
    "type": "humiditySensor",
    "name": "Xiaomi humidity sensor",
    "topics": {
        "getCurrentRelativeHumidity": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return parseFloat(JSON.parse(message).humidity);"
        },
        "getStatusLowBattery": {
            "topic": "zigbee2mqtt/ID",
            "apply": "if (JSON.parse(message).battery < 20) return 1; else return 0;"
        }
    }
},
{
    "accessory": "mqttthing",
    "type": "temperatureSensor",
    "name": "Xiaomi temperature sensor",
    "topics": {
        "getCurrentTemperature": {
            "topic": "zigbee2mqtt/ID",
            "apply": "return parseFloat(JSON.parse(message).temperature);"
        },
        "getStatusLowBattery": {
            "topic": "zigbee2mqtt/ID",
            "apply": "if (JSON.parse(message).battery < 20) return 1; else return 0;"
        }
    }
}

Inkbird IBS-TH1 / Plus Temperature & Humidity sensor

Using the Theengs Gateway to bridge BLE to MQTT.

{
    "name": "Inkbird IBS-TH1",
    "accessory": "mqttthing",
    "manufacturer": "Inkbird",
    "model": "IBS-TH1 Plus",
    "serialNumber": xxxx,
    "url": "mqtt://localhost:1883",
    "type": "custom",
    "services": [
        {
            "type": "temperatureSensor",
            "topics": {
                "getCurrentTemperature": {
                    "topic": "home/TheengsGateway/BTtoMQTT/(mac address without colons)",
                    "apply": "return JSON.parse(message).tempc"
                }
            }
        },
        {
            "type": "humiditySensor",
            "topics": {
                "getCurrentRelativeHumidity": {
                    "topic": "home/TheengsGateway/BTtoMQTT/(mac address without colons)",
                    "apply": "return JSON.parse(message).hum"
                }
            }
        }
    ]
}

Posted by @christophersjchow

SENSORS: LEAK

Xiaomi Aqara Water Leak Sensor

{
    "accessory": "mqttthing",
    "type": "leakSensor",
    "history": true,
    "name": "Leak sensor",
    "topics": {
        "getLeakDetected": {
            "topic": "zigbee2mqtt/<ID>",
            "apply": "return (JSON.parse(message).water_leak);"
        },
        "getStatusLowBattery": {
            "topic": "zigbee2mqtt/<ID>",
            "apply": "if (JSON.parse(message).battery < 20) return 1; else return 0;"
        },
        "getBatteryLevel": {
            "topic": "zigbee2mqtt/<ID>",
            "apply": "return JSON.parse(message).battery;"
        }
    },
    "integerValue": false
}

SENSORS: SMOKE

Wemos ESP-01S Smoke Alarm

A smoke alarm is a safety product, at your own risk.

This configuration is based on a standard smoke alarm (6€ - 12€) in which the small Wemos ESP-01S running tasmota is installed.

If you have enough space you can consider large parts like in this link.

When the alarm triggers power will be fed to the ESP and will connect to the broker.

We're not certain the power will be available for a long-time so we're going to listen the to the telemetry message on tasmota system boot which will report its Online status (in example topic is configured in tasmota to 'smoke-alarm'). Configure the wemos with a fixed IP address to avoid wasting time and issues with DHCP (ipaddress1, ipaddress2, ipaddress3, ipaddress4). Once the power is lost to the wemos, the mqtt connection to the broker is lost who will announce Offline and the Homekit smoke sensor will deactivate.

            "type": "smokeSensor",
            "name": "Smoke Alarm",
            "url": "mqtt://your_broker_ip_address:1883",`
            "username": "your_username",
            "password": "your_password",
            "topics": {
                "getSmokeDetected": "tele/smoke-alarm/LWT"
            },
            "onValue": "Online",
            "offValue": "Offline",
            "history": true,
            "manufacturer": "Your_alarm_brand",
            "model": "ESP-01S",
            "serialNumber": "your_serial_number",
            "firmwareRevision": "8.5",
            "accessory": "mqttthing"
        },

Posted by ceraz68

Switches

Xiaomi/Aqara QBKG24LM/QBKG25LM/QBKG23LM

{
            "accessory": "mqttthing",
            "type": "switch",
            "name": "Switch Name",
            "url": "mqtt://:1883",
            "username": "username",
            "password": "password",
            "logMqtt": true,
            "mqttPubOptions": {
                "retain": true
            },
            "topics": {
                "getOn": {
                    "topic": "zigbee2mqtt/ID",
                    "apply": "return JSON.parse(message).state_right === 'ON' ? true : false;"
                },
                "setOn": {
                    "topic": "zigbee2mqtt/ID/set",
                    "apply": "return JSON.stringify({state_right: (message ? \"ON\" : \"OFF\")});"
                }
            }
        }

Posted by zuhair68

Kincony KC868 A32 Relay Switch Board

Example configuration for one switch out of 32 from Kincony Relay Board KC-868 A32

{
    "type": "switch",
    "name": "Relay 1",
    "url": "mqtt://192.168.1.88:1883",
    "username": "gone",
    "password": "1234",
    "logMqtt": true,
    "topics": {
        "setOn": "KC868_A32/B48A0A40454C/SET"
    },
    "onValue": "{\"output1\":{\"value\":true}}\" }",
    "offValue": "{\"output1\":{\"value\":false}}\" }",
    "manufacturer": "Kincony",
    "model": "KC868-A32",
    "serialNumber": "B48A0A40454C",
    "firmwareRevision": "v1.0.10",
    "_bridge": {
        "username": "0E:EC:E7:17:46:33",
        "port": 59618
    },
    "accessory": "mqttthing"
}

Thanks to krokodilik

THERMOSTATS

Sinope TH1124ZB

Insert the name and the ID of your device in place of YOUR_THERMOSTAT_NAME and YOUR_THERMOSTAT_ID

{
  "accessory": "mqttthing",
  "type": "thermostat",
  "name": "YOUR_THERMOSTAT_NAME",
  "url": "mqtt://localhost:1883",
  "topics": {
      "getCurrentTemperature": {
        "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID",
        "apply": "return JSON.parse(message).local_temperature"
      },
      "getTargetTemperature": {
        "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID",
        "apply": "return JSON.parse(message).occupied_heating_setpoint"
      },
      "getTargetHeatingCoolingState": {
        "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID",
        "apply": "return JSON.parse(message).system_mode == 'idle' ? 'OFF' : 'HEAT'"
      },
      "getHeatingThresholdTemperature": {
        "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID",
        "apply": "return JSON.parse(message).local_temperature"
      },
      "setTargetHeatingCoolingState": {
        "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID/set",
        "apply": "return JSON.stringify({'system_mode': message == 'OFF' ? 'idle' : 'heat'})"
      },
      "setTargetTemperature": {
        "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID/set",
        "apply": "return JSON.stringify({'occupied_heating_setpoint': message })"
      }
  },
  "heatingCoolingStateValues": ["OFF", "HEAT"],
  "restrictHeatingCoolingState": [0, 1],
  "temperatureDisplayUnitsValues": "CELSIUS",
  "minTemperature": 4,
  "maxTemperature": 38,
  "startPub": [
    { "topic": "zigbee2mqtt/YOUR_THERMOSTAT_ID" }
  ]
}

Homematic IP Thermostats (CCU-Jack plugin)

Integration of Homematic IP thermostats (e.g. HmIP-eTRV-2) using the mdzio/ccu-jack Homematic MQTT plugin.

Insert the name and the ID of your device in place of YOUR_THERMOSTAT_NAME and YOUR_THERMOSTAT_ID

Setting the clientId in mqttOptions is a workaround and required unless issue #440 is fixed.

{
    "accessory": "mqttthing",
    "type": "thermostat",
    "name": "YOUR_THERMOSTAT_NAME",
    "mqttOptions": {
        "clientId": "mqttthingYOUR_THERMOSTAT_NAME"
    },
    "topics": {
        "getCurrentTemperature": {
            "topic": "device/status/YOUR_THERMOSTAT_ID/1/ACTUAL_TEMPERATURE",
            "apply": "return JSON.parse(message).v"
        },
        "getTargetTemperature": {
            "topic": "device/status/YOUR_THERMOSTAT_ID/1/SET_POINT_TEMPERATURE",
            "apply": "return JSON.parse(message).v"
        },
        "setTargetTemperature": {
            "topic": "device/set/YOUR_THERMOSTAT_ID/1/SET_POINT_TEMPERATURE"
        },
        "getCurrentRelativeHumidity": {
            "topic": "device/status/YOUR_THERMOSTAT_ID/1/HUMIDITY",
            "apply": "return JSON.parse(message).v"
        },
        "getCurrentHeatingCoolingState": {
            "topic": "device/status/YOUR_THERMOSTAT_ID/1/LEVEL",
            "apply": "return JSON.parse(message).v == 0 ? 'OFF' : 'HEAT'"
        }
    },
    "heatingCoolingStateValues": [ "OFF", "HEAT" ],
    "restrictHeatingCoolingState": [ 1 ],
    "temperatureDisplayUnitsValues": "CELSIUS"
 }

Posted by Dada40

ShellyPlus1 + temperature add-on with Shelly Script Thermostat

We consider that the Shelly's component switch:0 is acting as thermostat relay to control a heater. Configure your ShellyPlus1 device, and enable MQTT. Then install the ShellyPlus1Thermostat script from https://github.com/FermedePommerieux/Shelly-script/blob/main/ShellyPlus1Thermostat.js, configure and enable it. This script allows you to use an external sensor if you don't have a shelly add-on.

        {
            "name": "ShellyPlus1 Thermostat",
            "accessory": "mqttthing",
            "type": "thermostat",
            "url": "homebridge",
            "username": "homebridge",
            "password": "homebridge",
            "topics": {
                "getCurrentHeatingCoolingState": "shellyplus1-XXXXXXXXXXXX/thermostat/currentHeatingCoolingState",
                "setTargetHeatingCoolingState": "topic": "shellyplus1-XXXXXXXXXXXX/thermostat/targetHeatingCoolingState",
                "getTargetHeatingCoolingState": "shellyplus1-XXXXXXXXXXXX/thermostat/targetHeatingCoolingState",
                "getCurrentTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/currentTemperature",
                "setTargetTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/targetTemperature",
                "getTargetTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/targetTemperature",
                "setCoolingThresholdTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/coolingThresholdTemperature"
                "getCoolingThresholdTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/coolingThresholdTemperature",
                "setHeatingThresholdTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/heatingThresholdTemperature"
                "getHeatingThresholdTemperature": "shellyplus1-XXXXXXXXXXXX/thermostat/heatingThresholdTemperature"
            },
            "minTemperature": 16,
            "maxTemperature": 24,
            "restrictHeatingCoolingState": [
                0,
                1
            ],
            "logMqtt": false,
            "_bridge": {
                "username": "XX:XX:XX:XX:XX:XX"
            }
        }

WINDOW COVERINGS

Ikea Blinds via Zigbee2MQTT can be controlled reliably with this codec.

Bridges

Bulbs & Lights

Dimmers & Switches

Garage Door Openers

Heaters and Coolers

Lock Mechanism

Outlets & Plugs

Security System

Sensors: Air Quality & Carbon Dioxide

Sensors: Contact & Motion

Sensors: Humidity & Temperature

Sensors: Smoke

Switches

Thermostat

Clone this wiki locally