[Solved] Hall Effect Flow Sensor Input
I'm trying to create an input for a hall effect based flow sensor... it's working fine, except I'm not sure the best way to get the total volume to continue to iterate. After every sample period, the total volume resets. Is there anyway to have a persistent total without using a separate math SUM input? I'm attaching the code as a TXT file.
I recently made these nice set_custom_option() and get_custom_option() (code ref) functions for inputs that store and retrieve values in the database, which will persist across deactivations/activations. Here's an example how you would use them in your input module:
volume_to_store = 40.5
volume_to_retrieve = self.get_custom_option("total_volume")
If you just want it to persist while the Input is active, you should use self (e.g. "self.total_volume").
Also, if you would like to include this Input in the built-in set, after you get it tuned to your liking, please submit a pull request on github, or alternatively I can add it myself if you would like.
Cool. I think I want the total volume to be calculated only during the the current session versus across multiple activations... if someone wants the total across multiple activations, they can use the SUM math function to get the total over a certain period of time. I'll let you know if I have any issues and put through a pull request when done.
I would be inclined to give the user the option, with a "custom_option" selection box to either "Clear total volume at deactivation/reboot" or "store total volume indefinitely". I can think of a couple use cases for both, rather than relying on a math controller. I also like to think about spontaneous reboots from power outages.
I also noticed that you could change:
'type': 'text', 'default_value': '1.0',
'type': 'float', 'default_value': 1.0,
To already have it cast to the correct type when you want to pass it to ReadHall()
I'm going to do a pull request with the input having a variable 'session_total_volume' and a clear session total button. You can add a 'sensor_total_volume' variable (and a clear sensor total button) with the custom option for others when you pull the code, if you'd like.