Comfort Automation/ Security System Forums > Software Applications > Misc Software Interfaces > Comfort to MQTT |
Moderated by: slychiu |
Author | Post | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cab123 Member
|
Hi, i would like to share with the community my simple driver implementation of comfort to MQTT. I have this running for a couple of months and never registered any failure with the communication. MQTT is amazingly light and mature. And my driver seems to be stable enough for the job, had some issues with strange USB resets, but now it gracefully handles every USB quirks i found, including reconnecting the UCM. This approach provides a simple and flexible way to interact with comfort from/to multiple sources. Personally i have comfort ULTRA, individual power monitoring, solar inverter statistics all feeding data to a MQTT broker. Then I process some of that data in NodeRED and present/control everything in OpenHAB. It works really well. I do not use the alarm section of comfort, only home automation with push buttons, relays, infrared and some KNX stuff. Used hardware: - UCM USB - A x86 server with Debian Jessie installed (could be a raspberry Pi) (1) Connect the UCM/USB to the server and make the USB connection deterministic: (1.1) Find the Device / ID / Serial Number of the device:
(1.2) From the output above we get: - idVendor: 0403 - idProduct: 6001 - Serial Number: A7007iyv Your data will probabily be the same, except for the unique serial number of your UCM. Next create a file like the one below and add the right info:
Now everytime the USB UCM is connected th the server it will be uniquely available at /dev/comfort, regardless of other USB peripherals in the system. (2) Install MQTT broker and clients http://mosquitto.org/2013/01/mosquitto-debian-repository/ for the clients: sudo apt-get install mosquitto-clients anoher good reference with some testing: https://pallavichaurasia94.wordpress.com/2014/10/14/mosquitto-in-debian/ (3) the script to establish a bridge between Comfort and MQTT: (3.1) First install the folloing perl modules:
(3.2) Find a appropriate directory, for example /opt and copy the contents of the script to a new file, for example:
To test: WINDOW_1: run the script
WINDOW_2: listen for MQTT events
WINDOW_3: post something to comfort topic MQTT
On the WINDOW_2 you should see something like:
That´s it! Now you can subscribe (listen) or post commands to the MQTT broker and interact with comfort. Make the script boot at startup by editing the file just before "exit 0"
And now comfort can easily be integrated with other bits of amazing software, like openHAB, NodeRED, etc. If there is any interest in this i can share some of my NodeRED and OpenHAB integration configuration. Have fun! |
|||||||||||||||||||||
tech07 Administrator
|
yes pleasecan this work with UCM/ETh03? How can this allow working with openhab etc |
|||||||||||||||||||||
cab123 Member
|
Hi, i'm not sure how the UCM/ETH03 works, since i don't have one, but i suppose everything is possible . I'll gather some info and post here later a working example of OpenHAB controlling comfort. |
|||||||||||||||||||||
cab123 Member
|
So the next step after having a MQTT broker interacting with comfort is to install NodeRED http://nodered.org/ It is really easy to set up stuff in logical blocks, however some javascript is needed for the functions. This is my processing of comfort stuff: The first "flow" updates comfort's time periodically. Every 10 minutes a timestamp is generated, passed through the "Build Date Command" and sent to the MQTT topic comfort is listening to. The function is something like this: At the bottom of the first image, every group of received messages from Comfort are handled. For instance, i have temperature sensors, one KNX and another from a SCS that are transformed to MQTT also and sent to the broker. This way i can later read the sensors and display them on openHab. The "split function is configured as shown: and the Sensor function decodes comfort sensor messages like this:
All processing can be done here. Imagination is the limit, everything can be done with small bits of code and simple "flows". Later i will try to show some of my OpenHab setup that takes advantage of all this data. Fell free to ask any questions. |
|||||||||||||||||||||
cab123 Member
|
Hi guys sorry for the late update, i didn't want to show the openhab examples in portuguese so i kept delaying a update. Now i have changed my dashboards to show you what is the final result. for setting up openhab to control comfort you just need to interact with the mqtt broker, still it is a bit slow learning curve but it is totally worth it! and for example inside the TV control you can find the actual control: The buttons listen for updates, so if i turn off my living room TV locally, i am actually pressing a KNX button that sends a telegram to the BUS that is captured by the UCM and passed on to comfort that updates a counter that is sent though serial connection that is captured by the perl driver and sent to MQTT, that broadcasts it to any listening device, where openhab is waiting, and then applies some rules to update the button status that is binded to the TV, so next time i toggle the TV i will perform the right action! Easy! Last edited on Wednesday Aug 10th, 2016 06:36 pm by cab123 |
|||||||||||||||||||||
slychiu Administrator
|
Thats nice. Its good to see Comfort with Openhab. We will try to test it |
|||||||||||||||||||||
slychiu Administrator
|
How does the Comfort program go into this setup? |
|||||||||||||||||||||
cab123 Member
|
Hi not sure i understand your question. The comfort software requires direct and exclusive access to the UCM, so they cannot exist in a system at the same time. In order to use comfort apps or to upload new configuration, i normally shutdown this "driver" and use the socat approach described here: http://www.comfortforums.com/view_topic.php?id=3249&forum_id=83&jump_to=13896#p13896 |
|||||||||||||||||||||
meep Member
|
Hi Is there any chance you could post more of your Node-Red javascript? I need to do exactly this as I want to start using my old comfort as essentially an i/o block for openHab. The more reference code I can find the better. As an aside - any thoughts on how one could go about accessing Comfort voicemail recordings from openHab? Many thanks Peter |
|||||||||||||||||||||
idheath Member
|
I'm so pleased that I've seen this thread :-) I have just started with openHAB and am just about to have a play with MQTT (for other reasons). I've been wondering for ages how I could connect Comfort to openHAB and wondered myself about MQTT as a sensible option. I have a UCM/ETH02 which I intend to keep for Comfigurator. I also have a UCM/232 which I plan to connect to my Raspberry Pi 3 (which is running openHAB and will also be running MQTT when I install it). I've got a tiny USB to serial converter so I should be able to link my UCM/232 to the Raspberry Pi that way. |
|||||||||||||||||||||
meep Member
|
I managed to get comfort talking to Mqtt and node-red via ucm/232 and a usb/serial convertor. Works great both to and from. It's on Windows though so I needed to completely re-write the perl driver to work. I'll share it here when I've got it refined. Last edited on Sunday Oct 9th, 2016 01:02 am by meep |
|||||||||||||||||||||
idheath Member
|
meep wrote:I managed to get comfort talking to Mqtt and node-red via ucm/232 and a usb/serial convertor. Works great both to and from. Thanks v.much |
|||||||||||||||||||||
meep Member
|
Well, I managed to get this working on windows with Win32::SerialPort in Perl. (just couldn't hack the above code to work so started afresh). It's a long way from cab123's original driver in terms of code but owes a lot to his concept, structure and techniques. It's also got a LOT less error checking implemented so is really just a proof of concept at this stage and would require a few more additions to make it more robust. While this does send and receive between comfort and MQTT, and you can check these messages in Node-Red, I added a Trace function to allow key messages be printed to the console - really helps with debugging.
This can be tested with something like the command below at the command line. Obviously change your own Mosquito server and port details. (note, you must first issue the login (LI) command to Comfort, with a user code, or it will keep returning 'NA' as the response);
Attached is an example of this running. You can see the initial receipt of the "z?" query from MQTT and the response from comfort sent back. Then you can see Comfort reporting activity Input 05 (that's the result of me opening and closing a window with a contact sensor). NB: For some reason, the forum is stripping backslashes from the code segments above. I've tried to add them back in but if you're trying to run this and it's failing, it mey be due to a missing '\' somewhere. Attachment: Capture.PNG (Downloaded 115 times) Last edited on Monday Oct 10th, 2016 12:09 pm by meep |
|||||||||||||||||||||
cab123 Member
|
Hey! I'm very happy to see you are having fun with this! I don't have much more javascript examples, aside from what i already shared, it's pretty basic stuff. i would recommend you to switch to a linux box for these server-side protocols - they will run forever, will never complain, and be readily available to serve you anytime :-) A small raspberry Pi is cheap to buy/run and has enough horsepower to do this and much more. |
|||||||||||||||||||||
meep Member
|
Cheers, it's more getting to grips with node-red and regex to be honest, getting there slowly. I run all my stuff on a single unraid server through a combination of dockers and vms. I went with a Windows vm as I needed to pass through the usb/serial adapter and as I'll likely need to run comfigurator for a while, thought I'd go with Windows as I wouldn't need to keep swapping connections etc. Might switch back to a Linux vm as I get more comfortable with it all. Thanks for the inspiration on this and taking the time to document it here, really helped me realise what I needed to do was possible. |
|||||||||||||||||||||
jelockwood Guest
|
@cab123 If you're still working on this any plans to implement an MQTT broker on the UCM/Pi module? Obviously one could use the UCM/Eth03 and then link to a standard external Raspberry Pi but would seem to make sense to do the Comfort side of this using the dedicated Pi module. |
|||||||||||||||||||||
mattbrain UCM Pi Users
|
The alphaWerk components uses MQTT as their backend & Mosquitto is installed on the CM3. It is locked to localhost only by default but can be opened up to external devices easily. There is also nothing stopping you from installing different software, hardware notes are available to use your own tools to talk to comfort and manage the watchdog timer. |