Cannot find simple open/close script

I am having troubel finding a simple way to do an open/closed loop script to make a magnetic door sensor ( alarm type ) that is NO to show up Closed then Show up open then the connection is broke ( door open ) so I can use that digital switch to make cayenne trigger other stuff when the door gets opened.

you can use this script to read the door sensor switch state and send it to cayenne https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Sensors/GenericDigitalInput/GenericDigitalInput.ino

I have a raspberry pi, do you have the code for pi it just says arduino on there.

you can either use cayenne agent or use cayenne python library to send data to cayenne https://github.com/myDevicesIoT/Cayenne-MQTT-Python and add https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/ to read button state.