I have just come across your software and it is fantastic, love the ease of setting up new sensors and it looks to have saved me shed loads of time.
I have a dumb question…I have an atlas ph sensor taking readings every 15 min and this shows up correctly on the live measurements page.
I want to send this evry 15 minute reading to a remote mqtt broker which I setup in the mqtt.publish.value config. However I am stuck to what I put in the value section. Can anybody help me?
Hey there.
There might be a better solution for this, but what would work in the meantime is the following:
Via Setup select Function, select Conditional Controller, in Conditions select single last (or whatever suits your needs), in Actions select MQTT publish.
In the first code section you could use something like this:
measurement = self.condition("{308e8761}")
if measurement is not None: # If a measurement exists
self.run_action("{8618e781}", value=measurement)
Just replace the IDs with the ones from your configuration.
Thanks for your direction which I followed but I must be doing something wrong as my mqtt broker doesnt receive any data and the mycodo logs dont look right.
I am able to setup an mqtt publish as an output and manually send a value to the mqtt broker without any issues.
I am able to setup the Atlas ph sensor as an input and the sensor readings on the live measurements page look to be good and the readings are updated inline with the settings.
I setup the conditonal controller with single,last and the action as mqtt publish and also update the code with the condition and action id’s but the logs show the following which just repeats:…
2022-01-29 18:19:46,646 - INFO - mycodo.controllers.controller_input_5ff0f7a8 - Activated in 2766.1 ms
2022-01-29 18:19:46,651 - DEBUG - mycodo.daemon - Input controller with ID 5ff0f7a8-657b-440d-976c-90b471e9f588 activated.
2022-01-29 18:19:46,722 - ERROR - mycodo.inputs.sensorutils - Conversion not found for ‘C’ to ‘pH’.
2022-01-29 18:19:52,665 - INFO - mycodo.controllers.controller_conditional_0879a423 - Deactivated in 116.4 ms
2022-01-29 18:19:52,665 - DEBUG - mycodo.daemon - Conditional controller with ID 0879a423-ac3a-471c-b0fb-f7fefa9127b8 deactivated.
2022-01-29 18:19:54,834 - INFO - mycodo.controllers.controller_conditional_0879a423 - Activated in 37.2 ms
2022-01-29 18:19:54,835 - DEBUG - mycodo.daemon - Conditional controller with ID 0879a423-ac3a-471c-b0fb-f7fefa9127b8 activated.
2022-01-29 18:20:04,867 - INFO - mycodo.controllers.controller_conditional_0879a423 - This INFO log entry will appear in the Daemon Log
2022-01-29 18:20:04,867 - ERROR - mycodo.controllers.controller_conditional_0879a423 - This ERROR log entry will appear in the Daemon Log
2022-01-29 18:20:04,951 - INFO - mycodo.controllers.controller_conditional_0879a423 - Check this measurement in the Daemon Log. The value is 7.043
2022-01-29 18:20:44,146 - ERROR - mycodo.inputs.sensorutils - Conversion not found for ‘C’ to ‘pH’.
2022-01-29 18:21:05,076 - INFO - mycodo.controllers.controller_conditional_0879a423 - This INFO log entry will appear in the Daemon Log
2022-01-29 18:21:05,077 - ERROR - mycodo.controllers.controller_conditional_0879a423 - This ERROR log entry will appear in the Daemon Log
2022-01-29 18:21:05,133 - INFO - mycodo.controllers.controller_conditional_0879a423 - Check this measurement in the Daemon Log. The value is 7.13
2022-01-29 18:21:44,129 - ERROR - mycodo.inputs.sensorutils - Conversion not found for ‘C’ to ‘pH’.
an update…
I can now see the sensor message being received by the mqtt broker but there is no value in the message.
Message 46 received on aarc/sensors/unit001/ph at 17:05:
QoS: 0 - Retain: false
This is a step forward. If anyone has any ideas as to why there is no content in the mqtt message please let me know.
I have a single Atlas ph sensor connected and configured as an input over i2c and it is configured in mycodo to take a reading every 15 minutes.
I want to take the output value from the ph sensor reading and send this to my mqtt broker on Home Assistant.
I have setup a conditional config that takes “single/last” for the ph sensor and also have an action configured where it is published to mqtt.
I can see the correct ph sensor value (from the live measurements and also log files) and I can see the mqtt publish message being received at the mqtt broker.
However what is missing from the mqtt publish packet is the actual value of the ph sensor.
this is the conditional statement…not sure why the fonts are all over the place…
# Example code for learning how to use a Conditional. See the manual for more information.
self.logger.info("This INFO log entry will appear in the Daemon Log")
self.logger.error("This ERROR log entry will appear in the Daemon Log")
if not hasattr(self, "loop_count"): # Initialize objects saved across executions
self.loop_count = 1
else:
self.loop_count += 1
# Replace "asdf1234" with a Condition ID
measurement = self.condition("{e26ddd49}")
self.logger.info("Check this measurement in the Daemon Log. The value is {val}".format(val=measurement))
if measurement is not None: # If a measurement exists
self.message += "This message appears in email alerts and notes.\n"
if measurement < 1: # If the measurement is less than 23
self.message += "Measurement is too Low! Measurement is {meas}\n".format(meas=measurement)
elif measurement > 1: # Else If the measurement is greater than 27
self.message += "Measurement is too High! Measurement is {meas}\n".format(meas=measurement)
# Replace "qwer5678" with an Action ID
self.run_action("{5b66bf30}", message=self.message) # Run a single specific Action
Sorry I am at a loss. The actions I have are within the conditional config. the config for these action is below:
Actions
Select One
Hostname
192.168.1.16
Port
1883
Topic
aarc/sensors/unit001/ph
Keep Alive
60
Client ID
mycodo_mqtt_client
Use Login
Username
mqtt01
Password
••••••••
MQTT: Publish: Publish a value to an MQTT server.
self.run_action("{5b66bf30}", value=33) will execute only this action and publish the value 33. self.run_all_actions() will not execute this action.
Good to hear. I try to maintain good documentation, so if there can be any improvement for new users to the software, let me know. I’m always looking to reduce where people can get hung up.