I am trying to write a simple function to toggle based on receipt of of a specific payload (a button press from a zigbeetomqtt capture of a sonoff button)
if (msg.payload=="single"){
if (cur_state==0){
cur_state=1;
} else {
cur_state=0;
}
}
}
msg.payload=cur_state;
return msg;
Where / how do I declare cur_state and am I returning the updated cur_state correctly - I suspect that msg.payload=cur_state; is not the correct syntax.