diff --git a/README.md b/README.md index 6afa35e..e989d6e 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,22 @@ A plugin for the Decent Espresso DE1 machine that tracks water and filter replacement date 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. +You can also hit the reset button and will auto populate with todays date. + +## Features +- Track total water usage in liters or gallons +- Set a filter change date +- **Get notified when you reach a water usage threshold** - Set your desired threshold in the plugin settings and you'll receive a popup reminder when it's time to change your filter +- Reset counter when you change your filter + +## Usage +1. Set your preferred units (L or gallons) +2. Enter the date you last changed your filter +3. Set a filter change reminder threshold (e.g., 100L or 26gal) +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 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 Thank you Damian for some sanity checks and question answering. diff --git a/plugin.tcl b/plugin.tcl index a83cf0e..faa4521 100644 --- a/plugin.tcl +++ b/plugin.tcl @@ -1,11 +1,10 @@ -set plugin_name "de1_water_tracker_plugin" +set plugin_name "de1_water_tracker" 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 version 0.2 + variable description "Track total water usage and get notified when it's time to change your filter." variable name "Water Usage Tracker" variable settings @@ -15,24 +14,53 @@ namespace eval ::plugins::${plugin_name} { 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::de1_water_tracker::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_variable $page_name 1280 600 -font global_font -width 800 -fill "#444444" -anchor "center" -textvariable {$::plugins::de1_water_tracker_plugin::settings(display)} + add_de1_variable $page_name 1280 600 -font global_font -width 800 -fill "#444444" -anchor "center" -textvariable {$::plugins::de1_water_tracker::settings(display)} dui add entry $page_name 1280 760 -tags filter_date -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) \ + -textvariable ::plugins::de1_water_tracker::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 - 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 1280 890 -tags use_gallons -textvariable ::plugins::de1_water_tracker::settings(use_gallons) -fill "#444444" \ + -label [translate "Display in gallons"] -label_font Helv_10_bold -label_fill #4e85f4 -command ::plugins::de1_water_tracker::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 "" + dui add entry $page_name 1280 1010 -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::settings(filter_threshold_display) \ + -label [translate "Filter change reminder (L or gal)"] -label_pos {1280 950} \ + -label_font Helv_10_bold -label_width 1200 -label_fill "#444444" -label_anchor center + + add_de1_text $page_name 1280 1150 -text [translate "Reset Counter"] -font Helv_10_bold -fill "#4e85f4" -anchor "center" + add_de1_button $page_name ::plugins::de1_water_tracker::reset_counter 980 1120 1580 1220 "" + + # 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 +74,92 @@ 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] } + 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 de1_water_tracker + }]} { + # 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 de1_water_tracker + + # 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 de1_water_tracker 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 de1_water_tracker + } + + 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 +179,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 de1_water_tracker update_display + check_threshold } } } @@ -95,7 +190,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 +205,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::de1_water_tracker::on_state_change - plugins gui de1_water_tracker_plugin [build_ui] + plugins gui de1_water_tracker [build_ui] } } \ No newline at end of file