It sounds like the two black wire with the pigtail are the incoming hot and a branch hot to another location, such as the outlet. The other black attached to the switch is probably the switched hot that goes to the fixture being controlled.
You can verify this by turning the switch to off, making sure all the wires and terminals are clear and not touching anything else metal, and then turning on the breaker. Using the non-contact tester, carefully check the wires. The paired blacks should read hot, but the switched black should not.
If this is what you have, wiring the new switch is pretty straightforward. Turn the breaker off again. Confirm no wires are now hot. The new switch is basically connected the same way as the old, but with a neutral wire and ground wire added.
- The hot pigtail is connected to the line terminal.
- The switched black wire is connected to the load terminal.
- A pigtail (white) is added to the bundle of neutral wires and connected to the neutral terminal
- A pigtail (bare) is added to the bundle of ground wires and connected to the ground terminal.
The traveler terminal is not used (and it looks like it is covered anyway).
Use wire nuts, and if you like, tape over them for extra safety. You also could put a wrap of tape around the z-switch covering the terminals. Carefully insert the wires back in the box. Screw the switch into the box. Turn the power back on.
While most dumb switches do not need a neutral connection, many smart switches, such as the z-switch, do. Now all switches have a separate ground connection, although many in the past did not.
Best Answer
I've never connected a motion switch before but it looks like the two whites neutrals in the wall box stay together, and then just twist one of the two blacks coming out the wall box each and individually with one of the blacks coming off the switch (just pick one from wall to twist with wire nut with one on the switch, and then do the other blacks). The green and the other small wire are ground wires so those will go from a newly connected pigtail to the metal box, and follow instructions from the Important Grounding Note section below for correctly connecting the grounds.
Important Grounding Note: You should use pigtails to connect the two grounding conductors to the circuit grounding conductors, and the box. Putting them all under the same screw, is not the proper way to do it.