How to use a number template for statistics

The use case is kWh info is not as useful for decision making as cash value.
I am looking to make a number template for each circuit and major load.

I seem to be unable to use this entity in any statistics elements

I have found notes that this needs to be added to a template to enable
state_class: “measurement”
But that option is not available in the number helper.
I prefer to use the UI to manage these objects rather than 60-70 files. I assume this is just not exposed to the UI. Where are the files for helper definitions are stored so I can test adding it there?

Or is there a better method to create a currency cost entity?
Seems like a very common use, is there a normal way to do this?

Seems like there should be a cost object type, and a helper that can link to a kWh, liters etc entity and create a linked money value.

A Template number is not a Template sensor… if you want statistics you need to use a Template sensor, which will give you the options to set device class, state class, and unit of measurement.

Sensor - Device Class

image

I guess I never properly understood the distinction.
So a sensor is a number or bool with a specific class that allows extensible functions?

I was thinking you assigned a class to a number.

There is no “sensor” helper in the UI, then all this needs to be done via files?

There is… it’s two lines down from where you selected your Template number:

number entities, like input_number entities, are distinguished by the fact that they are designed to be changed directly by the user. These entities can be manipulated via dashboards as well as script actions like number.set_value.

A sensor’s value is not directly adjustable by the user.

1 Like

A sensor is an entity that holds a value that is not entered manually. Number entities and input_number enitites are entities that allow user input.

For sensors to have statistics, they need to be numerical (having a unit_of_measurement is how Home Assistant determines if a sensor is numerical). Input numbers and numbers are numerical by design - they always have a unit of measurement (it can be an empty string).

For a sensor to have statistics, they also need to have the right state_class and device_class. Input_numbers and numbers generally do not have the state_class needed to keep statistics. That is not so strange, as they are not measurements or accumulated totals but user input.

Are you interested in manual entry, or can the value be calculated? Being a number entity and a numerical entity are not necessarily the same thing.

1 Like

To get back to the topic at hand, monetary entities have weird limitations because they are reserved for price, which is considered not a measurement or total. This totally ignores the fact that a monetary is a device class type designation that is totally separate from what state class is describing.

A price can be considered a measurement, a balance can be considered a total and an energy total multiplied by the energy price can be considered total_increasing. They are all monetary. However, Home Assistant does not agree with that.

The solution is to avoid device class monetary whenever you can. Just use your favorite unit_of_measurement to represent the valuta so it is numerical. Then set the state class to what is appropriate to you. And don’t tell Frenck about it :wink:

Thank you I am apparently blind.
Possibly still blind.

Monetary seems not to be available option, and it is not free typeable:

Also I don’t understand the difference between number and input_number if both are intended to be UI settable.

Read the post just above yours. You probbly missed it as we typed simultaniously. Monetary is considered a special device class. It might be filtered out there.

Interesting, so HA needs two separate Device Class, one for Monetary Rates (USD/L, USD/kWh) and a Real Monetary Total (USD,GBP,EUR)

No, Freck just needs to get of his high horse and see that monetary is a flexible term :slight_smile: But what you say could also help settle the dispute. I just keep avoiding monetary because it does not add much value until this is fixed.

I created a template with no device class, Units USD, and State Class total Increasing.

It is recognized as a statistics sensor now for UI, without a device class.
Waiting for data to accumulate to test.

Even separating them if you have a market rate agreement, and a data feed of rates that changes through the day, Rates should also be available to statistics like high-low-mean.

Monetary is translated to Balance in the UI.