I am having trouble getting accurate temperature readings over time from the lm335 temerature sensor.

I am using the LM335 class below to read the lm335 sensor connected to analog 0. The power is connected direct from the analog +/- pins. By reading other threads on here I believe I ended up with a 1k resistor connected to the sensor (though it's been a while). I have tried other variations of code that I have found in the forums here too.

A few days ago when I switched to the code below, I tweaked the lm335_offset number, which ended up at 621 in order to calibrate the sensor to match a thermometer in the room. It seemed to be working great for probably almost 2 days, but this morning I could tell it was much hotter in the room than my readings. In fact, it's about 30 degrees off (too low) this morning! No code changes, no electrical changes, it is just 30 degrees too low for some reason!

Can you measure the analog voltage from the LM335 with a voltmeter (e.g. a multimeter)? The LM335 relies on the resistor to supply enough curent to operate the chip. If it's too high (too many Ohms), not enough current will be supplied. This will usually result in the sensor reading too low. Maybe you could try a slightly smaller resistor, or maybe a connection has become loose?

You ideally need to use a 2k2 resistor, not 1k, to get the best accuracy (the datasheet specifies 1mA for its ratings and 5V - 2.98V is 2V for the resistor.)

You don't say what accuracy you want BTW - unless you have the sensor shielded from heat radiation and under forced-air-circulation you'll easily get 1C or so error from heat radiation from nearby heat sources (that includes you). For some bizarre reason thermal sensors are often encapsulated in black plastic, not metal cans (which pick up far less heat radiation).

Ideally you'd use a constant-current source and measure the voltage at both terminals (treat it as a 4-terminal device) so you don't see IR drops in the leads (although at 1mA that's not such a problem).

If you are using it remotely a 100pF across the leads at both ends will reduce the effect of RF pickup which could affect readings.