Hello,
This tutorial will show you how to display your solar power information from a Victron Energy Colour Control GX via the MQTT 3 binding on your openHAB 3 interface.
This tutorial assumes you already have ethernet or wifi connected and working on your CCGX, and a MQTT bridge and thing setup on your openHAB 3 setup.
- Install the JSONPath Transformation addon so the MQTT values get converted correctly.
Find the IP/host CCGX device. (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.
triggers:
- id: "1"
configuration:
cronExpression: 0/30 * * * * ? *
type: timer.GenericCronTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: |
val actions = getActions("mqtt", "mqtt:broker:ccgx")
actions.publishMQTT("R/a0f6fd5aa8c8/system/0/Serial", "")
logInfo("Solar", "CCGX MQTT Keep Alive Timer fired!!")
type: script.ScriptAction
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! It will show the topic and the value. Assign the topics to individual channels through the GUI or code.
UID: mqtt:topic:ccgx:ccgx
label: CCGX
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:ccgx
location: Shed
channels:
- id: pv_battery_soc
channelTypeUID: mqtt:dimmer
label: Battery SoC
description: ""
configuration:
stateTopic: N/a0f6fd5aa8c8/system/0/Dc/Battery/Soc
transformationPattern: JSONPATH:$.value
- id: pv_battery_voltage
channelTypeUID: mqtt:number
label: Battery Voltage
description: null
configuration:
formatBeforePublish: "%.4f"
stateTopic: N/a0f6fd5aa8c8/system/0/Dc/Battery/Voltage
transformationPattern: JSONPATH:$.value
- id: pv_power_pv
channelTypeUID: mqtt:number
label: Solar Power
description: null
configuration:
stateTopic: N/a0f6fd5aa8c8/system/0/Dc/Pv/Power
transformationPattern: JSONPATH:$.value
- id: pv_power_consumption
channelTypeUID: mqtt:number
label: Consumption
description: null
configuration:
stateTopic: N/a0f6fd5aa8c8/system/0/Ac/Consumption/L1/Power
transformationPattern: JSONPATH:$.value
Add new equipment to your semantic model. Add âpoints from thingâ to your equipment and choose your mqtt thing with all the channels added. They can now be viewed on the MainUI.
Enjoy!