[SOLVED] Getting error when using timestamp for managing lights on and off with motion sensor

This is somewhat an XY Problem. Your over all approach is awkward and suboptimal. A more appropriate approach would be to use Timers. See Design Pattern: Motion Sensor Timer which has an example using both expire and another with Timers.

For lots of examples showing time comparisons, see Design Pattern: Simple State Machine (e.g. Time Of Day).

The root of your problem is “Dimmer off after 30 minutes without Motion” runs every minute. When you just start up OH, motionStamp is NULL because there has been no moton. You can’t cast NULL to DateTimeType.