Just cant work out persistance

I am trying to recall the historic state of a dimmer at a point in time

I log the time I want to recall by:
var time_play_started = now

I then (after another event has occurred) want to check the dimmer historic state back at the time captured by:
if(Lounge_Dimmer.historicState(time_play_started) == 100) {

I keep getting nulls in the error log
yet I know that the item is correct because
sendCommand(Lounge_Dimmer, ON) - on its own works

Persistence is also working an I can see values in habmin

can anyone help me?
Do I need to import some other libraries?
Does there need to be a value that matches exactly to the time_play_started variable in the persistence data, or does it find the closest one?

The return value of Lounge_Dimmer.historicState(time_play_started) is an HistoricItem instance, not a number. Using Lounge_Dimmer.historicState(time_play_started).state should work better.

The historicState query is implemented to do a range query from the time specified to the beginning of the historic data with the latest points being first in the results. The code then takes the first value it finds, if any. So it finds the most recent value prior to or equal to the queried time.

Thankyou! that was it!