You bring up a use case that hasn’t been requested until now. So you want to calculate a value (presumably using some Input or other controller), then publish that value via MQTT? For all the possible combinations that Mycodo can be configured, I can think of only one method and it requires us to get a little creative with some Python code and a Conditional Controller Function. Actually, there are multiple if we’re going to use code, but I’ll show you the easiest.
I do think there is a lot of value in adding an MQTT Publish Action. And indeed, this has been discussed for Inputs, but it really can be applied to Function Actions as well:
Here’s how (theoretically) it would work:
Create an Output (MQTT Publish: Value) and set all the MQTT server settings.
Create a Function (Conditional Controller).
With Python code, perform the calculations you were doing with the Math controller you mentioned. If you used Input measurements, for example, use any of the available Conditions to pull measurements to use with your calculation.
Add the following code to the Conditional Statement, which will pass a value to the Output created earlier that will then pass the value to the MQTT server:
Where output_id is set to the ID of your MQTT Value Output and publish_value is set to the value you want to publish. You can copy the ID of your Output to your clipboard by clicking the button next to the name of your Output on the Output page. This button will show a tool tip with your Output ID when hovered over the button.
Now, considering that this is not an easy way to use Mycodo, since it involves Python code, I see a great amount of value in adding an MQTT Action that can be easily used with Functions to pass a value. Considering the two topics, above, show a lot of interest in such a feature, It’s already high on my priority list and I hope to have it added for the next Mycodo release.
This will allow you to create a Conditional Controller and add from the Actions dropdown the MQTT Publish action. This isn’t currently released, so if you want to test the new feature, you’ll have to upgrade to master.
In my case, my smart home system is collecting data from all “subsystems” and provide it to two dashboards.
The Mycodo pi will get an own display at the aquaponic system, but it would be great to have the values also at one dashboard
Yes, I’m using a cheap aliexpress pH-probe + ADS1115 device. So i have to calculate the correct pH value. Altas scientific ist hard to find in Germany
I’ll add a turbidity sensor and a flow meter in the next weeks. Turbidity should give me a hint, if algae starts to grow in the system and the flow meter if the pumps are working correctly.
Hope to have some time during next week, to give your solution a try. I’ll let you know
This is just a warning because you made no reference to “self” in the function. Warnings are not always an issue, such as this case. The pylint that runs on the code will show a number of warnings related to minor things such as this. What’s important is that the code runs.