for triggers have a look at this topic Sending MQTT messages within notification limit and modify the code accordingly.