jaroschek / home-assistant-myuplink

Custom Home Assistant integration for devices and sensors in myUplink account.
39 stars 8 forks source link

Set state_class on a temperature sensors, thus enabling long term statistics collection #66

Closed imsh closed 5 months ago

imsh commented 5 months ago

This allows drawing nice graphs of these sensors using statistics-graph

imsh commented 5 months ago

It might fix #53

jaroschek commented 5 months ago

Hello @imsh, thank you for your contribution.

roccolord commented 4 months ago

I fail to see that this is working properly, still only get 10 days on temp sensors image

imsh commented 4 months ago

I fail to see that this is working properly, still only get 10 days on temp sensors image

Are you trying to use the statistics-graph? The PR is not changing the max age of collected values, but rather allows to collect the aggregated values which normally cover longer periods. Fx this is my config and resulting graph: image

roccolord commented 4 months ago

OK, but why doesn't it work like other temperature sensors that also have long term statistics, ie displays the lts when doing normal HA graphs, like this: image

roccolord commented 4 months ago

Did do a graph like yours, but I have no data: image The last sensor is not a myuplink sensor, which has data. All the myuplink sensors are listed a statistics in developer tools. But only 5 days stored. Very strange!

imsh commented 4 months ago

This is how my bt1 graph looks in history view: image the data from statistics seems to be displayed fine.

Maybe HA is not updating the sensor's attribute properly if it was already created by an older version of the code which was not setting the attribute?

roccolord commented 4 months ago

The config looks to be ok: { "aliases": [], "area_id": null, "capabilities": { "state_class": "measurement" }, "config_entry_id": "31ddf43c6be83a9c9db1544bfebd1fef", "device_class": null, "device_id": "a6e46f88be6be37114f8e1d7e8d813c6", "disabled_by": null, "entity_category": null, "entity_id": "sensor.f1255_16_cu_nibef_f1255_16_cu_room_temperature_bt50", "hidden_by": null, "icon": null, "id": "3024723c2720d9b1063f0b5c52dc1193", "has_entity_name": false, "name": "Room temperature (BT50)", "options": { "conversation": { "should_expose": true }, "sensor": { "display_precision": null } }, "original_device_class": "temperature", "original_icon": null, "original_name": "F1255-16 CU Arrie NIBEF F1255-16 CU Room temperature (BT50)", "platform": "myuplink", "supported_features": 0, "translation_key": null, "unique_id": "myuplink_emmy-r-96125-20230919-06505918065019-80-1f-12-07-1f-f4_40033", "previous_unique_id": null, "unit_of_measurement": "°C" },

roccolord commented 4 months ago

I found that there a duplicates of state_attributues table with different config:

381 | 2660811100 | {"unit_of_measurement":"°C","device_class":"temperature","friendly_name":"Room temperature (BT50)"} -- | -- | -- 289325 | 500508076 | {"state_class":"measurement","unit_of_measurement":"°C","device_class":"temperature","friendly_name":"Room temperature (BT50)"} Both pointing to the same metadata_id, guess the upgrade made new attribute since it has the state_class set. Other attributes, from other integrations, just have one state_attribute row per. So I guess this is wrongly handled.
roccolord commented 4 months ago

It looks to be working now, I guess it started collecting historical data at a later date then I expected!