Triggers in led status

Hello, i’m building project with NodeMCU and Cayenne. Right now, i’m controlling the LED.

Okay, thats fine, board connects with cayenne and i can see thae values that i need.
I’ve a button, for turn on/off led from cayenne and value widget for see the led state.

My problem, is that when i set up a trigger only works when its refere to button, if i set it for the value isnt works

>> value trigger

Thats the worse, that only works for one.

Thanks a lot

make the variable i global and place Cayenne.virtualWrite(xxx) in the CAYENNE_OUT_DEFAULT() but this function will be called every 15second.

like this?

yes, and remove from CAYENNE_IN_DEFAULT()


So, I put this, and this is the trigger

But… the same, no trigger shots

delete the widget associate with channel 2 from the cayenne dashboard. then change Cayenne.virtualWrite(2, i) to Cayenne.virtualWrite(2, i, "digital_sensor", "d") . Next delete the trigger from the cayenne dashboard. Now, upload the code which will generate a new two state widget. Add it by clicking on the +. Now add trigger to this widget.

Perfect!, great shramik… perfect. But, right now i’ve a doubt… Before, the status change was inmediatly, but right now, I need chage 2 times LED_switch (web button) for change value.
I explain:

push one time cayenne button: Phisical LED change (great!), but Led_status value not (bad)
push again cayenne button: Phisical LED change (great!), Led_status value change

The value change at the second time.

And another… I’m reciving notifications each X secons while conditions is true (Led:status value = 1 > notf…notf…notf…) every time. How I can change it for only recive notifiactions one time (only with value change)?

thanks a lot, your help is gorgeous

this is for your first issue.

for the second issue have a look at this Sending MQTT messages within notification limit

I dont undertand how i can fix the first issue… you mean that CAYENNE_OUT_DEFAULT () is refreshing each 15 seconds… but… whats the solution? thanks

place publish line in main loop but only publish once. Use some kind of variable to set true or false the case to send the data only once. Something like this.

int previousState = -1;
int i = -1;
void loop()
	if (i != previousState) {
     Cayenne.virtualWrite(2, i, "digital_sensor", "d") 		
    previousState = i;

Use the first code you submitted. With the change Shramik suggested. This will update the led status when changed without extra pushes for the mqtt server

Cayenne.virtualWrite(2, i, “digital_sensor”, “d”)
Cayenne default IN

Having publish code in CAYENNE_IN() is not the best practise.