method for managing medication of a user, wherein a container for medicaments includes a storage chamber and a cap for closing the storage chamber is used, wherein the containe has a temperature sensor for measuring temperature inside the container; a humidity sensor for measuring humidity inside the container; an accelerometer sensor arranged in connection with the cap; communication means; and a first connecting part and a second connecting part arranged to attach to each other via magnetic forces. The method includes pre-setting the magnetic force between the first connecting part and the second connecting part to correspond to a given type of container; and recognising the type of container by the acceleration of the second connecting part during the attachment of the second connecting part to the first connecting part.