catduckgnaf / rtl_433_haos_addon

Add-On for RTL_433 Home Assistant Community Edition!
12 stars 2 forks source link

feature request - set max file size for log file #12

Closed iamjoshk closed 6 months ago

iamjoshk commented 6 months ago

Hi - using your new rtl_433 addon with great success. Thanks for picking this up to keep it going.

I've noticed that the log file will just keep growing in size. For now, I am just manually deleting log entries, but it would be great if the addon could have a feature that lets you set a max file size or some other way of limiting the file size.

catduckgnaf commented 6 months ago

So glad to hear that! The log file I have generated by default with the rtl_433.conf file.

You have a great point and I see few possible options.

  1. By default the json log can be commented out, so someone would need to enable it. A negative here is that updates don't overwrite an existing rtl_433.conf

  2. Because of the way the log file is generated, and the folder for it, I should be able to on every startup of the add-on fairly easily look for said file, and remove if greater than a certain size.

  3. Could simply delete the log file on every start of the application regardless of size.

My thoughts are to simply enable deletion at start up for now, I could push that update today work on add-on config variable for file size? Of even a boolean config option if someone didn't want it deleted.

any thoughts on preference and priority. Did you find the logging helpful? I lean towards leaving it and just removing the file on any restart.

catduckgnaf commented 6 months ago

@iamjoshk can you give this a try? https://github.com/catduckgnaf/rtl_433_haos_addon/releases/tag/2024.3.1

iamjoshk commented 6 months ago

One additional idea would be to rename the old log with a suffix, like .old or -1 so it can be checked if there's a crash or something.

I do find the log helpful. When I was creating a flex decoder for a device that doesn't have a built-in protocol, I noticed that it didn't capture the results from analyze pulses.

catduckgnaf commented 6 months ago

@iamjoshk that is exactly what I did. moves to output.json.bak

Also, feel free to make any changes to or suggestions to the discovery script for more devices. (if you want)

iamjoshk commented 6 months ago

Cool. I'll take a look at the update and the script in a little while.

The flex decoder is for a EV1527 which is very common, but every chip has different timings, so it can't be set up as a predefined protocol.

catduckgnaf commented 6 months ago

Cool. I'll take a look at the update and the script in a little while.

The flex decoder is for a EV1527 which is very common, but every chip has different timings, so it can't be set up as a predefined protocol.

I wonder if there is a way with some edits to the script we could make that a variable to pass through? I have seen the EV1527, so although I don't have one, I do believe it would help many others.

The script itself is located https://github.com/catduckgnaf/rtl_433_ha/blob/main/scripts/rtl_433_mqtt_hass.py

Still working on that being better at runtime. However if you edit the one at /config/rtl_433/scripts it will look for and load that one.

iamjoshk commented 6 months ago

Updated to 2024.3.1.

My log file is 27MB at the moment and it did not rename the existing log and start a new one. Tried restarting the addon, stopping/starting the addon, restarting HAOS itself, and then stopping/restarting the addon again.

The 27MB log file remains and a new one is not started.

catduckgnaf commented 6 months ago

Updated to 2024.3.1.

My log file is 27MB at the moment and it did not rename the existing log and start a new one. Tried restarting the addon, stopping/starting the addon, restarting HAOS itself, and then stopping/restarting the addon again.

The 27MB log file remains and a new one is not started.

Found the error, pushed a super minor release. Was my mistake with a path. Do you think 1MB is to low or should it be more?

Confirmed it will move the file, and upon success will delete the original.

2024.3.1.2 Let me know!

iamjoshk commented 6 months ago

I think ideal size will be dependent upon how many rtl_433 devices and how often they are triggered. Maybe a later release could let the user decide on size. I have 13 devices and 26 entities. I checked a random day's worth of log messages and it's 3.2MB.

iamjoshk commented 6 months ago

Updated to 2024.3.1.2 and the 27.6MB log was renamed to output.json.bak and a new log was started.

catduckgnaf commented 6 months ago

Updated to 2024.3.1.2 and the 27.6MB log was renamed to output.json.bak and a new log was started.

Excellent! Thank you. I will close this issue. I lean towards updating it to 5MB, also keeping in mind it only checks at startup, not any set interval for the moment. Thanks for the suggestion!

Feel free to join our discord, or any help/suggestions/previous work you have done any actually getting devices into HA, trying to make that a big next step is making things even easier for people who haven't had rtl_433 before.

Regardless, appreciate your time, and good suggestion!

iamjoshk commented 6 months ago

I have an automation that restarts the addon every day because I hop to a different frequency to pick up my water meter at the end of the day to measure usage per day, so I think my log will just roll over every day.

Thanks for turning this around so fast.

I'll see what I can contribute to help.

catduckgnaf commented 6 months ago

I can also likely said the log rotation as a user variable, or since you are one who requested it, if you have a preferred file size, happy to simply make that the default. :)

iamjoshk commented 6 months ago

User variable is the way to go!