I recently converted a Homeyduino project to MQTT and a VirtualDevice. It was rather easy!
For you arduino project you can take a look at PubSubClient
Below you can take a excerpt of my code:
const char *mqttServer = "192.168.1.61";
const int mqttPort = 8883;
const char *mqttUser = "test";
const char *mqttPassword = "uno";
WiFiClientSecure espClient;
PubSubClient client(espClient);
const char *motion_topic = "home/hallway/pir/motion";
const char *luminance_topic = "home/hallway/pir/luminance";
// after connecting to your wifi don’t forget to connect to the MQTT Server
if (!client.connected()) {
client.setServer(mqttServer, mqttPort);
client.setCallback(callback);
Serial.print("Connecting to MQTT server "); Serial.print(mqttServer);
while (!client.connected()) {
if (client.connect(clientId.c_str(), mqttUser, mqttPassword ))
{
Serial.println("\tconnected");
} else {
delay(500);
Serial.print(".");
}
}
}
// After reading some sensor values publish the values
float lux = lightMeter.readLightLevel();
client.publish(luminance_topic, String(lux).c_str(), true);
client.publish(motion_topic, motionDetected ? "1": "0", true);
Then subscribe to topic and set Virtual Device capability