A valve controller (102, 202, 302, 402) for a valve (101, 201, 301, 401) that comprises an actuator mechanically coupled to at least one flow controlling element, the valve controller (102, 202, 302, 402) comprising: a control unit, at least one pilot valve (25, 37, 72) for controlling the position of the flow controlling element(s) by energizing the actuator by allowing a pressurized fluid to enter the actuator and de-energizing the actuator by allowing the pressurized fluid to leave the actuator, a position sensor connected to the control unit for obtaining a position signal indicative of the position of one of said at least one flow controlling element, at least one pilot valve detection circuitry, said valve controller (102, 202, 302, 402) being further configured to execute a configuration phase comprising: controlling the position of the flow controlling element(s) by means of said at least one pilot valve (25, 37, 72) to set the flow controlling element(s) in a plurality of predefined states, acquiring, from the position signal, while the flow controlling element(s) is in at least two of the predefined states, a nominal position value (P1, P2, P3, P4) for each of said at least two of the predefined states, establishing, by means of said at least one pilot valve detection circuitry, a pilot valve integer corresponding to the number of said at least one pilot valve (25, 37, 72) that is/are connected to the control unit, the valve controller being characterized in that said configuration phase further comprises determining a tolerance criterion (ΔP1, ΔP2) for the position signal based on the pilot valve integer, wherein the tolerance criterion (ΔP1, ΔP2) defines an acceptable range of position values for the flow controlling element(s), as given by the position signal, while the flow controlling element(s) is in one of the predefined states, wherein the tolerance criterion gives an acceptable deviation for the position value in relation to the nominal position value. a control unit, at least one pilot valve (25, 37, 72) for controlling the position of the flow controlling element(s) by energizing the actuator by allowing a pressurized fluid to enter the actuator and de-energizing the actuator by allowing the pressurized fluid to leave the actuator, a position sensor connected to the control unit for obtaining a position signal indicative of the position of one of said at least one flow controlling element, at least one pilot valve detection circuitry, said valve controller (102, 202, 302, 402) being further configured to execute a configuration phase comprising: controlling the position of the flow controlling element(s) by means of said at least one pilot valve (25, 37, 72) to set the flow controlling element(s) in a plurality of predefined states, acquiring, from the position signal, while the flow controlling element(s) is in at least two of the predefined states, a nominal position value (P1, P2, P3, P4) for each of said at least two of the predefined states, establishing, by means of said at least one pilot valve detection circuitry, a pilot valve integer corresponding to the number of said at least one pilot valve (25, 37, 72) that is/are connected to the control unit, the valve controller being characterized in that said configuration phase further comprises determining a tolerance criterion (ΔP1, ΔP2) for the position signal based on the pilot valve integer, wherein the tolerance criterion (ΔP1, ΔP2) defines an acceptable range of position values for the flow controlling element(s), as given by the position signal, while the flow controlling element(s) is in one of the predefined states, wherein the tolerance criterion gives an acceptable deviation for the position value in relation to the nominal position value. controlling the position of the flow controlling element(s) by means of said at least one pilot valve (25, 37, 72) to set the flow controlling element(s) in a plurality of predefined states, acquiring, from the position signal, while the flow controlling element(s) is in at least two of the predefined states, a nominal position value (P1, P2, P3, P4) for each of said at least two of the predefined states, establishing, by means of said at least one pilot valve detection circuitry, a pilot valve integer corresponding to the number of said at least one pilot valve (25, 37, 72) that is/are connected to the control unit, the valve controller being characterized in that said configuration phase further comprises determining a tolerance criterion (ΔP1, ΔP2) for the position signal based on the pilot valve integer, wherein the tolerance criterion (ΔP1, ΔP2) defines an acceptable range of position values for the flow controlling element(s), as given by the position signal, while the flow controlling element(s) is in one of the predefined states, wherein the tolerance criterion gives an acceptable deviation for the position value in relation to the nominal position value.