Add a filter to timeseries pairs

You have two subqueries that both contain a column named datetime. When you say:

where datetime >= DATEADD(Hour, -25, GETDATE())

You need to tell SQL Server which one you mean. So either:

where tOn.datetime >= DATEADD(Hour, -25, GETDATE())

... or ...

where tOff.datetime >= DATEADD(Hour, -25, GETDATE())

I'm going to guess it should be tOn.