I would really like MQTT Subscribe and publish in Rule Machine'?
To trigger a Rule and
To push a value via MQTT.
I realise there is probably a convoluted way of doing some this with say a virtual dimmer with a custom driver doing the publish, using a custom action in a rule.
I would love to be able to trigger rules from one of my MQTT subscribed devices.
Here's an idea using a Tiny Web Server to convert an HTTP GET call to an MQTT publication
if (Request.Action.ToLower().StartsWith("mqtt"))
{
//e.g http://localhost:82/mqtt.svs?topic=test&value=123
if ((Request.ArgArray[0] != "topic") || (Request.ArgArray[2] != "value"))
throw new Exception("Invalid paramter");
string topic = Request.ArgArray[1];
string value = Request.ArgArray[3];
/// create client instance
MqttClient client = new MqttClient("localhost");
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
// publish a message on "/home/temperature" topic with QoS 2
ushort resp = client.Publish(topic, Encoding.UTF8.GetBytes(value), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
string sjson = JsonConvert.SerializeObject(client);
//Send back last value usefull
HTTPserver.Response(sjson);
//client.Disconnect();
}