Well I guess that answers that
I’m starting to wonder if the problem is Python itself… it’s just too slow and is a resource hog compared to something like C++.
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 169, in _do_get
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 167, in _do_get
return self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 393, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 678, in init
self.__connect()
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 902, in __connect
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 898, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/create.py”, line 645, in connect
return dialect.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/default.py”, line 616, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/opt/Mycodo/mycodo/databases/utils.py”, line 26, in session_scope
yield session
File “/opt/Mycodo/mycodo/actions/base_action.py”, line 97, in setup_logger
Input.unique_id == action.function_id).first()
^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/query.py”, line 2748, in first
return self.limit(1)._iter().first() # type: ignore
^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/query.py”, line 2847, in _iter
result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 2308, in execute
return self._execute_internal(
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 2180, in _execute_internal
conn = self._connection_for_bind(bind)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 2047, in _connection_for_bind
return trans._connection_for_bind(engine, execution_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 2, in _connection_for_bind
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/state_changes.py”, line 139, in _go
ret_value = fn(self, *arg, **kw)
^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 1143, in _connection_for_bind
conn = bind.connect()
^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 3269, in connect
return self._connection_cls(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 147, in init
Connection._handle_dbapi_exception_noconnection(
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 2431, in _handle_dbapi_exception_noconnection
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 145, in init
self._dbapi_connection = engine.raw_connection()
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 3293, in raw_connection
return self.pool.connect()
^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 452, in connect
return _ConnectionFairy._checkout(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 1269, in _checkout
fairy = _ConnectionRecord.checkout(pool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 716, in checkout
rec = pool._do_get()
^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 169, in _do_get
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 167, in _do_get
return self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 393, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 678, in init
self.__connect()
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 902, in __connect
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 898, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/create.py”, line 645, in connect
return dialect.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/default.py”, line 616, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)
2024-03-16 08:01:09,526 - ERROR - mycodo.databases.utils - Error raised in session_scope. Session will be rolled back: db_uri=‘sqlite:////opt/Mycodo/databases/mycodo.db’, error=‘(sqlite3.OperationalError) unable to open database file
(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)’
Traceback (most recent call last):
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 145, in init
self._dbapi_connection = engine.raw_connection()
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 3293, in raw_connection
return self.pool.connect()
^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 452, in connect
return _ConnectionFairy._checkout(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 1269, in _checkout
fairy = _ConnectionRecord.checkout(pool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 716, in checkout
rec = pool._do_get()
^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 169, in _do_get
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 167, in _do_get
return self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 393, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 678, in init
self.__connect()
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 902, in __connect
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 898, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/create.py”, line 645, in connect
return dialect.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/default.py”, line 616, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “/opt/Mycodo/mycodo/databases/utils.py”, line 26, in session_scope
yield session
File “/opt/Mycodo/mycodo/utils/database.py”, line 70, in db_retrieve_table_daemon
return_table = return_table.first()
^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/query.py”, line 2748, in first
return self.limit(1)._iter().first() # type: ignore
^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/query.py”, line 2847, in _iter
result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 2308, in execute
return self._execute_internal(
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 2180, in _execute_internal
conn = self._connection_for_bind(bind)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 2047, in _connection_for_bind
return trans._connection_for_bind(engine, execution_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 2, in _connection_for_bind
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/state_changes.py”, line 139, in _go
ret_value = fn(self, *arg, **kw)
^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/orm/session.py”, line 1143, in _connection_for_bind
conn = bind.connect()
^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 3269, in connect
return self._connection_cls(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 147, in init
Connection._handle_dbapi_exception_noconnection(
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 2431, in _handle_dbapi_exception_noconnection
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 145, in init
self._dbapi_connection = engine.raw_connection()
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/base.py”, line 3293, in raw_connection
return self.pool.connect()
^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 452, in connect
return _ConnectionFairy._checkout(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 1269, in _checkout
fairy = _ConnectionRecord.checkout(pool)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 716, in checkout
rec = pool._do_get()
^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 169, in _do_get
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/impl.py”, line 167, in _do_get
return self._create_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 393, in _create_connection
return _ConnectionRecord(self)
^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 678, in init
self.__connect()
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 902, in __connect
with util.safe_reraise():
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
raise exc_value.with_traceback(exc_tb)
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/pool/base.py”, line 898, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/create.py”, line 645, in connect
return dialect.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/sqlalchemy/engine/default.py”, line 616, in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)
2024-03-16 08:01:09,751 - ERROR - mycodo.database - The Mycodo database is locked. Trying to access again in 1 second…
2024-03-16 08:01:09,585 - ERROR - mycodo.controllers.controller_conditional_8cb60bed - Exception executing Run Python Code
Traceback (most recent call last):
File “/opt/Mycodo/mycodo/controllers/controller_conditional.py”, line 183, in check_conditionals
self.conditional_run.conditional_code_run()
File “/opt/Mycodo/mycodo/user_python_code/conditional_8cb60bed-af46-471f-a1d5-faca410bee6f.py”, line 22, in conditional_code_run
measurement = self.condition(“a3855e9e”) #HS300 Lights Output Status LED Conditional
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/mycodo/controllers/base_conditional.py”, line 78, in condition
return self.control.get_condition_measurement(full_cond_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/mycodo/mycodo_client.py”, line 190, in get_condition_measurement
return self.proxy().get_condition_measurement(condition_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/client.py”, line 510, in call
return self.__send(self.__name, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/client.py”, line 256, in _pyroInvoke
msg = protocol.recv_stub(self._pyroConnection, [protocol.MSG_RESULT])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/protocol.py”, line 189, in recv_stub
header = connection.recv(6) # ‘PYRO’ + 2 bytes protocol version
^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/socketutil.py”, line 435, in recv
return receive_data(self.sock, size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/socketutil.py”, line 159, in receive_data
raise err
Pyro5.errors.ConnectionClosedError: receiving: not enough data
2024-03-16 08:01:09,677 - ERROR - mycodo.database - The Mycodo database is locked. Trying to access again in 1 second…
2024-03-16 08:01:09,710 - ERROR - mycodo.controllers.controller_conditional_31d0988f - Exception executing Run Python Code
Traceback (most recent call last):
File “/opt/Mycodo/mycodo/controllers/controller_conditional.py”, line 183, in check_conditionals
self.conditional_run.conditional_code_run()
File “/opt/Mycodo/mycodo/user_python_code/conditional_31d0988f-3e3f-425e-89a9-2e14e830a3e3.py”, line 22, in conditional_code_run
measurement = self.condition(“f6538538”) #HS300 Pump Output Status LED Conditional
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/mycodo/controllers/base_conditional.py”, line 78, in condition
return self.control.get_condition_measurement(full_cond_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/mycodo/mycodo_client.py”, line 190, in get_condition_measurement
return self.proxy().get_condition_measurement(condition_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/client.py”, line 510, in call
return self.__send(self.__name, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/client.py”, line 268, in _pyroInvoke
data = serializer.loads(msg.data)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/serializers.py”, line 290, in loads
return self.recreate_classes(serpent.loads(data))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/serializers.py”, line 256, in recreate_classes
return self.dict_to_class(literal)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/serializers.py”, line 309, in dict_to_class
return super(SerpentSerializer, cls).dict_to_class(data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/opt/Mycodo/env/lib/python3.11/site-packages/Pyro5/serializers.py”, line 235, in dict_to_class
So after deactivating all of my conditionals that run my LED status board it seems to be running ok. I just don’t understand how the simple conditionals can be causing such a huge CPU load.
VPD conditional…
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 time import sleep
9: from datetime import datetime
10:
11: class ConditionalRun(AbstractConditional):
12: def init(self, logger, function_id, message):
13: super().init(logger, function_id, message, timeout=30.0)
14:
15: self.logger = logger
16: self.function_id = function_id
17: self.variables = {}
18: self.message = message
19: self.running = True
20: self.loop_count = 0
21:
22: def conditional_code_run(self):
23: blinks=8
24: measurement = self.condition(“1c8c49f3”) #VPD [Function24] Status LED Conditional
25: if measurement is not None: # If a measurement exists
26: if measurement < 0.8: # led is dark blue
27: self.run_action(“1a811689”, value={“payload”: “0,0,2”})
28: elif measurement >= 0.8 and measurement < 1.15: # led is green
29: self.run_action(“1a811689”, value={“payload”: “0,1,0”})
30: elif measurement >= 1.15 and measurement < 1.4: # led is yellow
31: self.run_action(“1a811689”, value={“payload”: “1,1,0”})
32: elif measurement >= 1.4: # led is bright red
33: self.run_action(“1a811689”, value={“payload”: “2,0,0”})
34: else: # If no measurement exists led is flashing bright blue
35: for _ in range(blinks):
36: self.run_action(“1a811689”, value={“payload”: “0,0,10”})
37: sleep(.75)
38: self.run_action(“1a811689”, value={“payload”: “0,0,0”})
39: sleep(.75)
40:
41: def function_status(self):
42: # Example code to provide a return status for other controllers and widgets.
43: status_dict = {
44: ‘string_status’: f"The controller has looped {self.loop_count} times at {datetime.now()}",
45: ‘loop_count’: self.loop_count,
46: ‘error’:
47: }
48: return status_dict
Humidity conditional…
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 time import sleep
9: from datetime import datetime
10:
11: class ConditionalRun(AbstractConditional):
12: def init(self, logger, function_id, message):
13: super().init(logger, function_id, message, timeout=30.0)
14:
15: self.logger = logger
16: self.function_id = function_id
17: self.variables = {}
18: self.message = message
19: self.running = True
20: self.loop_count = 0
21:
22: def conditional_code_run(self):
23: blinks=8
24: measurement = self.condition(“5bdca006”) #SHTC3 (Grow Humidity Status LED Conditional)
25: if measurement is not None: # If a measurement exists
26: if measurement < 55: # If the measurement is < 55 led is dark blue
27: self.run_action(“9c798bf5”, value={“payload”: “0,0,2”})
28: elif measurement >= 55 and measurement < 68: # LED is green
29: self.run_action(“9c798bf5”, value={“payload”: “0,1,0”})
30: elif measurement >= 68 and measurement < 73: # LED is yellow
31: self.run_action(“9c798bf5”, value={“payload”: “1,1,0”})
32: elif measurement >= 73 and measurement < 75: # LED is red
33: self.run_action(“9c798bf5”, value={“payload”: “2,0,0”})
34: elif measurement >= 75: # Else If measurement is >= 75 LED is flashing bright red
35: for _ in range(blinks):
36: self.run_action(“9c798bf5”, value={“payload”: “5,0,0”})
37: sleep(.75)
38: self.run_action(“9c798bf5”, value={“payload”: “0,0,0”})
39: sleep(.75)
40: else: # If no measurement exists led is flashing bright blue
41: for _ in range(blinks):
42: self.run_action(“9c798bf5”, value={“payload”: “0,0,10”})
43: sleep(.75)
44: self.run_action(“9c798bf5”, value={“payload”: “0,0,0”})
45: sleep(.75)
46:
47: def function_status(self):
48: # Example code to provide a return status for other controllers and widgets.
49: status_dict = {
50: ‘string_status’: f"The controller has looped {self.loop_count} times at {datetime.now()}",
51: ‘loop_count’: self.loop_count,
52: ‘error’:
53: }
54: return status_dict
Temp conditional…
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 time import sleep
9: from datetime import datetime
10:
11: class ConditionalRun(AbstractConditional):
12: def init(self, logger, function_id, message):
13: super().init(logger, function_id, message, timeout=30.0)
14:
15: self.logger = logger
16: self.function_id = function_id
17: self.variables = {}
18: self.message = message
19: self.running = True
20: self.loop_count = 0
21:
22: def conditional_code_run(self):
23: blinks=8
24: measurement = self.condition(“afe3b81a”) #SHTC3 (Grow Temp Status LED Conditional)
25: if measurement is not None: # If a measurement exists
26: if measurement < 55: # If the measurement is < 55 led is dark blue
27: self.run_action(“cba8014f”, value={“payload”: “0,0,2”})
28: elif measurement >= 55 and measurement < 60 : # Else If measurement is >= 55 led is medium blue
29: self.run_action(“cba8014f”, value={“payload”: “0,1,2”})
30: elif measurement >= 60 and measurement < 70: # Else If measurement is >= 60 led is light blue
31: self.run_action(“cba8014f”, value={“payload”: “0,2,1”})
32: elif measurement >= 70 and measurement < 80: # Else If measurement is >= 70 led is green
33: self.run_action(“cba8014f”, value={“payload”: “0,1,0”})
34: elif measurement >= 80 < 85: # Else If measurement is >= 80 led is yellow
35: self.run_action(“cba8014f”, value={“payload”: “1,1,0”})
36: elif measurement >= 85: # Else If measurement is >= 85 led is flashing bright red
37: for _ in range(blinks):
38: self.run_action(“cba8014f”, value={“payload”: “5,0,0”})
39: sleep(.75)
40: self.run_action(“cba8014f”, value={“payload”: “0,0,0”})
41: sleep(.75)
42: else: # If no measurement exists led is flashing bright blue
43: for _ in range(blinks):
44: self.run_action(“cba8014f”, value={“payload”: “0,0,10”})
45: sleep(.75)
46: self.run_action(“cba8014f”, value={“payload”: “0,0,0”})
47: sleep(.75)
48:
49: def function_status(self):
50: # Example code to provide a return status for other controllers and widgets.
51: status_dict = {
52: ‘string_status’: f"The controller has looped {self.loop_count} times at {datetime.now()}",
53: ‘loop_count’: self.loop_count,
54: ‘error’:
55: }
56: return status_dict