clearInterval inside of socket getStates function

I try to use a modified socket.io adaption for iobroker (smart home broker) with a setInterval function for showing every second the time ago of the last received timestamp of

It works so far, till the second updated timestamp comes… It seems clearInterval did not stop the interval and the timer is running twice with the old and new timestamp.

How and where do i have to clearInterval correctly?

My code:

servConn.namespace = 'mobile.0';
servConn._useStorage = false;

var stromv = 'hm-rpc.1.MEQ123456.1.POWER';

var subscriptions = [stromv];

var states = [];

servConn.init({
  name: 'mobile.0',
  connLink: 'http://IP:8082',
  socketSession: ''

}, {

  onConnChange: function(isConnected) {

    if (isConnected) {
      console.log('connected');

    } else {
      console.log('disconnected');
    }
  },

  onUpdate: function(id, state) {

    setTimeout(function() {

      states[id] = state;

      let stromvID = states[stromv].val;
      let stromvIDts = states[stromv].ts;

      //Get States of subsribed states if changed
      servConn.getStates([stromvID], (error, states) => {
        document.getElementById("stromvAktuell").innerHTML = stromvID + " W/h";
      });

      servConn.getStates([stromvIDts], (error, states) => {

        function stopInterval() {
          clearInterval(timerId);
        };

        timerId = setInterval(function() {
          updateTimeAgo();
        }, 1000);

        function updateTimeAgo() {
          let duration = moment(stromvIDts).fromNow();
          console.log(duration);
          document.getElementById("stromvTs").innerHTML = duration;
        };

      });

    }, 0);

  },

  onError: function(err) {
    window.alert(_('Cannot execute %s for %s, because of insufficient permissions', err.command, err.arg), _('Insufficient permissions'), 'alert', 600);
  }

}, false, false);

servConn._socket.emit('subscribe', subscriptions);
<!DOCTYPE html>
<html lang="de">

<head>
  <link rel="icon" href="data:,">
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
  <title>TEST</title>
  <script src="http://IP:8082/socket.io/socket.io.js"></script>
  <script src="../tmp/conn.js"></script>
  <script src="moment-with-locales.js"></script>
  <script>
    moment.locale('de')
  </script>
</head>

<body>
  <div>
    Value: <b id="stromvAktuell">unknown</b>
    <br> Last update: <b id="stromvTs">unknown</b>
    <br>
  </div>
</body>