<aside> 💡 The count needs a function dependent on a variable that counts the parts the machine produces. It does not sum up the count to an overall-count. This part is done automatically by grafana!

</aside>

<aside> 💡 A count can be a float.

</aside>


  1. First you need to decide on which variable the count is dependent. Here are some possibilities:

    Variable to choose the variable’s effect on the count
    total length produced each product has a fixed length (divide the overall length…)
    a sensor measures each passing by of a product the variable itself is the count.
    two messages with two different total lengths Count equals difference between two messages
  2. From here on you may need to do some calculations to get to the count (if it is not directly passed). Also you might need a json formula.

    Untitled

    <aside> 💡 the functions below are just EXAMPLES from this specific flow:

    </aside>

    //this is the difference function above:
    curr=msg.payload.Laenge_ges_mm
    prev=context.get("prev")||0;
    
    msg.payload.difference=curr-prev
    context.set("prev",curr);
    return msg;
    
    //this is the TO JSON function above:
    msg.payload = {
    "timestamp_ms": Date.now(),
    "count": Math.round(msg.payload.Laenge_ges_mm)
    }
    
    return msg;
    
  3. The next step is to see if the count is larger then 0, and only store it under the topic count if so. (By this we forbid messages that do not transport a count to get through). We do not want to save all messages with basically empty counts!

    Untitled