Is there a way to create a statistics type entity via helpers?
I.e. at the moment I have an input_number but honestly it could be anything that can be updated…
I’m not aware of any way to explicitely set the state class on input numbers. You may have to use a template sensor as an intermediate.
How would one go about doing that?
If it helps I already have a sensor which I’m using for UI representation (sensor.input_number_name) to remove the unneeded decimal point
I get this error when I try to add a data-source according to the video above

Hello, I would like to ask, if I want to retention only 2 sensor for 30 days, so this config correct?
recorder:
purge_keep_days: 30
include:
entities:
- sensor.sma_daily_yield_wh
And other sensor keep retention default 10 days?
That’s not possible. You can only set days for the whole database.
Petro, Thank You your answer.
When I’ve setup mariaDB on my nas, how do I change the retention to infinite?
Maybe I missed the reply here. But is it then 0 for infinit or do I need to fix that different?
and although this has gone stale, if i set up recorder to use an external DB does that include the history and the statistics… My DB runs on an external NVME server so im not worried about disk performance. I currently running an alternative HA solution nad its got 5 years worth of data, which i do occasionally go back to…
Just a question, reading this topic and thinking out of the box.
When I add a MQTT Sensor configured by Node-Red, for example:
The function node contains:
(this is a working setup I wrote to add any virtual sensor and used for more then a year. BTW dont just copy/paste because logTimeStamp is a custom variable.)
var logTimeStamp = global.get('logTimeStamp')||"No Timestamp";
var _topicBase = "homeassistant";
var _topicComponent = "sensor"
var _topicNodeId = "presence";
var _topicDeviceName = "detection";
var _topic = _topicBase + "/" + _topicComponent + "/" + _topicNodeId + "/" + _topicDeviceName
var _qos = 2;
var _retain = true;
var _payload = {
"name": "Presence Detection",
"icon": "hassio:eye-outline",
"unique_id": "mqtt_presencedetection",
"has_entity_name": "true",
"node_id": _topicNodeId,
"state_topic": _topic + "/state",
"device": {
"name": "Mqtt Security",
"manufacturer": "MQTT Hass.io",
"model": "Custom",
"identifiers": ["Mqtt Security"],
"sw_version": "20230803",
"suggested_area": "Algemeen"
}
};
if (msg.payload === '' ){
node.status({fill:"red",shape:"dot",text: logTimeStamp + " " + _topic});
_topic = _topic + "/config";
_qos = 0;
_retain = false;
_payload = '';
} else {
node.status({fill:"green",shape:"dot",text: logTimeStamp + " " + _topic});
_topic = _topic + "/config";
}
var message = {
topic: _topic,
qos: _qos,
retain: _retain,
payload: _payload
};
return message;
The MQTT device is using (as an example) just four states: “home”, “away”, “sleep”, “holliday”.
The question, can I add, at the var _payload config, to get the four states to be stored in the long-term-statistics? :
¨device_class": "enum",
"options": {}
If so, how do I configure the options list and can this be a way to do it?
Any idea?
Can I ask why? I have a pump monitor (on a sump pump) that I would like to keep the data for about 18 months for comparison purposes. I guess I am interested in whether this is a fundamental reason from an HA perspective or the issue of writes to an SD card. Trying to learn. Thanks.
Performance issues. Very large SQLite databases can have an adverse effect on HA performance.
Unfortunately long term statistics (kept forever) is not generated for binary entities like switches, valves, input_booleans, etc… because the statistics would take up just as much room as the state values. Just time averaging a binary sensor would give odd results. e.g. if your pump was on for 50% of an hour is that on or off for the hourly average?
I use a time series database (InfluxDB) to keep data like that for two years.
I’m completely new to HA. I’m searching for long-term sensor data storage and stumbled upon this thread.
Is InfluxDB the only officially supported way to store long-term sensor data?
No TDengine, TimescaleDB or similar?
I don’t want to start a pro/con InfluxDB but reading through many forum posts there is a good chance that someone will ask the question why not simply using InfluxDB.
InfluxDB v1 is basically EoL since ages
InfluxDB v2 is also not really maintained anymore and basically is something (besides the name) fully different compared to v1.
InfluxDB v3 again is some completely different product compared to v1 and v2 and they started with the licensing nightmare where they partly rolled back for home-users.
Simply speaking - I personally consider the politics behind InfluxDB completely erratic and so I moved (before HA) from InfluxDB to other DBs and I really only want to start using InfluxDB again if that is a “must” to reliably have long-term data storage in HA (without fiddling days in the background which is overwhelming for a newbie).
(just my opinion to answer the question in advance why not simply use InfluxDB).
So yes, I can use InfluxDB but I’d like to avoid it if there is any other product equally easy to set up in HA. Is there any?
Long term storage exists in HA. Is the current LTS system not good enough?
Thanks, petro, like I wrote - I’m a newbie.
So reading through tons of docs it always says default retention period for data is 10 days and it should not be extended to more than 30 days.
30 days is not sufficient for me because for some stuff I will need to do calculations or otherwise follow up on data months or even a year later.
That’s includes all different kind of sensors, some have decimal values (measurements), some are binary, some are numeric values (no measurements, like modbus register values where certain values have certain functions), some are counters.
Again my understanding with the documentation was that the retention is only 10 days.
History retention is only 10 days, however long term statistics is endless. If LTS does not suit your needs, you’d need to set up an external database like Influx.
Thank you!
So, did some more reading and I saw LTS will aggregate values. That’s unfortunately not sufficient for my use case so I’ll need some external DB.
So going back to my original post:
Is it correct that only InfluxDB is fully integrated for this purpose (in terms of a GUI clickable solution)? Messing with the config files would be overwhelming for me currently.
