Get a bed occupancy sensor and put a condition in your automation to only run if the bed is occupied.