Binary-Sensor with Influxdb

Hello,
I have a binary sensor called binary_sensor.dgbackup and it is checking the status of a LED. If the LED turns on (the government electricity supply is “OFF” and my apartment is on Generator backup -LED turns On). Generator backup is Peak Tariff for my purpose.

So I want to maintain a log in Influxdb of the timestamps when the binary_sensor.dgbackup is in On status and timestamp in Off status (log the times when state changes).

While I am able to see the binary_sensor.dgbackup in InfluxDB under state --> entity_id but I am not able to figure out how to log time.
Later I want to run queries for the duration we were on a generator supply.

How do I carry out this in InfluxDB. I looked for it and couldn’t find anything. If this has already been discussed and someone is aware of the link, please share. Thank you.

did you ever figure this out?

No, never got it working