kizniche / Mycodo

An environmental monitoring and regulation system
http://kylegabriel.com/projects/
GNU General Public License v3.0
2.95k stars 494 forks source link

Measurement is always None though the automation works #1206

Closed lalebarde closed 1 year ago

lalebarde commented 2 years ago

Describe the problem/bug

[I have one function to open a solenoid valve (not listed here) and to activate a conditional controller that monitors a sensor which is True when the tank is full. When this condition is fulfilled, it closes the valve. When I run it, it works, the tank is filled and the water feed is stopped. But, when I look at the logs, the measurement looks always None, and the message f"Tank full, sensor = {measurement}" (f"Cuve pleine, Cuve Niv Haut = {measurement}" in the listing below) does not appear in the logs as expected]

Versions:

Reproducibility

Please list specific setup details that are involved and the steps to reproduce the behavior:

  1. [Activate the controller]
  2. [Make the sensor change state for at least 3 seconds = 3x the sampling rate]
  3. [Wait a few seconds (1s sampling rate)]
  4. [See the logs]

Expected behavior

[The measurement should not be None, and the value should appear. Then when the sensor is made change its state, the value measured should change, and the message should appear in the logs]

Screenshots

[Here is a full session log where I do trigger the sensor (light on) "Test Cuve Niv Haut" is the name of the conditional controller "Cuve Niv Haut" is the sensor name 2022-06-23 23:00:41,370 - INFO - mycodo.controllers.controller_conditional_960d9665 - Activated in 132.9 ms 2022-06-23 23:00:41,415 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:41,538 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:42,567 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:42,701 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:43,464 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:43,568 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:44,595 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:44,679 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:45,456 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:45,548 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:46,580 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:46,695 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:47,473 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:47,611 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:48,644 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:48,715 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:49,491 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:49,602 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:50,653 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:50,835 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:51,615 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:51,775 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:52,561 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:53,100 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:53,652 - INFO - mycodo.controllers.controller_conditional_960d9665 - Test Cuve Niv Haut 2022-06-23 23:00:53,869 - INFO - mycodo.controllers.controller_conditional_960d9665 - Cuve Niv Haut = None 2022-06-23 23:00:54,374 - INFO - mycodo.controllers.controller_conditional_960d9665 - Deactivated in 214.4 ms]

Additional context = Conditional Statement

self.logger.info("Test Cuve Niv Haut") # Daemon Log
measurement = self.condition("{b5f6a76b}") 
self.logger.info(f"Cuve Niv Haut = {measurement}") # Check this measurement in the Daemon Log
if measurement is not None:  # If a measurement exists
    if measurement == True:
        self.message += f"Cuve pleine, Cuve Niv Haut = {measurement}\n"
        self.logger.info(f"Cuve pleine, Cuve Niv Haut = {measurement}")
        self.run_all_actions(message=self.message)  # Run all actions sequentially

image

kizniche commented 1 year ago

I would enable debug mode logging for the output as well so you can see exactly where that's executed in the log. From your log, it appears the Conditional never actually executes any of the code in the lower block.

kizniche commented 1 year ago

Looking more closely at the code, you have the Max Age set to 3 seconds, which means None will be returned if there is no measurement stored in the database from the past 3 seconds. Having such a short period will certainly cause issues with retrieving measurements reliably.