Can I make a sensor that has data from the past?

I want to make a custom integration that imports data from local power provider (bchydro) at least until i get one of the power montiors installed. After playing with the data available from their site it looks like things are done in hourly increments and at least lagging by 2 hours.

Is there are a way I can make the sensor set the value for the entire hour, and have it done in the past? I mostly want to be able see what i have on during high periods. And ideally be able to pull data into the energy dashboard. I do have the code working for fetching data into a sensor, just not sure if possible to backfill.

Rough first pass - GitHub - halkeye/homeassistant_bchydro: Plugin to pull data from bchydro website.

Gavin

1 Like

You mean you want this sensor to lag in time?
I believe I have read that is not possible.

But what you could do is to have your own power meter lag with two hours.
You just need to set up a sensor to duplicate the values from two hours ago, that way you will have the electric company’s and your lagging sensor show the “same” data.

If I had any idea how to do that to existing sensors. I’d have to do that for each and every plug and other power reporting sensor I had right? It would work, but i don’t think its worth the effort personally.

I see… I thought you had a CT clamp on the incoming line.
You probably could do it in one go, but the calculation would be very CPU intensive (I assume) so it would probably not be realistic

eventually. I am really excited about the idea, but logistics of buying it, and installing it, and everything means it probably wont be in the short term, and I can do software anytime.

In case you still want to try then the way I thought of doing this “timeshift” was with Node red.

Inject → get entities node, where you filter out the entities to loop (power reporting entities) → get history node → function node, where you loop the sensor data backwards until you get to 2 hours back and grab this value as the new value → Entity node, that saves the data to a new sensor.

1 Like

Why not simply inject the data at the appropriate place in the database.

I can look into that after work, but can you point me to any examples/info?

I am not sure this is possible (maybe it should be) but I feel this would be an ideal use for the History Stats. My thoughts would be to set the start time to now() - 2 hours, with a duration of maybe 1 minute or so. Reading through the documents and It is not clear if it is possible but, like I said, this would be a great use case.

1 Like