GitHub repository: mr-manuel/venus-os_dbus-mqtt-pv
- Disclaimer
- Supporting/Sponsoring this project
- Purpose
- Config
- JSON structure
- Install / Update
- Uninstall
- Restart
- Debugging
- 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,
"power_factor": 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,
"power_factor": 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,
"power_factor": 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).
{
"apower": 0.0,
"voltage": 0.0,
"freq": 0,
"current": 0.000,
"pf": 0,
"aenergy": {
"total": 0.000
}
}
Ensure your Shelly device uses the same topic as configured in config.ini
. Enable MQTT on your Shelly device and set the host, port, and topic correctly.
Setting up tasmota as Tasmota-SmartMeter is not part of this documentation. See https://tasmota.github.io/docs/Smart-Meter-Interface/#meter-metrics or https://homeitems.de/smartmeter-mit-tasmota-auslesen/# (German) for detailed information on how to set up Tasmota-EnergyMeter.
In order to get dbus-mqtt-pv working with the Tasmota-SmartMeter, the script on tasmota has to be configured in a specific way.
Depending on your individual Smart Meter, the first part of the script looks like this:
>D
>B
=>sensor53 r
>M 1
+1,3,s,0,9600,pv
Important for dbus-mqtt-pv is, that the <jsonPrefix>
of the meter definition is called pv
.
Following is an example of the meter metrics:
1,77070100100700ff@1,Current Consumption,W,power,16
1,77070100240700ff@1,Current Consumption P1,W,power_L1,16
1,77070100380700ff@1,Current Consumption P2,W,power_L2,16
1,770701004c0700ff@1,Current Consumption P3,W,power_L3,16
Important are the 2 last parts of each line.
- The last number (
16
) lets tasmota transmit this reading via mqtt immediately. This is necessary to get updates of the current power consumption as fast as possible. - The second last entry needs to be named exactly like this: L1:
power_L1
, L2:power_L2
, L3:power_L3
, total pv power:power
. These are the keywords that are expected by dbus-mqtt-pv.
The MQTT messages sent from tasmota should then look like this:
21:57:13.103 RSL: SENSOR = {"Time":"2023-11-22T21:57:13","pv":{"power":413}}
21:57:13.124 RSL: SENSOR = {"Time":"2023-11-22T21:57:13","pv":{"power_L1":94}}
Sending the total energy (kWh consumed and delivered) is also possible.
Since those values are not changing much, it is sufficient to transmit them only every TelePeriod seconds.
Again, the important parts are the last two of each line, where 3
in this case means that you will get a precision of 3 digits (see meter metrics/precision).
1,77070100010800ff@1000,Total Consumed,KWh,energy_forward,3
1,77070100020800ff@1000,Total Delivered,KWh,energy_reverse,3
It is possible to directly use the ip address of your venusOS installation as MQTT host in tasmota.
For this to work, set the MQTT part of config.ini
to localhost
and enable the MQTT server on your venusOS: https://github.com/victronenergy/dbus-mqtt#set-up
The topic in tasmota has to fit together with the config.ini. For example:
Tasmota Topic: SML
Tasmota Full Topic: %topic%/
config.ini topic = SML/SENSOR
Additional information can be found in this issue.
-
Login to your Venus OS device via SSH. See Venus OS:Root Access for more details.
-
Execute this commands to download and copy the files:
wget -O /tmp/download_dbus-mqtt-pv.sh https://raw.githubusercontent.com/mr-manuel/venus-os_dbus-mqtt-pv/master/download.sh bash /tmp/download_dbus-mqtt-pv.sh
-
Select the version you want to install.
-
Press enter for a single instance. For multiple instances, enter a number and press enter.
Example:
- Pressing enter or entering
1
will install the driver to/data/etc/dbus-mqtt-pv
. - Entering
2
will install the driver to/data/etc/dbus-mqtt-pv-2
.
- Pressing enter or entering
-
Edit the config file to fit your needs. The correct command for your installation is shown after the installation.
- If you pressed enter or entered
1
during installation:
nano /data/etc/dbus-mqtt-pv/config.ini
- If you entered
2
during installation:
nano /data/etc/dbus-mqtt-pv-2/config.ini
- If you pressed enter or entered
-
Install the driver as a service. The correct command for your installation is shown after the installation.
- If you pressed enter or entered
1
during installation:
bash /data/etc/dbus-mqtt-pv/install.sh
- If you entered
2
during installation:
bash /data/etc/dbus-mqtt-pv-2/install.sh
The daemon-tools should start this service automatically within seconds.
- If you pressed enter or entered
-
To uninstall the default instance:
bash /data/etc/dbus-mqtt-pv/uninstall.sh
-
To uninstall the second instance:
bash /data/etc/dbus-mqtt-pv-2/uninstall.sh
-
To restart the default instance:
bash /data/etc/dbus-mqtt-pv/restart.sh
-
To restart the second instance:
bash /data/etc/dbus-mqtt-pv-2/restart.sh
-
To check the logs of the default instance:
tail -n 100 -F /data/log/dbus-mqtt-pv/current | tai64nlocal
-
To check the logs of the second instance:
tail -n 100 -F /data/log/dbus-mqtt-pv-2/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.
This software supports the latest three stable versions of Venus OS. It may also work on older versions, but this is not guaranteed.