1. Learning Centre
  2. Solution Kits
  3. 👥 SafeSpace+ (People Counter)

How to create a calculation for Currently IN

Know how many people are currently in the area you're monitoring and inform the relevant personnel.

 Introduction:

This counter provides an accurate & low cost method to count people entering/ leaving a room or a building. The people counter is battery powered (with 2 standard 1.5V AA batteries) & is available in LoRa & cellular variants.

Custom Rule

To be able to count the people currently IN the monitored area, you have to create a custom rule in ALSO IoT Platform. Below are the steps to follow:

  1. Go to your People Counter device 
  2. Click on the “+ NEW ASSET” button 
    1. Create the virtual asset “currently_in”, type: integer
  3. Once you created the asset, go to the “Rules” section on the left sidebar 
  4. Click on “+ NEW RULE” button, but hold the SHIFT on your keyboard at the same time! 
    1. Thus, you’ll enter the Custom rule editor 
  5. Type in the rule name as you wish 
    1. For example: Currently IN – calculation 
  6. Paste the following code in the Body section of the rule: 
            device = allthingstalk.device.YOUR_DEVICE_ID 

            math = allthingstalk.math.basic.op 

            compare = allthingstalk.math.compare 

            compare_logic = allthingstalk.math.basic.logic 

            compare_condition = allthingstalk.util.condition 

              

            device.Total_Counter_A -> math.a     

            device.Total_Counter_B -> math.b 

              

            math.a-b -> device.currently_in 

            Note: you can find your DEVICE ID in the upper right corner > SETTINGS > Authentication > Device ID

            Rectifying negative values 

            The people counter can show the negative values, for instance, if you have more people exiting than entering. 

            This can happen due to: 

            • People entering/exiting not one-by-one, but in groups > not good for the people counter, since it uses the IR beam interruption for counting 
            • People were present in the monitored area in the time of installation. Hence, the Total Counters A & B have to be reseted to 0 at some time when you’re certain there are NO people inside.  

            Therefore, you can decide not to show negative values (people inside) by updating the rule above with the following code: 

            device = allthingstalk.device.YOUR_DEVICE_ID 

            math = allthingstalk.math.basic.op 

            compare = allthingstalk.math.compare 

            compare_logic = allthingstalk.math.basic.logic 

            compare_condition = allthingstalk.util.condition 

              

            device.Total_Counter_A -> math.a     

            device.Total_Counter_B -> math.b 

              

            math.a-b -> compare.a 

            0 -> compare.b 

            compare.a<b -> compare_condition.if 

            0 -> compare_condition.then 

            compare_condition.out -> device.currently_in 

              

            math.a-b -> compare_condition.else 

            compare_condition.out -> device.currently_in 

            Note: you can find your DEVICE ID in the upper right corner > SETTINGS > Authentication > Device ID


            Your rule should look something like one below: 

            Related articles: