pnp sensor on raspberry
The sensor output switches 24 V or 0 V.


That means it's a digital sensor and should be connected to a digital input. You use analog inputs for varying signals which are "analogous" to the physical property you are measuring - e.g., temperature, pressure, etc.







simulate this circuit &ndash; Schematic created using CircuitLab


  I also know I have to bring it down to 3,3V.


So we need to divide the voltage by 3.3 / 24 = 7.3. 68k and 10k as shown in Figure 1 should do the job.

The resistor values are high to keep currents low. If you have a two-wire sensor it may need a certain current in the 'off' condition to power the electronics. In that case we may need to scale the resistors down by a factor of 10 or so. Let us know and post a link to the sensor datasheet.