Energy exchanges of magnets with the environment