Hall Effect Flow Se...
 
Notifications
Clear all

[Solved] Hall Effect Flow Sensor Input  

  RSS

not_5
(@not_5)
Eminent Member
Joined: 2 years ago
Posts: 33
October 27, 2020 8:04 pm  

Hey Kyle,

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.

Thanks!

 

This topic was modified 1 month ago by not_5

Quote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 368
October 27, 2020 8:17 pm  

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
self.set_custom_option("total_volume", my_volume)
volume_to_retrieve = self.get_custom_option("total_volume")

Mycodo Developer


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 368
October 27, 2020 8:19 pm  

If you just want it to persist while the Input is active, you should use self (e.g. "self.total_volume").

Mycodo Developer


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 368
October 27, 2020 8:22 pm  

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.

Mycodo Developer


ReplyQuote
not_5
(@not_5)
Eminent Member
Joined: 2 years ago
Posts: 33
October 27, 2020 8:27 pm  

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.


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 368
October 27, 2020 8:34 pm  

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.

Mycodo Developer


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 368
October 27, 2020 8:37 pm  

I also noticed that you could change:

            'type': 'text',
            'default_value': '1.0',

to:

            'type': 'float',
            'default_value': 1.0,

To already have it cast to the correct type when you want to pass it to ReadHall()

Mycodo Developer


ReplyQuote
not_5
(@not_5)
Eminent Member
Joined: 2 years ago
Posts: 33
October 27, 2020 9:11 pm  

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.


ReplyQuote