GitHub repository: mr-manuel/venus-os_dbus-mqtt-pv
- Disclaimer
- Supporting/Sponsoring this project
- Purpose
- Config
- JSON structure
- Home Assistant
- Install
- Uninstall
- Restart
- Debugging
- Multiple instances
- Compatibility
- Screenshots
I wrote this script for myself. I'm not responsible, if you damage something using my script.
You like the project and you want to support me?
The script emulates a Photovoltaic AC Inverter in Venus OS. It gets the MQTT data from a subscribed topic and publishes the information on the dbus as the service com.victronenergy.pvinverter.mqtt_pv
with the VRM instance 51
.
Copy or rename the config.sample.ini
to config.ini
in the dbus-mqtt-pv
folder and change it as you need it.
Minimum required
{
"pv": {
"power": 0.0
}
}
Minimum required with L1
{
"pv": {
"power": 0.0,
"L1": {
"power": 0.0
}
}
}
Minimum required with L1, L2
{
"pv": {
"power": 0.0,
"L1": {
"power": 0.0
},
"L2": {
"power": 0.0
}
}
}
Minimum required with L1, L2, L3
{
"pv": {
"power": 0.0,
"L1": {
"power": 0.0
},
"L2": {
"power": 0.0
},
"L3": {
"power": 0.0
}
}
}
Full
{
"pv": {
"power": 0.0,
"voltage": 0.0,
"current": 0.0,
"energy_forward": 0.0, --> Total/Lifetime produced energy in kWh
"L1": {
"power": 0.0,
"voltage": 0.0,
"current": 0.0,
"frequency": 0.0,
"energy_forward": 0.0 --> Total/Lifetime produced energy in kWh
},
"L2": {
"power": 0.0,
"voltage": 0.0,
"current": 0.0,
"frequency": 0.0,
"energy_forward": 0.0 --> Total/Lifetime produced energy in kWh
},
"L3": {
"power": 0.0,
"voltage": 0.0,
"current": 0.0,
"frequency": 0.0,
"energy_forward": 0.0 --> Total/Lifetime produced energy in kWh
}
}
}
This is only a simple example that can be reduced expanded to match the minimum or full requirements shown above.
alias: mqtt publish sensor pv power
description: ""
trigger:
- platform: state
entity_id: sensor.YOUR_PV_POWER_ENTITY
condition: []
action:
- service: mqtt.publish
data_template:
payload: |
{
"pv": {
"power": {{ (states('sensor.YOUR_PV_POWER_ENTITY') | float(0)) }},
"L1": {
"power": {{ (states('sensor.YOUR_PV_L1_POWER_ENTITY') | float(0)) }}
},
"L2": {
"power": {{ (states('sensor.YOUR_PV_L2_POWER_ENTITY') | float(0)) }}
},
"L3": {
"power": {{ (states('sensor.YOUR_PV_L3_POWER_ENTITY') | float(0)) }}
}
}
}
topic: homeassistant/energy/pv
In the config.ini
of dbus-mqtt-pv
set the MQTT broker to the Home Assistant hostname/IP and the topic to the same as in your Home Assistant config (like above).
-
Login to your Venus OS device via SSH. See Venus OS:Root Access for more details.
-
Execute this commands to download and extract the files:
# change to temp folder cd /tmp # download driver wget -O /tmp/venus-os_dbus-mqtt-pv.zip https://github.com/mr-manuel/venus-os_dbus-mqtt-pv/archive/refs/heads/master.zip # If updating: cleanup old folder rm -rf /tmp/venus-os_dbus-mqtt-pv-master # unzip folder unzip venus-os_dbus-mqtt-pv.zip # If updating: backup existing config file mv /data/etc/dbus-mqtt-pv/config.ini /data/etc/dbus-mqtt-pv_config.ini # If updating: cleanup existing driver rm -rf /data/etc/dbus-mqtt-pv # copy files cp -R /tmp/venus-os_dbus-mqtt-pv-master/dbus-mqtt-pv/ /data/etc/ # If updating: restore existing config file mv /data/etc/dbus-mqtt-pv_config.ini /data/etc/dbus-mqtt-pv/config.ini
-
Copy the sample config file, if you are installing the driver for the first time and edit it to your needs.
# copy default config file cp /data/etc/dbus-mqtt-pv/config.sample.ini /data/etc/dbus-mqtt-pv/config.ini # edit the config file with nano nano /data/etc/dbus-mqtt-pv/config.ini
-
Run
bash /data/etc/dbus-mqtt-pv/install.sh
to install the driver as service.The daemon-tools should start this service automatically within seconds.
Run /data/etc/dbus-mqtt-pv/uninstall.sh
Run /data/etc/dbus-mqtt-pv/restart.sh
The logs can be checked with tail -n 100 -f /data/log/dbus-mqtt-pv/current | tai64nlocal
The service status can be checked with svstat svstat /service/dbus-mqtt-pv
This will output somethink like /service/dbus-mqtt-pv: up (pid 5845) 185 seconds
If the seconds are under 5 then the service crashes and gets restarted all the time. If you do not see anything in the logs you can increase the log level in /data/etc/dbus-mqtt-pv/dbus-mqtt-pv.py
by changing level=logging.WARNING
to level=logging.INFO
or level=logging.DEBUG
If the script stops with the message dbus.exceptions.NameExistsException: Bus name already exists: com.victronenergy.pvinverter.mqtt_pv"
it means that the service is still running or another service is using that bus name.
It's possible to have multiple instances, but it's not automated. Follow these steps to achieve this:
-
Save the new name to a variable
driverclone=dbus-mqtt-pv-2
-
Copy current folder
cp -r /data/etc/dbus-mqtt-pv/ /data/etc/$driverclone/
-
Rename the main script
mv /data/etc/$driverclone/dbus-mqtt-pv.py /data/etc/$driverclone/$driverclone.py
-
Fix the script references for service and log
sed -i 's:dbus-mqtt-pv:'$driverclone':g' /data/etc/$driverclone/service/run sed -i 's:dbus-mqtt-pv:'$driverclone':g' /data/etc/$driverclone/service/log/run
-
Change the
device_name
, increase thedevice_instance
and update thetopic
in theconfig.ini
Now you can install and run the cloned driver. Should you need another instance just increase the number in step 1 and repeat all steps.
It was tested on Venus OS Large v2.92
on the following devices:
- RaspberryPi 4b
- MultiPlus II (GX Version)