Help with Arduino Device Code

Hi

My 1st time here. I have a smart home project and I’m trying to decide the best software to run it.

So I’m trying cayenne - the api option, but I’m struggling to find detailed documentation.

Where I can find the api detailed docs to know for example the arguments for:
Cayenne.virtualWrite(args???)

I saw the examples
Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
Cayenne.virtualWrite(0, lastMillis);

My first goal now is to thrigger a 12v fan if a thermometer reachs a certain temp.
the fan is controled by a analog relay.
Here’s my piece of code so far:

sysTemp = Thermister(analogRead(0));
Cayenne.celsiusWrite(0, sysTemp);

if (sysTemp > 30 && fanIsRunning == false) {
digitalWrite(28, HIGH);
fanIsRunning = true;
}
if (sysTemp < 25 && fanIsRunning == true) {
digitalWrite(28, LOW);
fanIsRunning = false;
}

// now I want to inform the dashboard the ventilation status
Cayenne.virtualWrite(1, TYPE_BOOLEAN, fanIsRunning); //??????

Thermister function can be found at:

Thanks for any help

1 Like

I have an Idea, but I don’t know if it will works:

What about to add the following code:

if (fanIsRunnung == true)
{
    CAYENNE_OUT(V1)
    {
    Cayenne.virtualWrite(V1, 1);
    }
}
else {

    CAYENNE_OUT(V1)
    {
    Cayenne.virtualWrite(V1, 0);
    }

}

And then you can add Device/Widget → Digital Input and then select the Virtual Pin that you define to monitor. If it works, you will see either zero or one.

Let me know if you need more help. I can write also the whole code for you later and send it as PM.

Thanks for your response.

The code can be simplified by:
Cayenne.virtualWrite(V1, fanIsRunning);

don’t understand what the CAYENNE_OUT(V1) is doing.

But since i’m using the cayenne api I can’t add sensors to my device, so all the dashboard shows is 0 or 1.
I think I can’t add sensors to it… can I?

Of course that you can add sensors. You can read more in documentation. You can add custom sensors - Here in the Community you can find themes to almost any sensor for Arduino. Some of them are already implemented and there is ready copy/paste code snippets. Also videos are provided.
Documentation → HERE

That documentation don’t have much things about the api.
I’m looking for something that shows cayenne api commands like this with arduino

About adding sensors, I don’t know why I cant… see the picture below…
The device i want to add sensors is the Device 6e2e not shown in the list

Just as a reference, usually when someone on the Cayenne forums talks about the API they are usually referring to the MQTT API. From your code I would assume that you are using the Arduino libraries. If you go here it does a decent job explaining everything. The reason you cannot add a sensor is because your Ardunio is offline (or at least there is no connection to the Cayenne servers). After it is online you should be able to add the sensor.