Custom sensors


I am trying to achieve the following, however I can’t find a way to do it. Maybe it’s very easy, but I’m stuck…
I want to make a sensor (or similar) which updates every day at midnight. This would basically set a certain meter reading of gas and a second sensor (or similar) would set the daily usage of gas. I don’t want to use a input_number, as it shouldn’t be able to change it manually.
Basically I would like to have a dummy sensor which I can update through automations.

Please let me know how I can achieve this!

Answer to your question: You can to that e.g. with AppDaemon (HA addon). At least that’s the way I create and update “dummy sensors”.
But: Do you know

That could be what you are looking for, without an automation. Daily usage of gas e.g.

If you don’t want to use a utility meter with a daily cycle (it updates all day and resets at midnight), you can do this:

Use a template sensor. Template - Home Assistant

Set the scan interval to something huge (years). Entity integration platform options - Home Assistant

Update your sensor with the home assistant update entity service, in an automation with a time trigger set to midnight. Service calls - Home Assistant

I am not able to follow you exactly.
For the template sensor I need to set a value_template. But what should I put there?
And do I set the scan interval for only that template sensor? How?

Your meter readings. You know, the ones you want to record at midnight.


By adding that option to your sensor definition.

Thanks! However, I don’t see how to add the scan interval to the template sensor. This is not clear to me from the page you linked and it’s not mentioned in the template sensor page at all.
Can you help me?

Just a add it to the sensor definition like any other option.

Are you sure that the scan interval is a valid option? Scan intervals are only on specific devices, not all sensors & platforms utilize the field. I.E. both template sensors and utility meter sensors do not use scan interval.

No I’m not. Because the documentation is about as vague as it can be about it.

Well if yiu say so, I believe you and that’s spanners to that plan.

Where does this data actually come from? Template sensors can’t make external API calls, they can only massage other HA state into new state via templates. So how does the meter reading data get into this template? Is it actually the sensor which you only want to update at midnight or do you have an API or something which pulls meter reading data and you only want to call that at midnight?