Hello Angelo,
as per short discussion in the blog, here my idea about implementing an addon feature which would allow Hydrosys4 to work as MQTT client and it would open to a very easy integration with home automation systems.
The current software implementation integrates a MQTT broker to Hydrosys4 software making Hydrosys4 as MQTT server meaning a sensor connect to it and send data over configured topics.
What I am proposing is that Hydrosys4 works as client which would mean that the software will have the capability to connect to an external MQTT broker existing in the lan and send, over user configured topics, status information and other possible payload. Please note: I want to stress that the implementation I am proposing only allow Hydrosys4 to send status information and would not receive commands to drive actuators.
In order to do that the Hydrosys4 software shall implement:
1) A visual interface to configure the MQTT server address, username, and password, where to send messages. It could be a simple view to be added to the configuration page or maybe at this point, it would be good to add a MQTT config menu item if you want).
2) A visual interface to configure topics, one for each pin, through which the status of the several functionalities could be sent, e.g. “Zone1/Irrigation ON/OFF” or “Zone1/humidity xyz”. This could be either an extension of the existing HW setting table where, for each pin, a topic and payload could be defined or a dedicated table if you implement a MQTT config menu item). The payload could be a status ON/OFF or a sensor measurement. The user could select the type of payload through a dropdown menu and based on the type of pin.
An additional general topic always present could be a heartbeat of the system which is simple sending, at regular and configurable interval, a status of Hydrosys4, e.g. “hydrosys/status ON” so that a user could detect possible loss of connectivity and/or system downtime.
3) In order to make the functionality robust there could be functions which:
a. at start-up send an updated of all the configured topics.
b. when Hydrosys4 receives a request on an “give-me-update” topic it send an update of all the configured topics
As stated in the blog, this enhancement could allow many owners of home automation system to easily integrate Hydrosys4 in their systems with a standard interface. The advantage for you would be to increase the audience of user who would/could use your software (I believe it is many).
Maybe a bit ambitious and long to implement, however, it could be done in increment. If I may suggest, in order to speedup/simplify the implementation. you could reuse some piece of software already developed and available in github implementing the basic connectivity functions and which could be integrated in Hydrosys4.
Ciao
Giuseppe
Hi Angelo,
I have just now upgraded my Pi and I am going to test the imeplemrntation in the coming weeks.
Thank you very much to take the time and spend effort to this implementation.
Ciao
Giuseppe
Update: Home assistant integration has been implemented in the latest release of hydrosys4 SW, details in the this post:
https://wordpress.com/post/hydrosysblog.wordpress.com/2987
@rmperreault Many Thanks for the information, I didn't know about the MQTT bridge feature, it looks very handy for many scenarios.
Great! Thanks!
Here's my two cents - i already connect to external MQTT via config files for the mqtt - create a config file under the /etc/mosquitto/conf.d directory to something like this:
# connection 10.0.0.158 hydrosys
connection bridge-01
address 10.0.0.158:1883
topic # out
topic # in
Restart mosquitto and you are all set. You can also add user id and password. Look at Mosquitto Bridge instructions.
This way you can get the hydrosys server to communicate via b bridge to the address you require. You should be able to connect to an external MQTT as well. You can add as many bridge as you would like.
Hopefully this could same a lot of work on programming. Here's a link providing information on how to bridge MQTT to both internal and external sites with password.
encryption:
Sorry, I did not catch the fact that the Adafruit MQTT server was remote so It requires a password. So not supported for the moment.
Ok. Will give it another go. But cant get it to work. I try using a web API but cant get to assemble the full url with the SecretKey. I need something like this: WEB: https://io.adafruit.com/Juanchu_j/feeds/testfeed API: https://io.adafruit.com/api/v2/Juanchu_j/feeds/testfeed But I need to pass the Key in the url. https://io.adafruit.com/api/docs/#adafruit-io-http-api
The Hydrosys4 can be connected as client to a remote server using the url. Unfortunately encryption is not supported. To use a remote url you can just type it in the "address" field. you can refer to the below link in the paragraph "Hydrosys4 configuration (For input)" for the basing input configuration. The format of the MQTT message should be Json.
Hello Juan,
thanks for sharing your idea. Actually from my experience the most flexible and almost standard way to share data among multiple sensors is using the MQTT protocol. As in your case, the sensors are connected to a raspberry, if this raspberry is connected to the network, then making a python script to send MQTT messages with the sensors reading should be quite simple. Once the sensor readings are transferred to MQTT then can be easily imported in to the Hydrosys4 SW.
unfortunately I didn't see in the Pimoroni site any indication on how to export this sensor data to MQTT messages, this is quite easy to implement and will add a lot of flexibility.
Hi Angello and Giuseppe,
This you are working on is really good. I would love to add my point of view of what I have been building, maybe it can help.
Right now i have an account on Adafruit's IO, being the hart of my IoT deployment. I use it as a comunication center point and have programmed some triggers (as my systems intelligence), but I would rather have Hyddrosys4 doing this. What I would like to be able to do, is to read feeds and publish to feeds.
I would use the read/subscribe feature, to be able to bring to Hydrosys, the values of a range of sensors I hace on almost self contained projects. For example, I use Pimoroni's Enviro+ to read temp, humidity, gases composition, light exposure, noise, etc.. Then i have the Pimoroni's Grow + wich has not only soil humidity and saturation sensors, but can drive small 6VDC pumps.
As for publishing, i use a standard 8 relay module to control Barrina Led Grow Lights, some AC plugs that control Vivosun Heat Mats and a couple of 12V DC Brushless Fans.
I would love to contribute, feel free to use my hardware as if it were yours. I'm available for videochat if you wish.
Let me know how can I be of any help?
Hi Angelo,
the whole idea is to have a pushed and not pulled mechanism in normal operations (in a restart use case depending on who restarts the signalling would change) therefore considerting the example you made Hydrosys4 sends a message when a pin status changes at time zero and at time 5 minutes elapsed. If I have understood the software implementation correctely a first ON message could be sent at pin activation and a OFF could be sent once the callback de-activate the pin.
Of course having a regular (and even configurable) status update interval time would be a top solution but of course the imeplemtnation complexity increases as you need to keep track of the timing in between callbacks ( ... well the call back could simply subtrack the interval from the remaining time then call a new one :) ) as well as have additional gadget to handle the config.
I think a first step would be to have an instant picture then we could on top implement the regular update of the status to reflect also the history.
Hi Giuseppe,
Still have questions regarding the actuators, let's take a practical example. Irrigation starts and last for 5 minutes.
If you want to know the status of the irrigation line, the external system (home assistant) should query the Hydrosys4 exactly in that 5 minutes when the irrigation is ON otherwise this information will be missed. Or the hydrosys4 system should send a status update very frequently (for example every one minute).
Is this the use case?
In this way the most important aspect is not the historic data but the instant picture of the system status.
Hi Angelo,
nice to read I am adding some value to the project.
For the actuators I think we should look at the use case we are trying to implement. As owner of an automation system my basic interest is to check if something is ongoing or open/closed . Therefore when integrating towards an external system I believe the basic info needed is "ON/OFF" and "OPEN/CLOSED" information. Time of activation and position are additional information which can be used for use cases where I could implement feature like "progression" of an event which also would mean sending more messages during the ongoing action ... nice to have but not first priority in my eyes.
What is your view on my point 3 about "restart" use cases. Most of the time, when a system restarts, it looses status information and I beleive it is useful to have those features to allow an update in those cases. What do you think?
About testing, yes I think it is the minimum I can do as contribution to the project .... of course time allowing ....
Ciao Giuseppe,
Thanks for the detailed explanation of the proposed feature, I think this could have positive impact on the project. Actually already got other request of the same type, but finally you provided a good amount of info which can be translated in a real implementation.
Here some idea that I think will make the feature easier to implement from my side:
- The HardwareSetting table lists all the objects that have a meaning in the system, the names are unique so I think the topic can be directly related to the name of the objects in the hardware table.
- In the MQTT setting page there will be the field for the IP address of the server, username, password, the list of objects with the relevant topics derived from the name and the checkbox to add or not to the MQTT.
- for the sensors, the easier way to send the MQTT payload is when the sensor readings are registered in the Raspberry database. Payload should have some info, but basically the reading and the time.
- for the Actuators, this is more complicate. Normally the system just provide info when an actuator is started and what action is performed. For example for Pulse type, it will provide the time of activation and the duration of the activation period. For the hbridge, the time of activation and the final position. Do you think this could make sense?
- The hearthbeat can be a good idea, also easy to implement.
Currently I don't have much time to dedicate to it, but I'll keep updating this post on the progresses, you can help me with the testing ;). It would require several iterations.