Victron vs Smart Home
In this post, we will show you how to read information from a photovoltaic power plant from the company Victron. We will connect to the Cerbo unit via MQTT. Based on these values, we can control various devices (heating, boiler, etc.) and prevent battery waste for large appliances when they don't need to run.
Hardware
Pi-Home - if you don't have it, see the section How to Do It
Victron FVE
Software
OpenHAB 3
Procedure:
1) Find the IP address of Cerbo on your router. Usually in the DHCP tab, for example, on MikroTik, go to IP-> DHCP Server -> Leases. In this example, it's 10.1.1.125
2) Enter the IP in your browser and enable the MQTT Broker function in Settings -> Services.
3) In OpenHAB, in Settings -> Things, add a new MQTT Broker (New Thing -> MQTT -> MQTT Broker) and enter the Cerbo's IP address. Use "ccgx" as the identifier and name it, for example, MQTT CCGX
4) Connect to Raspberry via SSH
ssh openhabian@RASPBERRY-IP-ADDRESS
5) Connect to Raspberry via SSH (our fictional OpenHAB IP is 10.1.1.125)
mosquitto_sub -h 10.1.1.125 -t "#"
If everything is working, you will get a VRM ID:
In the following sections, replace the ID with your own ID. Since MQTT on Cerbo goes to "sleep" every 60 seconds, we need to keep refreshing communication and tell it that someone is listening. For this, a simple rule in Rules directly in OpenHAB 3 UI is sufficient. Go to Rules, add a new rule, give it a name (e.g., Cerbo's Refresh), and use the following code:
triggers:
- id: "1"
configuration:
cronExpression: 0/30 * * * * ? *
type: timer.GenericCronTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: |
val actions = getActions("mqtt", "mqtt:broker:ccgx")
actions.publishMQTT("R/c0619*****/system/0/Serial", "")
logInfo("Solar", "CCGX MQTT Keep Alive Timer fired!!")
type: script.ScriptAction
Select Save. Then you can create a new Thing for each item you want to read into OpenHAB. Again, go to Settings -> Things, and using the + icon, create a new one. Fill it out according to the following pattern. Don't forget to choose the MQTT Victron in the MQTT Broker that you created earlier.
After creating it, expand the Code tab where you can copy the following channels:
UID: mqtt:topic:pihome:vitronthings
label: Victron Things
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:ccgx
channels:
- id: pv_battery_soc
channelTypeUID: mqtt:dimmer
label: Battery SoC
description: null
configuration:
stateTopic: N/c0619*******/system/0/Dc/Battery/Soc
transformationPattern: JSONPATH:$.value
- id: pv_battery_temp
channelTypeUID: mqtt:dimmer
label: Battery Temperature
description: null
configuration:
stateTopic: N/c0619*******/system/0/Dc/Battery/Temperature
transformationPattern: JSONPATH:$.value
- id: pv_battery_state
channelTypeUID: mqtt:dimmer
label: Battery State
description: null
configuration:
stateTopic: N/c0619*******/system/0/Dc/Battery/State
transformationPattern: JSONPATH:$.value
- id: pv_battery_voltage
channelTypeUID: mqtt:number
label: Battery Voltage
description: null
configuration:
formatBeforePublish: "%.4f"
stateTopic: N/c0619*******/system/0/Dc/Battery/Voltage
transformationPattern: JSONPATH:$.value
- id: pv_battery_power
channelTypeUID: mqtt:number
label: Battery Power
description: null
configuration:
formatBeforePublish: "%.4f"
stateTopic: N/c0619*******/system/0/Dc/Battery/Power
transformationPattern: JSONPATH:$.value
- id: pv_power_pv
channelTypeUID: mqtt:number
label: Solar Power
description: null
configuration:
stateTopic: N/c0619*******/system/0/Dc/Pv/Power
transformationPattern: JSONPATH:$.value
- id: pv_power_consumptionL1
channelTypeUID: mqtt:number
label: Consumption L1
description: null
configuration:
stateTopic: N/c0619*******/system/0/Ac/Consumption/L1/Power
transformationPattern: JSONPATH:$.value
- id: pv_power_consumptionL2
channelTypeUID: mqtt:number
label: Consumption L2
description: null
configuration:
stateTopic: N/c0619*******/system/0/Ac/Consumption/L2/Power
transformationPattern: JSONPATH:$.value
- id: pv_power_consumptionL3
channelTypeUID: mqtt:number
label: Consumption L3
description: null
configuration:
stateTopic: N/c0619*******/system/0/Ac/Consumption/L3/Power
transformationPattern: JSONPATH:$.value
- id: grid_power_consumptionL1
channelTypeUID: mqtt:number
label: Grid L1
description: null
configuration:
stateTopic: N/c0619*******/system/0/Ac/Grid/L1/Power
transformationPattern: JSONPATH:$.value
- id: grid_power_consumptionL2
channelTypeUID: mqtt:number
label: Grid L2
description: null
configuration:
stateTopic: N/c0619*******/system/0/Ac/Grid/L2/Power
transformationPattern: JSONPATH:$.value
- id: grid_power_consumptionL3
channelTypeUID: mqtt:number
label: Grid L3
description: null
configuration:
stateTopic: N/c0619*******/system/0/Ac/Grid/L3/Power
transformationPattern: JSONPATH:$.value
- id: pv0_power
channelTypeUID: mqtt:number
label: PV0 Power
description: null
configuration:
stateTopic: N/c0619*******/solarcharger/0/Yield/Power
transformationPattern: JSONPATH:$.value
- id: pv1_power
channelTypeUID: mqtt:number
label: PV1 Power
description: null
configuration:
stateTopic: N/c0619*******/solarcharger/1/Yield/Power
transformationPattern: JSONPATH:$.value
After Channels, go to Settings -> Items -> Add Items from Textual Definition and paste below rows:
Group Victron "Victron" <energy> ["Inverter"]
Number pv_battery_soc "Battery SoC" <energy> (Victron) ["Energy"] { channel="mqtt:topic:pihome:vitronthings:pv_battery_soc" }
Number pv_battery_temp "Battery Temperature" <energy> (Victron) ["Temperature"] { channel="mqtt:topic:pihome:vitronthings:pv_battery_temp" }
Number pv_battery_state "Battery State" <energy> (Victron) ["Status"] { channel="mqtt:topic:pihome:vitronthings:pv_battery_state" }
Number pv_battery_voltage "Battery Voltage" <energy> (Victron) ["Voltage"] { channel="mqtt:topic:pihome:vitronthings:pv_battery_voltage" }
Number pv_battery_power "Battery Power" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv_battery_power" }
Number pv_power_pv "Solar Power" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv_power_pv" }
Number pv_power_consumptionL1 "Consumption L1" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv_power_consumptionL1" }
Number pv_power_consumptionL2 "Consumption L2" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv_power_consumptionL2" }
Number pv_power_consumptionL3 "Consumption L3" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv_power_consumptionL3" }
Number grid_power_consumptionL1 "Grid L1" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:grid_power_consumptionL1" }
Number grid_power_consumptionL2 "Grid L2" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:grid_power_consumptionL2" }
Number grid_power_consumptionL3 "Grid L3" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:grid_power_consumptionL3" }
Number pv0_power "PV0 Power" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv0_power" }
Number pv1_power "PV1 Power" <energy> (Victron) ["Power"] { channel="mqtt:topic:pihome:vitronthings:pv1_power" }
Insert it, and you're done! In OpenHAB, you now have real-time data from Victron. You can create various rules and also access the history and graphs of these values in OpenHAB. It's up to you how you want to display this in your dashboard and what rules you want to create. We welcome any rule suggestions in the comments.
You can find a complete list of the values that can be read in the download link here:
Tip: For all items, you can add Add metadata -> State description, and in the Pattern field, you can change the formatting. For example, a value like %.1f W in the Pattern field means rounding to one decimal place and the unit is Watts.
Add comment