Mqtt scripting for nymea

I have enabled the MQTT broker in nymea: core. I have a few sensors who publish various values in MQTT, but I don’t know how to capture those values in nymea scripting or nymea rules.
In the Log tab of /debug, if I set a filter to MQTT, I can see all the MQTT messages published in my network.
I’ve searched this forum but nothing relates to MQTT published messages in nymea scripting or nymea rules.

Hi @flax1k, welcome to nymea!

I think this might be what you’re looking for:
https://nymea.io/documentation/users/advancedusage/sensor-on-mqtt-server

1 Like

Thank you @mzanetti for your quick answer.
I know the tutorial that you sent me and I read it carefully many times, but I couldn’t find “Internal MQTT client” in the list of things to be added and I am not able to add the Internat MQTT client, or any MQTT related thing.
Did I miss something?

Thank you

Oh, I see…

https://nymea.io/documentation/users/usage/things#installing-more-plugins

This should help. I’ll make the documentation more clear. Thanks for the feedback.

1 Like

Still no luck for me. I’ve installed all packages with mqtt word, but I can’t find that Internal mqtt client in the list of things.
Can you please write me what package(s) need to be installed to find that Internal MQTT client?
The following packages are already installed (have the “+” sign):
libnymea-mqtt
libnymea-mqtt-dbgsym
nymea-mqtt-server
nymea-mqtt-server-dbgsym
nymea-plugin-mqttclient
nymea-plugin-mqttclient-dbgsym

Nymea-plugin-mqttclient is what you want.

Did you restart nymea after installing the plugin? At this point it still requires a restart to load new plugins. We’ll be adding support for loading Plugins at runtime in the future.

1 Like

It’s working now :grinning: :+1:
After the nymea restart I found the internal mqtt client and I modified the script according with my published mqtt JSON message, so now it’s working. Thank you @mzanetti :pray:

1 Like

Question: is it possible to publish a mqtt message using the internal mqtt client?
I try to figure it out but no result yet.
Should I use ThingAction or DeviceAction?
And what’s the syntax to publish a message?

DeviceAction is deprecated and you should use ThingAction.

You can find the actions of the mqtt plugin in its JSON defintion:

Something like this should work:

import QtQuick 2.0
import nymea 1.0

Item {

    Component.onCompleted: {
        publishAction.execute({"topic": "/some/topic", "data": "Hello", "qos": 1 })
    }    
        
    ThingAction {
        id: publishAction
        thingId: "{115fb220-1b8f-4d4d-959e-8c5e6bfbeecb}" // Internal MQTT client
        actionName: "trigger"
    }
}

I admit this is not documented very well yet. We’ll need to do something about that.

1 Like

Thanks, it works :+1:

1 Like