Of course - didn't think about that. That resistor has to deal with the heat.
The power rating of the resistor depends on the actual voltages and how long it lasts. I was expecting you see spikes, so short pulses only. Then it's no problem.
The value of the resistor is not very critical. It is mainly based on being as big as possible, supplying just enough current to the opto at 12V input for it to pull down the output signal. So that's what you should test as well: the lowest voltage that you want to detect.