Hello.
This tutorial will show you how to display your solar power information from a Victron Energy Colour Control GX via the MQTT binding on your openHAB interface. Please note the 1.x binding is obsolete; it has been replaced by the 2.x mqtt binding which you should use instead. I have a post further down this thread which highlights the changes required.
This tutorial assumes you already have ethernet or wifi connected and working on your CCGX. Let’s get started.
-
Find the IP address of your CCGX. in Settings->Services->Ethernet or Wi-Fi (depending on how you connect to your CCGX.
-
Enable the MQTT service on your CCGX in Settings->Services->MQTT
- Install the MQTT binding in your openHAB installation. Add the CCGX broker service.
# conf/services/mqtt.cfg
ccgx.url=tcp://192.168.0.163:1883
(I also add this IP to my /etc/hosts file to make life easier on the command line)
- Install mosquitto clients for testing/debugging on your development machine (ie. on Debian);
sudo apt-get install mosquitto-clients
This gives us two clients. mosquitto_pub can be used to publish messages to a broker and mosquitto_sub can be used to subscribe to a topic to receive messages.
- Find your CCGX VRM Portal ID in Settings->Services->VRM online portal or issue
mosquitto_sub -h ccgx -t "#"
Replace ccgx with your IP or add it to your system’s hosts file. The response will be a 12 character hex value and look something like
{"value": "a0f6fd5aa8c8"}
a0f6fd5aa8c8 is your portal ID, please substitute this ID in all further examples
- Since the MQTT scripts on the CCGX go to sleep after 60 seconds let’s add a rule to let the CCGX know someone is listening and therefore keep sending information.
// conf/rules/ccgx.rules
rule "CCGX MQTT Keep Alive Timer"
when
Time cron "0/30 * * * * ?"
then
publish("ccgx", "R/a0f6fd5aa8c8/system/0/Serial", "") // substitute portal ID
end
Now with the CCGX constantly sending out messages we can play around with what we want to read.
On the command line issue
mosquitto_sub -h ccgx -t "N/#" -v
to watch all the messages being sent from the CCGX. There is a lot! Choose the ones you want. The most interesting ones for me were added to my .items file.
// conf/items/ccgx.items
Number PV_battery_voltage "Battery Voltage" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Dc/Battery/Voltage:state:JSONPATH($.value)]"}
Number PV_battery_power "Battery Power" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Dc/Battery/Power:state:JSONPATH($.value)]"}
Number PV_battery_current "Battery Current" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Dc/Battery/Current:state:JSONPATH($.value)]"}
Number PV_power "Solar Power" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Dc/Pv/Power:state:JSONPATH($.value)]"}
Number PV_ac_consumption "AC Out" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Ac/Consumption/L1/Power:state:JSONPATH($.value)]"}
Number PV_soc "State of Charge" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Battery/Soc:state:JSONPATH($.value)]"}
Number PV_generator "Generator (AC In)" {mqtt="<[ccgx:N/a0f6fd5aa8c8/system/0/Ac/Genset/L1/Power:state:JSONPATH($.value)]"}
You should be able to see where to make the substitutions to reflect what you want to read.
Install the JSONPath Transformation addon so the MQTT values get converted correctly.
Add the items to a sitemap if you like
Frame label="Solar" {
Text item=PV_battery_voltage label="Battery Voltage [%.2fv]"
Text item=PV_battery_power label="Battery Power [%.2fw]"
Text item=PV_battery_current label="Battery Current [%.2fa]"
Text item=PV_soc label="BatteryCharge [%.0f%%]"
Text item=PV_ac_consumption label="AC Out [%.0fw]"
Text item=PV_power label="Solar In [%.0fw]"
Text item=PV_generator label="Generator (AC In) [%.0fw]"
}
Enjoy.
** Remember that the CCGX will only send out messages if it thinks someone is listening. If you aren’t getting any messages issue
mosquitto_pub -h ccgx -t "R/a0f6fd5aa8c8/system/0/Serial" -m ""
to kick things off for another 60 seconds.