Ok, I understand what’s up now. We could probably make this clearer in our UI, but the widget creation process is a little different for MQTT-connected devices.
For all MQTT sensor data, instead of adding the widget, and then feeding it with data, you do it the other way around – publish the sensor values to Cayenne in your code using
virtualWrite(), and we’ll auto-create temporary widgets on your dashboard which you can then accept and customize.
virtualWrite() expects a parameter format like:
virtualWrite(mqtt_channel_number, value, "type value", "unit value")
A few quick examples:
Pass temperature value 25.2 in Celsius to MQTT Channel 2
virtualWrite(2, 25.2, "temp", "c")
Pass generic value 17.222 to MQTT Channel 6
virtualWrite(6, 17.222, "analog_sensor", "null")
Digital 2-state value 1 on channel 5:
virtualWrite(5, 1, "digital_sensor", "d")
You can use the chart in this thread to help you build these statements for other data/unit types. I’d be happy to help in that regard as well.
For MQTT Actuators (like a relay), the process is a little different:
First create a custom button or slider widget – as you’ve noticed, this is one of the few things that was not blocked for you. Don’t worry about the ‘Relay’ widget you may have found digging in menus – it’s just a dolled up button widget and you can customize your custom button widget the same way.
Add code to a CAYENNE_IN(x) block where x == the channel you selected for the custom widget in step 1. It looks like you basically have this in place already, presuming your button is set to channel 8.