How many entities in an area?
I want to make it so I always have 50 entities in an area. So when 1 dies/despawns/leaves the area I want it to detect that and summon in a new entity, and yes I do want them to die/despawn/leave the area so preventing those things is not an option.
Plug a redstone clock into 2 Command blocks (or use 1.9 Repeat command blocks):
The first command:
/testfor @e[x=X,y=Y,z=Z,r=R]
And the second:
/testforblock X Y Z command_block 1 {SuccessCount:49}
Place a Comparator leading from the second Command Block - that is, if there are 49 entities, it succeeds. Then place your final command block next to the Comparator, into it put your /summon
command.