question

ee21 avatar image

Sending "write" commands via MQTT, can anyone provide some basic setup help?

This manual found here covers MQTT and how it can be used to send "D.Bus" commands:

https://github.com/victronenergy/dbus-mqtt/blob/master/README.md


An example write request is given here:

Example: On a Hub-4 system we can change the AC-In setpoint with this message:

Topic: W/e0ff50a097c0/vebus/257/Hub4/L1/AcPowerSetpoint Payload: {"value": -200}


I have identified the D.Bus "paths" I wish to control, here:

The ESS related D-Bus paths are:

  • com.victronenergy.settings /Settings/CGwacs/AcPowerSetPoint (Grid power setpoint)

  • com.victronenergy.settings /Settings/CGwacs/MaxChargePercentage (Enable/Disable charger)

  • com.victronenergy.settings /Settings/CGwacs/MaxDischargePercentage (Enable/Disable inverter)


I have 0 experience with MQTT however, and am not sure how to setup a "client" or "subscribe" to the VenusGX's built in Mosquito "Broker", let alone issue a command as shown in example above. Is anyone able to provide some basic instructions or a link to where I might learn how to do this? Ideally I would like to run the MQTT "client" on an Android platform, although I suspect guides that cover this on a Rasberry Pi can be easily adapted. Any help with this is appreciated, thank you!

ESSVenus GX - VGXVenus OSMQTT
2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

4 Answers
nigelfxs avatar image
nigelfxs answered ·

Hi ee21

I suggest starting off getting a MQTT Server setup and experimenting with subscribing to messages and publishing messages. Once you have this working, you can then find an Android app to display/send the messages.

The CCGX implements a MQTT Client (once you enable the MQTT option in the menu). This will publish/receive MQTT messages to the Victron MQTT Broker (Server) - mqtt.victronenergy.com.

You can setup your own MQTT server on running on a Raspberry Pi - that also subscribes to the MQTT messages generated by the CCGX. The RPi should ideally be connected on the same LAN as the CCGX.

If you install the "Mosquitto" app on your RPi, you can then receive all MQTT messages, published by the CCGX, using the mosquitto_sub command (details are given in the github link in your post above). You will also need to use the mosquitto_pub command to periodically send a "keep-alive" command to the CCGX - otherwise it will stop sending MQTT data.

Keep in mind that the MQTT data is also published to the Victron servers, so will generate a continuous upload of around 8kbit/s. This does not seem like much, but adds up to over 2GB uploaded per month.

I hope this helps.

1 comment
2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Thank you for you input, I tried playing around a bit with it so far. I have been able to get a MQTT client to successfully subscribe and receive messages from the MQTT Broker on the Venus GX. I am now having issues identifying the MQTT "topics" that control the D-Bus paths I want to write. This might be better suited to be asked in a different thread, but if you are able to provide any input this for what the correct MQTT "topic" to control these D-BUS paths are, that would be great:

  • com.victronenergy.settings /Settings/CGwacs/AcPowerSetPoint (Grid power setpoint)

  • com.victronenergy.settings /Settings/CGwacs/MaxChargePercentage (Enable/Disable charger)

  • com.victronenergy.settings /Settings/CGwacs/MaxDischargePercentage (Enable/Disable inverter)

I have tried this for ac power setpoint:

W/985dad8185e7/vebus/261/Hub4/L1/AcPowerSetpoint

With payload:

{"value": 1000}


Which it did not seem like worked. 261 is the correct device ID for my VEBus devices, and that number is the VRM Portal ID from my Venus GX, and ESS is set to External Control. This is per this document here which outlines MQTT control topics: https://github.com/victronenergy/dbus-mqtt/blob/master/README.md


When I publish this topic, I get a message in response on the same topic which I am subscribed, but the message I get tells me that AC Setpoint remains at a value of 327000, which I am not sure where this value came from.


MY biggest issue here I guess is that I just don't understand how to translate a D-Bus Path Command, into a MQTT "write" Topic.


There are other paths I wish to control that are part of ESS that I have not yet identified as well, such as Maximum Inverter Power.

wildsilo avatar image
wildsilo answered ·

Hi there


I am a (little) further than you in the journey of getting to understand MQTT, I hope.


This should get you started:


The topic I use to publish to to set/change the AC setpoint:

W/XXXX-your serial number-XXX/settings/0/Settings/CGwacs/AcPowerSetPoint

Example to set to 50W (from Linux command line/bash script, but should work more or less the same anywhere):

mosquitto_pub -h 192.168.2.21 -t "W/XXX/settings/0/Settings/CGwacs/AcPowerSetPoint" -m '{"value": "50"}'

Hope this helps.

I strongly recommend installing MQTT Explorer (works on Mac, Linux and Windows). Connect to your MQTT broker (even on the Victron). Then you can enter a search term (like setpoint) and watch if it changes when you publish a message.

I initially thought about changing the mosquitto client on the Venus (I use a Venus GX, not a CCGX) to point to another broker, but decided against it,. as I wanted to keep the overall configuration as standard as possible. So I set up a Mosquitto broker on a Raspberry Pi, with a "bridge" that subscribes to the Victron GX and publishes it to itself. Now I can read from the Pi broker what is happening o the Venus, write to the Pi (and it gets sent to the Venus, etc.


This was my first step in setting up a home automation (load management via Sonoff switches) system. I wanted to configure it all manually before importing it into OpenHab or Hass.io.


It works well for me, and by using a separate Pi broker, it means everything I code/configure is in one place, and I do not need to change the Venus settings at all. I can add OpenHab later to the Pi, and it will just use the MQTT broker (and bridge) on the Pi for everything.


Good luck and enjoy.

1 comment
2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

@WildSilo I mostly am happy with the internal ESS controls, and have my setup working well. There will only be an occasional time, once a month maybe, when I would like to disengage the internal ESS controls, and set the "mode" to "keep batteries charged". Can MQTT be used to change the "mode" if not already set to External Control? Or can you think of a way to do this without operating in External Control mode all the time?

nigelfxs avatar image
nigelfxs answered ·

Hi ee21

I have never used MQTT to change settings - just to monitor the values etc.

The following links may be useful.

https://www.victronenergy.com/download-document/6195/ccgx-modbus-tcp-register-list-2.31.xlsx

https://www.victronenergy.com/live/ccgx:modbustcp_faq


2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

osaether avatar image
osaether answered ·

Below is a script I wrote to turn Relay 1 on in the CCGX with MQTT. It is possibly not the correct way of turning on the relay but you can learn some basic things from it. Here is the sctipt:

https://gist.github.com/osaether/5ad837a7ad40a8ce98fced6a3504f5ad

2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.