Skip to content

mr-manuel/venus-os_dbus-mqtt-pv

Repository files navigation

dbus-mqtt-pv - Emulates a physical PV Inverter from MQTT data

GitHub repository: mr-manuel/venus-os_dbus-mqtt-pv

Index

  1. Disclaimer
  2. Supporting/Sponsoring this project
  3. Purpose
  4. Config
  5. JSON structure
  6. Home Assistant
  7. Install / Update
  8. Uninstall
  9. Restart
  10. Debugging
  11. Compatibility
  12. Screenshots

Disclaimer

I wrote this script for myself. I'm not responsible, if you damage something using my script.

Supporting/Sponsoring this project

You like the project and you want to support me?

Purpose

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.

Config

Copy or rename the config.sample.ini to config.ini in the dbus-mqtt-pv folder and change it as you need it.

JSON structure

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
        }
    }
}

Home Assistant

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).

Install / Update

  1. Login to your Venus OS device via SSH. See Venus OS:Root Access for more details.

  2. 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
  3. Select the version you want to install.

  4. 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.

Extra steps for your first installation

  1. 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
  2. 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.

Uninstall

⚠️ If you have multiple instances, ensure you choose the correct one. For example:

  • 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

Restart

⚠️ If you have multiple instances, ensure you choose the correct one. For example:

  • 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

Debugging

⚠️ If you have multiple instances, ensure you choose the correct one.

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.

Compatibility

This software supports the latest three stable versions of Venus OS. It may also work on older versions, but this is not guaranteed.

Screenshots

Power and/or L1

Pv power L1 - pages Pv power L1 - device list Pv power L1 - device list - mqtt pv 1 Pv power L1 - device list - mqtt pv 2

Power, L1 and L2

Pv power L1, L2 - pages Pv power L1, L2 - device list Pv power L1, L2 - device list - mqtt pv 1 Pv power L1, L2 - device list - mqtt pv 2

Power, L1, L2 and L3

Pv power L1, L2, L3 - pages Pv power L1, L2, L3 - device list Pv power L1, L2, L3 - device list - mqtt pv 1 Pv power L1, L2, L3 - device list - mqtt pv 2