question

carsten2 avatar image
carsten2 asked

How to read/write other dbus values from python dbus service?

I have a have a dbus-driver which publishes data from my pv inverter to the dbus via a dbus-service derived from dummy-service.

How can I read dbus values, e.g. the current battery charging power (from com.victronenergy.system?). How can I write other dbus values, e.g. the limited the charging power of the battery?

d-bus
1 comment
2 |3000

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

gone-sailing avatar image gone-sailing commented ·

If you are smart enough to write a drive to publish values, reading values should be straightforward. All the information is available here:

https://github.com/victronenergy/venus/wiki/dbus-api

And use dbus-spy to inspect the dbus in real time.

0 Likes 0 ·
3 Answers
Ronald Rink avatar image
Ronald Rink answered ·

Hi @dcsonka as most of the "answer" information in this thread is inside comments, I hereby try to write up a complete answer.

How can I read dbus values, e.g. the current battery charging power (from com.victronenergy.system?). 

I know of two ways, Victron provides this functionality in Python:

  1. VeDbusItemImport
    see example here
  2. DbusMonitor
    see pulquero Battery Aggregator as an example on how to monitor multiple paths/values

The latter - as far as I understand the documentation - is the preferred option (as it handles a lot of overhead for you).

How can I write other dbus values, e.g. the limited the charging power of the battery?

When you found out on how to read the values via "DbusMonitor" you could use the same mechanism to also write these values.

However, in my understanding it would be better to create a "Battery Monitor" and you publish your CVL, CCL, DCL etc. values via your driver (inside your own namespace). Then the Venus OS would pick up your driver's values and publish them throughout the system. With this approach you would only need to write in your own namespace/service and not mess with any other processes. This is actually what the Battery Aggregator and dbus-serialdriver (among others) do.

For this you need to use the namespace "com.victronenergy.battery" and need to publish a couple of "/Info" paths/values (see dbus battery parameters and use "dbus-spy" to look at the values on a live system). Then you might want to enable DVCC and the chargers (if connected to Venus OS) will then use the parameters you previously published.


The above is what I did. There might be different approaches. And your scenario or use case might be different. My answer is based on what what you wrote and what I know. Hopefully this helps. Otherwise please you could provide more information on your setup and requirements.


2 |3000

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

dcsonka avatar image
dcsonka answered ·

I am also interested in how to read the temperature sensors values with a python script?

I can do it with dbus, but I want to read the same through a python script. How can I achieve the same through python?


root@einstein:~# dbus -y com.victronenergy.temperature.adc_builtin0_7 /Temperature GetValue

value = 19

2 comments
2 |3000

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

gone-sailing avatar image gone-sailing commented ·

You have multiple options, direct access to dbus, MQTT and ModTCP, using MQTT might be easier. It depends on where you want your code to run. If you gave a Cerbo, enabling the noce-red via Venus OS Large is problem the most simplest.

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

https://github.com/victronenergy/venus/wiki/dbus-api

https://github.com/victronenergy/dbus-mqtt

0 Likes 0 ·
Ronald Rink avatar image Ronald Rink commented ·

For reading data from other processes as your service, see description here: https://github.com/victronenergy/velib_python

Use VeDbusItemImport to read a single value from other processes the dbus, and monitor its signals.
Use DbusMonitor to monitor multiple values from other processes

See https://github.com/victronenergy/velib_python/blob/master/examples/vedbusitem_import_examples.py for an example with VeDbusItemImport. But DbusMonitor is probably preferred.

0 Likes 0 ·
krakel avatar image
krakel answered ·

Unfortunately I get for the command "dbus -y com.victronenergy.system/Dc/Battery/Soc GetValue" an empty output. Do I have to configure something before?

2 comments
2 |3000

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

gone-sailing avatar image gone-sailing commented ·

If you have ssh'ed into GX device, type dbus-spy to view the paths and values available. On my test device the Battery SOC reported by a BMV-702 is at

com.victronenergy.battery.ttyO2/Soc

1 Like 1 ·
Ronald Rink avatar image Ronald Rink commented ·
dbus -y com.victronenergy.system /Dc/Battery/Soc GetValue

You need to insert a SPACE character (" ") between the service name ("com.victronenergy.system") and the path ("/Dc/Battery/Soc").

0 Likes 0 ·

Related Resources

Additional resources still need to be added for this topic