Here is a step by step pictorial on how to use the embedded-mqtt-broker to create a Generic MQTT Thing.
- Add a Generic MQTT Thing by choosing the inbox --> + , select “MQTT Binding” to start searching but hit the “Add manually” then select “Generic MQTT Thing”
- Now add a channel to the Generic MQTT Thing. When you do this pick your channel_id_with_no_spaces.
NOTE: Double Check everything BEFORE you hit SAVE. Once you create the topic this way (via the UI) the only way to edit it is to delete it and recreate it.
-
Create the ITEM to Attach to the MQTT Topic channel:
Choose “Create new item”.
-
Link and ITEM to the TOPIC channel like this:
-
Hit Link. Now you are setup to actually switch the plug/light “on” or “off” or just use its ITEM in a rule. So here is the final result:
-
To access the plug in a rule, do this
To Turn the Plug ON use this in a rule:
Guest_Bathroom_EchoDot_Tuya_Plug.sendCommand(ON)
To Turn the Plug OFF use this in a rule:
Guest_Bathroom_EchoDot_Tuya_Plug.sendCommand(OFF)
- (optional) You can also do a test by accessing Guest_Bathroom_EchoDot_Tuya_Plug (by its label or name “Guest Bathroom MQTT Thing”) through the “Control” and go to its assigned location and hit the switch!
NOTE1
“The big hurdle at the moment is getting the localkey for each device. Only developers get a secret key they can use it to set or get the private key for the device(it changes each time it’s set up)” In other words, if you have to change the setup on any tuya plug or light bulb, you will have to rediscover the “localkey” for the plug or light bulb!!
tuya/<"socket" or "lightbulb">/<Virtual-id>/<localkey>/<ip-address>/command
tuya/<"socket" or "lightbulb">/<Virtual-id>/<localkey>/<ip-address>/state
NOTE2
NOTE1 means that if you added your Generic MQTT Things by using the PAPER UI and you make any setup change to the plug or bulb (i.e. change wifi networks, assign a new ip address, or factory reset the plug or bulb)…YOU WILL HAVE TO RECREATE the Generic MQTT Thing to gain access to the MQTT topic configurations (the /command and /state definitions)
I think it is better to create the Generic MQTT Thing inside a “mqtt.things” FILE and create the channels via “mqtt.items” FILE
Here are my files at this moment:
mqtt.things
Thing mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing "Generic MQTT Thing" (mqtt:systemBroker:embedded-mqtt-broker) @ "Home" {
Channels:
Type switch : MasterBedroom_EchoPlus_MQTT_TuyaChannel "Master Bedroom Echo Plus MQTT Tuya Channel" @ "Master Bedroom" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1",off="0" ]
Type switch : Netgear77_MQTT_Tuya_Channel "NETGEAR77 MQTT Tuya Channel" @ "Family Room" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1",off="0" ]
Type switch : FamilyRoom_MQTT_Tuya_Channel "Family Room Echo Plus MQTT Tuya Channel" @ "Family Room" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1",off="0" ]
Type switch : Basement_Garage_MQTT_Tuya_Channel "Basement Garage Ech Dot MQTT Tuya Channel" @ "Basement Garage" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1", off="0" ]
Type switch : Master_Bathroom_MQTT_Tuya_Channel "Master Bathroom Ech Dot MQTT Tuya Channel" @ "Master Bathroom" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1", off="0" ]
Type switch : Guest_Bedroom_MQTT_Tuya_Channel "Guest Bedroom Ech Dot MQTT Tuya Channel" @ "Guest Bedroom" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1", off="0" ]
Type switch : Guest_Bathroom_MQTT_Tuya_Channel "Guest Bathroom Ech Dot MQTT Tuya Channel" @ "Guest Bathroom" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1", off="0" ]
Type switch : Netgear86_MQTT_Tuya_Channel "NETGEAR86 MQTT Tuya Channel" @ "Master Bedroom" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1",off="0" ]
Type switch : Netgear86Bridge_MQTT_Tuya_Channel "NETGEAR86 BRIDGE MQTT Tuya Channel" @ "Family Room" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1",off="0" ]
Type switch : ARRIS_528A_MQTT_Tuya_Channel "ARRIS-528A MQTT Tuya Channel" @ "Master Bedroom" [ stateTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/state", commandTopic="tuya/socket/<Virtual-id>/<localkey>/<ip-address>/command", on="1",off="0" ]
}
mqtt.items
// Master Bedroom Echo Plus Plug
Switch Master_Bedroom_EchoPlus_Tuya_Plug "Master Bedroom Echo Plus Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:MasterBedroom_EchoPlus_MQTT_TuyaChannel"}
// Turn off NETGEAR 77 Router
Switch NETGEAR77_Tuya_Plug "NETGEAR 77 Router Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:Netgear77_MQTT_Tuya_Channel"}
// Mute the Family Room Echo Plus
Switch Family_Room_EchoPlus_Tuya_Plug "Family Room Echo Plus Smart Plug" <switch> (gMuteFamilyRoom,gMuteFrontOfHouse) {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:FamilyRoom_MQTT_Tuya_Channel"}
// Mute the Basement Garage Echo Dot
Switch Basement_Garage_EchoDot_Tuya_Plug "Basement Garage Echo Dot Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:Basement_Garage_MQTT_Tuya_Channel"}
// Mute the Master Bathroom Echo Dot
Switch Master_Bathroom_EchoDot_Tuya_Plug "Master Bathroom Echo Dot Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:Master_Bathroom_MQTT_Tuya_Channel"}
// Mute the Guest Bedroom Echo Dot
Switch Guest_Bedroom_EchoDot_Tuya_Plug "Master Bathroom Echo Dot Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:Guest_Bedroom_MQTT_Tuya_Channel"}
// Turn off NETGEAR86 Router
Switch NETGEAR86_Tuya_Plug "NETGEAR 86 Router Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:Netgear86_MQTT_Tuya_Channel"}
// Turn off NETGEAR86 Bridge
Switch NETGEAR86_Bridge_Tuya_Plug "NETGEAR 86 Bridge Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:Netgear86Bridge_MQTT_Tuya_Channel"}
// Turn off ARRIS-528A Router
Switch ARRIS_528A_Tuya_Plug "ARRIS-528A Smart Plug" <switch> {channel="mqtt:topic:systemBroker:embedded-mqtt-broker:Generic_Tuya_MQTT_Thing:ARRIS_528A_MQTT_Tuya_Channel"}
Since you are using files you will also need the “addons.cfg” file:
addons.cfg
# The installation package of this openHAB instance
# Note: This is only regarded at the VERY FIRST START of openHAB
# Note: If you want to specify your add-ons yourself through entries below, set the package to "minimal"
# as otherwise your definition might be in conflict with what the installation package defines.
#
# Optional. If not set, the dashboard (https://<yourserver>:8080/) will ask you to choose a package.
#
# Valid options:
# - minimal : Installation only with dashboard, but no UIs or other add-ons. Use this for custom setups.
# - simple : Setup for using openHAB purely through UIs - you need to expect MANY constraints in functionality!
# - standard : Default setup for normal users, best for textual setup
# - expert : Setup for expert users, especially for people migrating from openHAB 1.x
# - demo : A demo setup which includes UIs, a few bindings, config files etc.
#
# See https://www.openhab.org/docs/configuration/packages.html for a detailed explanation of these packages.
#
package = minimal
# Access Remote Add-on Repository
# Defines whether the remote openHAB add-on repository should be used for browsing and installing add-ons.
# This not only makes latest snapshots of add-ons available, it is also required for the installation of
# any legacy 1.x add-on. (default is true)
#
remote = true
# Include legacy 1.x bindings. If set to true, it also allows the installation of 1.x bindings for which there is
# already a 2.x version available (requires remote repo access, see above). (default is false)
#
#legacy = true
# A comma-separated list of bindings to install (e.g. "binding = sonos,knx,zwave")
binding = wemo, ntp, hue, zwave, mqtt, zigbee, amazonechocontrol, wifiled
# A comma-separated list of UIs to install (e.g. "ui = basic,paper")
ui = basic, paper, habpanel
# A comma-separated list of persistence services to install (e.g. "persistence = rrd4j,jpa")
persistence = jdbc-mysql
# A comma-separated list of actions to install (e.g. "action = mail,pushover")
action =
# A comma-separated list of transformation services to install (e.g. "transformation = map,jsonpath")
transformation =
# A comma-separated list of voice services to install (e.g. "voice = marytts,freetts")
voice =
# A comma-separated list of miscellaneous services to install (e.g. "misc = myopenhab")
misc = openhabcloud
I hope this helps