Get Player to half of a heart via vanilla potions
Solution 1:
Use Poison. It will lower a player's health to half a heart but not kill them.
The higher the level, the faster it drains, but it won't kill them.
effect give @p poison 10 1 true
Solution 2:
If we were to consider vanilla, then you must get splash potions of Poison II.
The easiest way of doing so is farming spiders, creepers, nether wart, and find glowstone.
Follow these instructions to make a Potion of Poison, then use a glowstone dust to add up the Poison level (Now it's Poison II.) and add a gunpowder to make it a Splash Potion.
You said you want to use a bed trap, right? Place an observer somewhere unnoticeable, and same thing goes for the dispenser. Connect some redstone and add in the splash potions in.
An example by SF. (the simplest form):
Now you got them hurt in their sleep.