That is definitely possible! You want to treat it just like your writing data to the dashboard. But instead of writing to a new channel with your data, use the same channel that button/actuator is on and just write a 0 or 1. So the example below, writes a 0 or “off” to the button on channel 1. If you want it on just change the 0 to a 1. The button will update right away on the dashboard.
Cayenne.virtualWrite(1, 0, "digital_sensor", "d");
You can also do this with a analog slider too. Instead of writing a 0 or 1, write the value you want the slider to show as below. I have it writing to channel 4, and then the value of my variable txPwr.
Cayenne.virtualWrite(4, txPwr, "analog_actuator", "null");
One thing to note is I don’t believe this will call your CAYENNE_IN functions. Meaning, that is you have code under your CAYENNE_IN(channel#) that runs when you press the button, it won’t be run when you change the actuator state from your code. I think it only runs when you press the button on the dashboard. I could be wrong but if your code under CAYENNE_IN isn’t being run, thats why. Just move the code out of the CAYENNE_IN function if you need it to run on any change with a “if” statement.
i hope that wasn’t too confusing lol.