Draggon / hassio-hdd-tools

27 stars 13 forks source link

Unknown attribute and Home Assistant restart #1

Closed McGiverGim closed 3 years ago

McGiverGim commented 4 years ago

Thanks for your addon!!! Two things about it:

  1. When the addon finishes the test, for some reason it seems my Home Assistant restarts. Or at least it looses the connection for some seconds. Is that intended for some reason?
  2. My SSD has a lot of unknown attributes, but only one (the latest) appear in your sensor. Maybe you can concat the field ID to the Unknown_ Attribute name to publish all of them?
    SMART Attributes Data Structure revision number: 1                                                                                                                                                                                       
    Vendor Specific SMART Attributes with Thresholds:                                                                                                                                                                                        
    ID# ATTRIBUTE_NAME          FLAGS    VALUE WORST THRESH FAIL RAW_VALUE                                                                                                                                                                   
    1 Raw_Read_Error_Rate     -O--CK   100   100   050    -    0                                                                                                                                                                           
    5 Reallocated_Sector_Ct   -O--CK   100   100   050    -    0                                                                                                                                                                           
    9 Power_On_Hours          -O--CK   100   100   050    -    83                                                                                                                                                                          
    12 Power_Cycle_Count       -O--CK   100   100   050    -    41                                                                                                                                                                          
    160 Unknown_Attribute       -O--CK   100   100   050    -    0                                                                                                                                                                           
    161 Unknown_Attribute       PO--CK   100   100   050    -    100                                                                                                                                                                         
    163 Unknown_Attribute       -O--CK   100   100   050    -    11                                                                                                                                                                          
    164 Unknown_Attribute       -O--CK   100   100   050    -    881                                                                                                                                                                         
    165 Unknown_Attribute       -O--CK   100   100   050    -    3                                                                                                                                                                           
    166 Unknown_Attribute       -O--CK   100   100   050    -    1                                                                                                                                                                           
    167 Unknown_Attribute       -O--CK   100   100   050    -    1                                                                                                                                                                           
    168 Unknown_Attribute       -O--CK   100   100   050    -    7000                                                                                                                                                                        
    169 Unknown_Attribute       -O--CK   100   100   050    -    100                                                                                                                                                                         
    175 Program_Fail_Count_Chip -O--CK   100   100   050    -    0                                                                                                                                                                           
    176 Erase_Fail_Count_Chip   -O--CK   100   100   050    -    0                                                                                                                                                                           
    177 Wear_Leveling_Count     -O--CK   100   100   050    -    0                                                                                                                                                                           
    178 Used_Rsvd_Blk_Cnt_Chip  -O--CK   100   100   050    -    0                                                                                                                                                                           
    181 Program_Fail_Cnt_Total  -O--CK   100   100   050    -    0                                                                                                                                                                           
    182 Erase_Fail_Count_Total  -O--CK   100   100   050    -    0                                                                                                                                                                           
    192 Power-Off_Retract_Count -O--CK   100   100   050    -    39                                                                                                                                                                          
    194 Temperature_Celsius     -O---K   100   100   050    -    50                                                                                                                                                                          
    195 Hardware_ECC_Recovered  -O--CK   100   100   050    -    0                                                                                                                                                                           
    196 Reallocated_Event_Count -O--CK   100   100   050    -    0                                                                                                                                                                           
    197 Current_Pending_Sector  -O--CK   100   100   050    -    0                                                                                                                                                                           
    198 Offline_Uncorrectable   -O--CK   100   100   050    -    0                                                                                                                                                                           
    199 UDMA_CRC_Error_Count    -O--CK   100   100   050    -    24                                                                                                                                                                          
    232 Available_Reservd_Space -O--CK   100   100   050    -    100                                                                                                                                                                         
    241 Total_LBAs_Written      ----CK   100   100   050    -    2299                                                                                                                                                                        
    242 Total_LBAs_Read         ----CK   100   100   050    -    857                                                                                                                                                                         
    245 Unknown_Attribute       -O--CK   100   100   050    -    252

This is what I get:

unit_of_measurement: °C
friendly_name: Hdd Temp
raw_read_error_rate: '0'
reallocated_sector_ct: '0'
power_on_hours: '83'
power_cycle_count: '41'
unknown_attribute: '252'
program_fail_count_chip: '0'
erase_fail_count_chip: '0'
wear_leveling_count: '0'
used_rsvd_blk_cnt_chip: '0'
program_fail_cnt_total: '0'
erase_fail_count_total: '0'
power-off_retract_count: '39'
temperature_celsius: '50'
hardware_ecc_recovered: '0'
reallocated_event_count: '0'
current_pending_sector: '0'
offline_uncorrectable: '0'
udma_crc_error_count: '24'
available_reservd_space: '100'
total_lbas_written: '2294'
total_lbas_read: '853'
'00': '0'
boesing commented 3 years ago

I've created a PR which is already merged by @Draggon. You might check the README as you can now configure the attribute you want to use to get the attributes from.

As the the new flag performance_check is disabled by default, there should be no performance check at startup. Atleast for me that fixed the home-assistant restart.

Regarding your unknown_attribute, you might want to give the attributes_property a shot. The output_file is now a JSON file. You might want to search for the property which contains the data you expect to be passed to your sensor.

Not sure if the attributes are being squashed by smartctl --json aswell.

McGiverGim commented 3 years ago

Hi @boesing !! Sorry for this late response, but Github didn't notice me about your answer to my issue.

Reboot problem fixed disabling the performance_check, thanks!

I have updated to the latest version, and configured for the data produced by it I think correctly, but I don't know if I have understood your explanation.

My problem is that Home Assistant only shows me ONE unknown attribute: image

but the problem is that the original smart information, that I published in this thread contains several of them, and I want to access some. For example, I want to see the content of the attribute with ID 169, that I think is the remaining life of the SSD, but this info is not provided by the sensor. I suspect all the unknown attributes are added with the same "name" to the list, ending with one overwriting the earlier.

McGiverGim commented 3 years ago

Looking at the code:

https://github.com/Draggon/hassio-hdd-tools/blob/50c9c9ab04c89635b59ae4a55fa41f0c714f9b98/hdd_tools/data/main.sh#L27

Here it seems he uses the name attribute. What I propose is to use name+_+id when the name is Unknown_Attribute, but my .sh skills are very limited... Someone has an idea of what to change to accomplish that?

McGiverGim commented 3 years ago

I've found the way... I don't know if it is the best solution, but replacing by this:

            ATTRIBUTES=$(echo $ATTRIBUTES | jq 'map({(if .name == "Unknown_Attribute" then "Unknown_Attribute_" + (.id | tostring) else .name end): .raw.string | capture("^(?<value>[[:digit:]]+)").value | tonumber}) | add | with_entries(.key |= ascii_downcase)')

it works. I will try to push a PR.