diff --git a/README.md b/README.md index 6afa35e..18a8fa4 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,31 @@ -# de1-water-tracker-plugin -A plugin for the Decent Espresso DE1 machine that tracks water and filter replacement date +# RO Filter Monitor Plugin -Basically you should be entering a date in the settings to track your filter. -You can also hit the reset button and will auto populate with todays date. +A plugin for the Decent Espresso DE1 machine that monitors RO (Reverse Osmosis) filter usage and reminds you when it's time to change your filter. -To-do: - - Add a ping to let you know when a set total L/gal has been reached for filter change - - Add a 2 months, 3 months, 6 months, and year selection for time based notifs +Track your water consumption and get timely notifications to ensure optimal water quality for your espresso. -Thank you Damian for some sanity checks and question answering. +## Features +- Track total water usage in liters or gallons +- Set a filter change date to track how long your current filter has been in use +- **Get notified when you reach a water usage threshold** - Set your desired threshold in the plugin settings and you'll receive a notification when it's time to change your filter +- Reset counter when you change your filter to start tracking the new one + +## Usage +1. Set your preferred units (L or gallons) +2. Enter the date you last changed your RO filter +3. Set a filter change reminder threshold (e.g., 100L or 26gal based on your filter's capacity) +4. The plugin will track your water usage and notify you when the threshold is reached +5. When you change your filter, hit "Reset Counter" to start tracking again + +## Installation +1. Copy the `ro_filter_monitor` directory into your DE1 plugins folder +2. Enable the plugin in your DE1 settings +3. Configure your filter change settings + +## To-do +- Add time-based notifications (2 months, 3 months, 6 months, 1 year options) +- Support for multiple filter stages + +--- + +Thank you Damian for some sanity checks and question answering. diff --git a/filelist.txt b/filelist.txt new file mode 100644 index 0000000..2314159 --- /dev/null +++ b/filelist.txt @@ -0,0 +1,2 @@ +plugin.tcl +settings.tdb diff --git a/plugin.tcl b/plugin.tcl index a83cf0e..e941fed 100644 --- a/plugin.tcl +++ b/plugin.tcl @@ -1,38 +1,70 @@ -set plugin_name "de1_water_tracker_plugin" +set plugin_name "ro_filter_monitor" namespace eval ::plugins::${plugin_name} { - variable plugin_name "de1_water_tracker_plugin" variable author "Sy_Butter" variable contact "Github" - variable version 0.1 - variable description "Track total water usage to help schedule filter changes." - variable name "Water Usage Tracker" + variable version 0.2 + variable description "Monitor RO filter usage and get notified when it's time to change your filter." + variable name "RO Filter Monitor" variable settings proc build_ui {} { variable settings - set page_name "plugin_water_tracker_page_default" + set page_name "plugin_ro_filter_monitor_page_default" add_de1_page "$page_name" "settings_message.png" "default" add_de1_text $page_name 1280 1310 -text [translate "Done"] -font Helv_10_bold -fill "#fAfBff" -anchor "center" - add_de1_button $page_name {say [translate {Done}] $::settings(sound_button_in); page_to_show_when_off extensions} 980 1210 1580 1410 "" + add_de1_button $page_name {say [translate {Done}] $::settings(sound_button_in); ::plugins::ro_filter_monitor::save_and_close} 980 1210 1580 1410 "" - add_de1_text $page_name 1280 300 -text [translate "Water Tracker"] -font Helv_20_bold -width 1200 -fill "#444444" -anchor "center" -justify "center" + add_de1_text $page_name 1280 300 -text [translate "RO Filter Monitor"] -font Helv_20_bold -width 1200 -fill "#444444" -anchor "center" -justify "center" - add_de1_variable $page_name 1280 600 -font global_font -width 800 -fill "#444444" -anchor "center" -textvariable {$::plugins::de1_water_tracker_plugin::settings(display)} + # Left column - Volume/Settings + add_de1_variable $page_name 680 500 -font global_font -width 600 -fill "#444444" -anchor "w" -textvariable {$::plugins::ro_filter_monitor::settings(display_volume)} - dui add entry $page_name 1280 760 -tags filter_date -width 12 -font Helv_10 \ + dui add entry $page_name 680 740 -tags filter_threshold -width 12 -font Helv_10 \ -borderwidth 1 -bg #fbfaff -foreground #4e85f4 -relief flat \ -highlightthickness 1 -highlightcolor #000000 \ - -textvariable ::plugins::de1_water_tracker_plugin::settings(filter_change_date) \ - -label [translate "Filter Last Changed Date"] -label_pos {1280 700} \ - -label_font Helv_10_bold -label_width 1200 -label_fill "#444444" -label_anchor center + -textvariable ::plugins::ro_filter_monitor::settings(filter_threshold_display) \ + -label [translate "Filter change reminder (L or gal)"] -label_pos {680 680} \ + -label_font Helv_10_bold -label_width 1200 -label_fill "#444444" -label_anchor w - dui add dcheckbox $page_name 1280 860 -tags use_gallons -textvariable ::plugins::de1_water_tracker_plugin::settings(use_gallons) -fill "#444444" \ - -label [translate "Display in gallons"] -label_font Helv_10_bold -label_fill #4e85f4 -command ::plugins::de1_water_tracker_plugin::toggle_units + dui add dcheckbox $page_name 680 820 -tags use_gallons -textvariable ::plugins::ro_filter_monitor::settings(use_gallons) -fill "#444444" \ + -label [translate "Display in gallons"] -label_font Helv_10_bold -label_fill #4e85f4 -command ::plugins::ro_filter_monitor::toggle_units - add_de1_text $page_name 1280 1000 -text [translate "Reset Counter"] -font Helv_10_bold -fill "#4e85f4" -anchor "center" - add_de1_button $page_name ::plugins::de1_water_tracker_plugin::reset_counter 980 970 1580 1070 "" + # Right column - Filter/Actions + add_de1_variable $page_name 1480 500 -font global_font -width 600 -fill "#444444" -anchor "w" -textvariable {$::plugins::ro_filter_monitor::settings(display_filter)} + + dui add entry $page_name 1480 740 -tags filter_date -width 12 -font Helv_10 \ + -borderwidth 1 -bg #fbfaff -foreground #4e85f4 -relief flat \ + -highlightthickness 1 -highlightcolor #000000 \ + -textvariable ::plugins::ro_filter_monitor::settings(filter_change_date) \ + -label [translate "Filter Last Changed Date"] -label_pos {1480 680} \ + -label_font Helv_10_bold -label_width 1200 -label_fill "#444444" -label_anchor w + + add_de1_text $page_name 1480 900 -text [translate "Reset Counter"] -font Helv_10_bold -fill "#4e85f4" -anchor "w" + add_de1_button $page_name ::plugins::ro_filter_monitor::reset_counter 1480 870 1880 930 "" + + # Create custom filter warning page + add_de1_page "water_filter_warning" "settings_message.png" "default" + + # Warning message + add_de1_text "water_filter_warning" 1280 700 \ + -text [translate "Time to change your water filter!"] \ + -font Helv_20_bold -fill "#dd0000" -anchor "center" -justify "center" -width 1200 + + # Additional info text + add_de1_text "water_filter_warning" 1280 850 \ + -text [translate "You've reached your set water usage threshold.\nReplace the filter, then reset the counter in plugin settings."] \ + -font Helv_10 -fill "#666666" -anchor "center" -justify "center" -width 1200 + + # Dismiss button + add_de1_text "water_filter_warning" 1280 1310 \ + -text [translate "OK"] \ + -font Helv_10_bold -fill "#fAfBff" -anchor "center" + + add_de1_button "water_filter_warning" \ + {say [translate {OK}] $::settings(sound_button_in); page_to_show_when_off off} \ + 980 1210 1580 1410 "" return $page_name } @@ -46,26 +78,94 @@ namespace eval ::plugins::${plugin_name} { if {[info exists settings(use_gallons)] && $settings(use_gallons)} { set value [expr {$settings(total_volume) / 3785.41}] set units "gal" + # Update threshold display + if {$settings(filter_threshold_ml) > 0} { + set settings(filter_threshold_display) [format "%.1f" [expr {$settings(filter_threshold_ml) / 3785.41}]] + } } else { set value [expr {$settings(total_volume) / 1000.0}] set units "L" + # Update threshold display + if {$settings(filter_threshold_ml) > 0} { + set settings(filter_threshold_display) [format "%.1f" [expr {$settings(filter_threshold_ml) / 1000.0}]] + } } set settings(filter_change_date) [string trim $settings(filter_change_date)] - set settings(display) [format [translate "Total water used: %.2f %s\nFilter last changed: %s"] $value $units $date_text] + # Split display into two columns + set settings(display_volume) [format [translate "Total water used:\n%.2f %s"] $value $units] + set settings(display_filter) [format [translate "Filter last changed:\n%s"] $date_text] + } + + proc update_threshold {} { + variable settings + # Convert display value to milliliters based on current unit + if {[catch { + set threshold_value [string trim $settings(filter_threshold_display)] + set old_threshold [expr {[info exists settings(filter_threshold_ml)] ? $settings(filter_threshold_ml) : 0}] + + if {$threshold_value eq "" || $threshold_value == 0} { + set settings(filter_threshold_ml) 0 + } else { + if {$settings(use_gallons)} { + set settings(filter_threshold_ml) [expr {$threshold_value * 3785.41}] + } else { + set settings(filter_threshold_ml) [expr {$threshold_value * 1000.0}] + } + } + + # If threshold changed, reset notification flag so user can be notified again + if {$old_threshold != $settings(filter_threshold_ml)} { + set settings(notification_shown) 0 + } + + save_plugin_settings ro_filter_monitor + }]} { + # Invalid input, reset to current value + update_display + } + } + + proc check_threshold {} { + variable settings + + # Convert the display value to ml before checking (in case user just entered it) + update_threshold + + # Only check if threshold is set and notification hasn't been shown + if {$settings(filter_threshold_ml) > 0 && !$settings(notification_shown)} { + if {$settings(total_volume) >= $settings(filter_threshold_ml)} { + set settings(notification_shown) 1 + save_plugin_settings ro_filter_monitor + + # Navigate to warning page instead of popup + set_next_page off water_filter_warning + page_to_show_when_off water_filter_warning + } + } } proc reset_counter {} { variable settings set settings(total_volume) 0 set settings(filter_change_date) [clock format [clock seconds] -format "%Y-%m-%d"] - save_plugin_settings $::plugins::de1_water_tracker_plugin::plugin_name + set settings(notification_shown) 0 + save_plugin_settings ro_filter_monitor update_display popup [translate "Counter reset"] } proc toggle_units {} { - save_plugin_settings $::plugins::de1_water_tracker_plugin::plugin_name + variable settings + # When toggling units, convert the threshold stored in ml to the new unit for display update_display + save_plugin_settings ro_filter_monitor + } + + proc save_and_close {} { + variable settings + # Save the threshold value before closing + update_threshold + page_to_show_when_off extensions } proc on_state_change {event_dict} { @@ -85,8 +185,9 @@ namespace eval ::plugins::${plugin_name} { Descale - AirPurge { set settings(total_volume) [expr {$settings(total_volume) + $::de1(volume)}] - save_plugin_settings $::plugins::de1_water_tracker_plugin::plugin_name + save_plugin_settings ro_filter_monitor update_display + check_threshold } } } @@ -95,7 +196,14 @@ namespace eval ::plugins::${plugin_name} { proc main {} { variable settings if {[array size settings] == 0} { - array set settings { total_volume 0 filter_change_date "" use_gallons 0 } + array set settings { + total_volume 0 + filter_change_date "" + use_gallons 0 + filter_threshold_ml 0 + filter_threshold_display "0" + notification_shown 0 + } } else { if {![info exists settings(filter_change_date)]} { set settings(filter_change_date) "" @@ -103,10 +211,19 @@ namespace eval ::plugins::${plugin_name} { if {![info exists settings(use_gallons)]} { set settings(use_gallons) 0 } + if {![info exists settings(filter_threshold_ml)]} { + set settings(filter_threshold_ml) 0 + } + if {![info exists settings(filter_threshold_display)]} { + set settings(filter_threshold_display) "0" + } + if {![info exists settings(notification_shown)]} { + set settings(notification_shown) 0 + } } update_display - ::de1::event::listener::on_major_state_change_add ::plugins::de1_water_tracker_plugin::on_state_change + ::de1::event::listener::on_major_state_change_add ::plugins::ro_filter_monitor::on_state_change - plugins gui de1_water_tracker_plugin [build_ui] + plugins gui ro_filter_monitor [build_ui] } } \ No newline at end of file diff --git a/settings.tdb b/settings.tdb index ba64bba..302f0a2 100644 --- a/settings.tdb +++ b/settings.tdb @@ -1,3 +1,13 @@ -total_volume 0 -filter_change_date "" -use_gallons 0 \ No newline at end of file +display {Total water used: 23.86 L +Filter last changed: 2025-10-24} +display_filter {Filter last changed: +2025-10-24} +display_volume {Total water used: +28.20 L} +filter_change_date 2025-10-24 +filter_threshold_display 50.0 +filter_threshold_ml 50000.0 +notification_shown 0 +total_volume 28196.059855957028 +use_gallons 0 +