question

mihair avatar image
mihair asked

This is for those who asked for a solution to dump excess PV power using dbus and VenusOS shell script

Hi,

I have seen requests in this forum for a script for dumping excess solar power to hot water tank based on system conditions like SOC, PV power and loads. Here is an example of a possible solution using dbus and a system relay for firing on and off the water tank heater


#!/bin/bash

# Fire ON Relay1 only if all of the folowing conditions are met:

# - Battery SOC >= 80%

# - Solarmax Power >= 1900 W

# - CriticalLoads power <= 1200 W


echo

DATE="Run at $(date +"%a %d%b %Hh%M") UTC"

echo $DATE


GONOGO_SM=`dbus -y com.victronenergy.grid.cgwacs_ttyUSB2_di32_mb1 /Connected GetValue | awk '{printf("%d\n",$3 + 0.5);}'`

GONOGO_BAT=`dbus -y com.victronenergy.battery.socketcan_can0 /Connected GetValue | awk '{printf("%d\n",$3 + 0.5);}'`

GONOGO_MULTI=`dbus -y com.victronenergy.vebus.ttyUSB0 /Connected GetValue | awk '{printf("%d\n",$3 + 0.5);}'`


# Run this script only if PV Inverter, CAN-BUS Battery and Multi are up and running, otherwise turn OFF Relay1

if [ $GONOGO_SM -eq 1 ] && [ $GONOGO_BAT -eq 1 ] && [ $GONOGO_MULTI -eq 1 ]

then

echo "---------------------------------------"

# Read output power of Solarmax, battery SOC and critical loads power consumption

SMP=`dbus -y com.victronenergy.pvinverter.cgwacs_ttyUSB2_di30_mb2 /Ac/L1/Power GetValue | awk '{printf("%d\n",$3 + 0.5);}'`

SOC=`dbus -y com.victronenergy.battery.socketcan_can0 /Soc GetValue | awk '{printf("%d\n",$3 + 0.5);}'`

CLP=`dbus -y com.victronenergy.system /Ac/ConsumptionOnOutput/L1/Power GetValue | awk '{printf("%d\n",$1 + 0.5);}'`

echo "Battery SOC $SOC"%

echo "SolarMax Power $SMP"W

echo "UPSloads Power $CLP"W


# Fire ON relay1 if SOC >= 80, SolarPower >= 1.9kW and Critical Loads <= 1.2kW

STATE=`dbus -y com.victronenergy.system /Relay/1/State GetValue`

if [ $SOC -ge 80 ] && [ $SMP -ge 1900 ] && [ $CLP -le 1200 ]

then

if [ $STATE -eq 0 ]

then

echo "---------------------------------------"

echo "Fire ON Relay1"

dbus -y com.victronenergy.system /Relay/1/State SetValue 1

else

echo "Relay1 is already ON"

fi

else

if [ $STATE -eq 1 ]

then

echo "---------------------------------------"

echo "Power OFF Relay1"

dbus -y com.victronenergy.system /Relay/1/State SetValue 0

else

echo "Relay1 is already OFF"

fi

fi


else

echo "---------------------------------------"

if [ $GONOGO_SM -eq 1 ]

then

echo "Warning! EM111 SOLARMAX PV Inverter meter not responding. Check RS485 connection or EM111!"

fi

if [ $GONOGO_BAT -eq 1 ]

then

echo "Warning! REC-BMS not responding. Check the unit or CAN connection!"

fi

if [ $GONOGO_MULTI -eq 1 ]

then

echo "Warning! MultiPlus not responding. Check the unit status!"

fi

echo "Power OFF Relay1"

dbus -y com.victronenergy.system /Relay/1/State SetValue 0

fi


echo

echo "***************************************"


This script should be executed every minute by crond system daemon using #crontab -e command with the following syntax:

0-59 * * * * /home/root/.ControlRelay1.sh > /dev/null 2>&1


Regards,

Mihai

Venus OS
2 |3000

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

2 Answers
petajoule avatar image
petajoule answered ·

Very nice, but I have quite the trouble with the persistence.

as mentioned in the other thread, setting the Buzzer is not persistent. And setting the Relay also seems to not have the right effect:

root@ccgx:~# dbus -y com.victronenergy.system /Relay/0/State SetValue 0
0
root@ccgx:~# dbus -y com.victronenergy.system /Relay/0/State GetValue
1
root@ccgx:~# dbus -y com.victronenergy.system /Relay/0/State SetValue 1
0
root@ccgx:~# dbus -y com.victronenergy.system /Relay/0/State GetValue
1

As you can see, setting to either 0 or 1 doesn't seem to have an effect. DBUS always returns 1 as the value for the relay.

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.

petajoule avatar image petajoule commented ·

Scrap that

Settings > Relay > Function set to "manual"

and behold: it behaves as you manually tell it to. ;-)

0 Likes 0 ·
mihair avatar image mihair commented ·

If your Relay/0 is used by another process then it will not survive at your dbus modifications

Please check CCGX>Settings>Relay page. If Function (Relay 1) is enabled then this is the case.. You can switch it back to manual for testing purposes and then dbus will work

0 Likes 0 ·
colin-jones avatar image
colin-jones answered ·

Thank you mihair for the sample. Very helpful as I am a novice at Linux and Bash.

I used dbus-spy to find my actual service names and it has been a great template.

You use a mixture of $1 and $3 in the printf calls, which I understand to be rounding the result to integer values, even though they are piping from a dbus ... -GetValue output.

I have found that sometimes I need one or the other from trial and error.

Is there logic behind it ? The service queried ? The value being returned ?


2 |3000

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

Related Resources