Email alert is not send

I have set up email alerts and received the test email successfully. I set up a conditional controller for temp alerts and pressed the “execute all actions” button. I received the email soon after. Then I warmed the temp sensor with hand and raised the temperature over the max limit for a few minutes but received no email. I see that the status of the controller shows as “inactive” even though I did activate it.

1 Like

I had copied the code from the instructions on the web page instead of modifying the one in mycodo / functions in the back end.
So I have set up this function again and now the emals are send correctly when pressing the “execute all actions” button.
But when I warm up the temp sensor with my hand to the upper limit set temp nothing happens.
I post the code below, maybe one of you can see what is wrong here


Full Conditional code:

  1: import os
  2: import sys
  3: sys.path.append(os.path.abspath('/var/mycodo-root'))
  4: from mycodo.controllers.base_conditional import AbstractConditional
  5: from mycodo.mycodo_client import DaemonControl
  6: control = DaemonControl(pyro_timeout=30.0)
  7: 
  8: from datetime import datetime
  9: 
 10: class ConditionalRun(AbstractConditional):
 11:     def __init__(self, logger, function_id, message):
 12:         super().__init__(logger, function_id, message, timeout=30.0)
 13: 
 14:         self.logger = logger
 15:         self.function_id = function_id
 16:         self.variables = {}
 17:         self.message = message
 18:         self.running = True
 19:         self.loop_count = 0
 20: 
 21:     def conditional_code_run(self):
 22:         # Example code for learning how to use a Conditional. See the manual for more information.
 23:         self.logger.info("This INFO log entry will appear in the Daemon Log")
 24: 
 25:         self.loop_count += 1  # Counts how many times the run code has been executed
 26: 
 27:         measurement = self.condition("ad4e1c79")  # Replace ID with correct Conditional ID
 28:         self.logger.info(f"Measurement value is {measurement}")
 29: 
 30:         if measurement is not None:  # If a measurement exists
 31:             self.message += "This message appears in email alerts and notes.\n"
 32: 
 33:             if measurement < 23:  # If the measurement is less than 23
 34:                 self.message += f"Measurement is too Low! Measurement is {measurement}\n"
 35:                 self.run_all_actions(message=self.message)  # Run all actions sequentially
 36: 
 37:             elif measurement > 34:  # Else If the measurement is greater than 27
 38:                 self.message += f"Measurement is too High! Measurement is {measurement}\n"
 39:                 # Replace "qwer5678" with an Action ID
 40:                 self.run_action("bb28109a", message=self.message)  # Run a single specific Action
 41:                 self.run_action("cbf04a4e", message=self.message)  # Run a single specific Action
 42: 
 43:     def function_status(self):
 44:         # Example code to provide a return status for other controllers and widgets.
 45:         status_dict = {
 46:             'string_status': f"The controller has looped {self.loop_count} times at {datetime.now()}",
 47:             'loop_count': self.loop_count,
 48:             'error': []
 49:         }
 50:         return status_dict

pylint code analysis:

************* Module mycodo.user_python_code.conditional_d8f88770-88c1-4639-9aa7-1fe77654b9ed
ko/Mycodo/mycodo/user_python_code/conditional_d8f88770-88c1-4639-9aa7-1fe77654b9ed.py:8:0: C0411: standard import "from datetime import datetime" should be placed before "from mycodo.controllers.base_conditional import AbstractConditional" (wrong-import-order)

------------------------------------------------------------------
Your code has been rated at 9.70/10 (previous run: 9.70/10, +0.00)

I have also tested this with a DHT22 sensor instead and it would also not trigger the email.
Is this working for you guys? Could you show your settings / code so I can figure out what is wrong?

Yesterday I a few hours after I changed to the DHT22 sensor I started to receive SMS warnings (have set up two email accounts, one to my email and another one to a sms service).
I deactivated the conditional controller when I came home.Today I turned it back and and again no
emails send. I looked at the logs and found that something is maybe wrong with my email server.

2023-09-12 13:57:07,212 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 13:57:07,465 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.7
2023-09-12 13:58:05,310 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 13:58:05,574 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.800000000000004
2023-09-12 13:59:05,459 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 13:59:05,703 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.9
2023-09-12 14:00:05,389 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:00:05,679 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.9
2023-09-12 14:01:05,303 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:01:05,606 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 34.0
2023-09-12 14:02:05,484 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:02:06,041 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.9
2023-09-12 14:02:07,082 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:02:07,341 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.9
2023-09-12 14:03:05,408 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:03:05,687 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.6
2023-09-12 14:04:05,379 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:04:05,895 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.2
2023-09-12 14:04:06,027 - ERROR - mycodo.action.email_bb28109a - Wait 2280 seconds to email again.
2023-09-12 14:04:06,158 - ERROR - mycodo.action.email_cbf04a4e - Wait 2280 seconds to email again.
2023-09-12 14:05:05,266 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:05:05,571 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.1
2023-09-12 14:05:05,691 - ERROR - mycodo.action.email_bb28109a - Wait 2220 seconds to email again.
2023-09-12 14:05:05,837 - ERROR - mycodo.action.email_cbf04a4e - Wait 2220 seconds to email again.
2023-09-12 14:05:56,919 - ERROR - mycodo.action.email_bb28109a - Wait 2169 seconds to email again.
2023-09-12 14:05:57,058 - ERROR - mycodo.action.email_cbf04a4e - Wait 2169 seconds to email again.
2023-09-12 14:06:05,449 - INFO - mycodo.controllers.controller_conditional_d8f88770 - This INFO log entry will appear in the Daemon Log
2023-09-12 14:06:05,941 - INFO - mycodo.controllers.controller_conditional_d8f88770 - Measurement value is 33.0

Looks like the emails server doesn’t want to accept the mail request???
Also the email should send above 32 degrees C. The code is set to run every 300 secs but the log shows that it takes a lot longer for the email sending attempt to kick in?

Update: Seems the email server was not at fault. While I was eating a little rain storm hit and the temp went below the minimum and I the emails arrived every 5 minutes, the interval set in the backend. So I wonder what is wrong here, why does the conditional function work when the low point is reached but not the other way around?

Have you accounted for the email refractory period?