@giacomo1574 welcome to cayenne community.
First of all if you can try shifting cayenne arduino library to cayenne MQTT library which is more stable : Converting Cayenne Arduino LIbrary sketches to Cayenne MQTT Arduino
you can do this but when connection is lost ,cayenne.loop function waits till connection is reestablished and then continues with rest of the code. so if you do your triggers in arduino code they wont run. so this feature is currently on cayenne roadmap. but there is a workaround, you can try this. Arduino Online/Offline Override