Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Jan 2, 2023
1 parent d6fd43a commit 6212c0e
Show file tree
Hide file tree
Showing 15 changed files with 1,500 additions and 0 deletions.
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# dbus-mqtt-battery - Emulates a physical PV Inverter from MQTT data

<small>GitHub repository: https://github.com/mr-manuel/venus-os_dbus-mqtt-battery</small>

### Disclaimer

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


### Purpose

The script emulates a battery in Venus OS. It gets the MQTT data from a subscribed topic and publishes the information on the dbus as the service `com.victronenergy.battery.mqtt_battery` with the VRM instance `41`.


### Config

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


### JSON structure

<details><summary>Required data</summary>

```json
{
"dc": {
"power": 79.6,
"voltage": 58.1,
"current": 1.4,
"temperature": 23
},
"consumed_amphours": 2.9,
"soc": 99,
"history": {
"voltageMin": 0,
"voltageMax": 0
}
}
```
</details>


### Install

1. Copy the `dbus-mqtt-battery` folder to `/data/etc` on your Venus OS device

2. Run `bash /data/etc/dbus-mqtt-battery/install.sh` as root

The daemon-tools should start this service automatically within seconds.

### Uninstall

Run `/data/etc/dbus-mqtt-battery/uninstall.sh`

### Restart

Run `/data/etc/dbus-mqtt-battery/restart.sh`

### Debugging

The logs can be checked with `tail -n 100 -f /data/log/dbus-mqtt-battery/current | tai64nlocal`

The service status can be checked with svstat `svstat /service/dbus-mqtt-battery`

This will output somethink like `/service/dbus-mqtt-battery: 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-battery/dbus-mqtt-battery.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.battery.mqtt_battery"` it means that the service is still running or another service is using that bus name.

### Compatibility

It was tested on following devices:

* RaspberryPi 4b
* MultiPlus II (GX Version)

### Screenshots

<details><summary>MQTT Battery</summary>

![MQTT Battery - pages](/screenshots/battery_pages.png)
![MQTT Battery - device list](/screenshots/battery_device_list.png)
![MQTT Battery - device list - mqtt battery](/screenshots/battery_device_list_mqtt-battery.png)

</details>
46 changes: 46 additions & 0 deletions dbus-mqtt-battery/config.sample.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[BATTERY]
; lower voltage when warning alarm is triggered
; default: 3.0 * cell count
VoltageLowWarning = 48.0
; lower voltage when critical alarm is triggered
; default: 2.9 * cell count
VoltageLowCritical = 46.4
; higher voltage when warning alarm is triggered
; default: 3.5 * cell count
VoltageHighWarning = 56.0
; higher voltage when critical alarm is triggered
; default: 3.6 * cell count
VoltageHighCritical = 57.6

; low SoC in percent (%) when warning alarm is triggered
LowSocWarning = 10.0
; low SoC in percent (%) when critical alarm is triggered
LowSocCritical = 5.0


[MQTT]
; IP addess or FQDN from MQTT server
broker_address = IP_ADDR_OR_FQDN

; Port of the MQTT server
; default plaintext: 1883
; default TLS port: 8883
broker_port = 1883

; Enables TLS
;tls_enabled = 1

; Absolute path to the Certificate Authority certificate file that is to be treated as trusted by this client
;tls_path_to_ca = /data/keys/mosquitto.crt

; Disables verification of the server hostname in the server certificate
;tls_insecure = 1

; Username used for connection
;username = myuser

; Password used for connection
;password = mypassword

; Topic where the meters data as JSON string is published
topic = enphase/battery
Loading

0 comments on commit 6212c0e

Please sign in to comment.