Javascript problem

Hi I’m trying to implement an Idle timer which sends a message to an mqtt broker after a certain amount of time has passed. I got the code for the idle timer and I know that this code works. The only problem I have now is that I don’t have a clue how to properly implement this in noodl.

So far this is my code:

    function activityWatcher(){

        //The number of seconds that have passed
        //since the user was active.
        var secondsSinceLastActivity = 0;

        //Five minutes. 60 x 5 = 300 seconds.
        var maxInactivity = (60 * .5);

        //Setup the setInterval method to run
        //every second. 1000 milliseconds = 1 second.
        console.log(secondsSinceLastActivity + ' seconds since the user was last active');
        //if the user has been inactive or idle for longer
        //then the seconds specified in maxInactivity   
        if(secondsSinceLastActivity > maxInactivity){
        console.log('User has been inactive for more than ' + maxInactivity + ' seconds');
        //Redirect them to your logout.php page.
        outputs.hydro = 1
        }, 1000);

        //The function that will be called whenever a user is active
        function activity(){
        //reset the secondsSinceLastActivity variable
        //back to 0
        secondsSinceLastActivity = 0;

        //An array of DOM events that should be interpreted as
    //user activity.
    var activityEvents = [
    'mousedown', 'mousemove', 'keydown',
    'scroll', 'touchstart'

    //add these events to the document.
    //register the activity function as the listener parameter.
    activityEvents.forEach(function(eventName) {
    document.addEventListener(eventName, activity, true);


        outputs: {
            //ledString: "string",
            hydro: "number"    

        run: function activityWatcher() {


It would be really appreciated if someone can help me implement this in the proper way!