Skip to content

Commit

Permalink
Added new virtual devices (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkjanfaber committed Dec 9, 2024
1 parent 3d7a156 commit 74da818
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/nodes/victron-virtual.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

function checkSelectedVirtualDevice() {
[
'grid', 'tank', 'temperature'
'grid', 'pvinverter', 'tank', 'temperature'
].map( x => { $('.input-'+x).hide() })
const selected = $('select#node-input-device').val()
$('.input-'+selected).show()
Expand Down Expand Up @@ -60,6 +60,8 @@
instance: {value:"", required: true},
// grid
grid_nrofphases: {value: 1, required: false},
// pvinverter
position: { value: 0, required: false},
// tank
fluid_type: { value: 0, required: false},
include_tank_battery: { value: false },
Expand Down Expand Up @@ -95,8 +97,10 @@
<div class="form-row">
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
<select id="node-input-device" required onchange="checkSelectedVirtualDevice()">
<option value="battery">Battery</option>
<option value="grid">Grid meter</option>
<option value="meteo">Meteo</option>
<option value="pvinverter">PV inverter</option>
<option value="tank">Tank sensor</option>
<option value="temperature">Temperature sensor</option>
</select>
Expand Down Expand Up @@ -159,6 +163,16 @@
<input type="number" id="node-input-tank_battery_voltage" style="width:100px;" value="3.3" step="0.1" min="0">
</div>
</div>
<div class="input-pvinverter">
<div class="form-row">
<label for="node-input-position"><i class="fa fa-sliders"></i> Position</label>
<select id="node-input-position">
<option value="0">AC input 1</option>
<option value="1">AC output</option>
<option value="2">AC input 2</option>
</select>
</div>
</div>
<div class="input-temperature">
<div class="form-row">
<label for="node-input-temperature_type"><i class="fa fa-thermometer-half"></i> Temperature type</label>
Expand Down
58 changes: 55 additions & 3 deletions src/nodes/victron-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const dbus = require('dbus-native-victron')
const debug = require('debug')('victron-virtual')

const properties = {
battery: {
Capacity: { type: 'd', format: (v) => v != null ? v.toFixed(0) + 'Ah' : '' },
'Dc/0/Current': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'A' : '' },
'Dc/0/Power': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'Dc/0/Voltage': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'V' : '' },
'Dc/0/Temperature': { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'C' : '' },
Soc: { type: 'd', min: 0, max: 100, format: (v) => v != null ? v.toFixed(0) + '%' : '' },
},
temperature: {
Temperature: { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'C' : '' },
TemperatureType: {
Expand All @@ -18,7 +26,8 @@ const properties = {
},
Pressure: { type: 'd', format: (v) => v != null ? v.toFixed(0) + 'hPa' : '' },
Humidity: { type: 'd', format: (v) => v != null ? v.toFixed(1) + '%' : '' },
BatteryVoltage: { type: 'd', value: 3.3, format: (v) => v != null ? v.toFixed(2) + 'V' : '' }
BatteryVoltage: { type: 'd', value: 3.3, format: (v) => v != null ? v.toFixed(2) + 'V' : '' },
Status: {type: 'i' }
},
grid: {
'Ac/Energy/Forward': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'kWh' : '', value: 0 },
Expand Down Expand Up @@ -53,6 +62,45 @@ const properties = {
'Temperature/LeavingWaterTempBeforeBUH': { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'C' : '' },
'Temperature/OutdoorHeatExchanger': { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'C' : '' }
},
pvinverter: {
'Ac/Energy/Forward': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'kWh' : '' },
'Ac/Power': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'Ac/L1/Current': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'A' : '' },
'Ac/L1/Energy/Forward': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'kWh' : '' },
'Ac/L1/Power': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'Ac/L1/Voltage': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'V' : '' },
'Ac/L2/Current': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'A' : '' },
'Ac/L2/Energy/Forward': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'kWh' : '' },
'Ac/L2/Power': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'Ac/L2/Voltage': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'V' : '' },
'Ac/L3/Current': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'A' : '' },
'Ac/L3/Energy/Forward': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'kWh' : '' },
'Ac/L3/Power': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'Ac/L3/Voltage': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'V' : '' },
'Ac/MaxPower': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'Ac/PowerLimit': { type: 'd', format: (v) => v != null ? v.toFixed(2) + 'W' : '' },
'ErrorCode': { type: 'i', value: 0, format: (v) => ({
0: 'No error',
}[v] || 'unknown'), },
'Position': { type: 'i', format: (v) => ({
0: 'AC input 1',
1: 'AC output',
2: 'AC input 2',
}[v] || 'unknown'), },
'StatusCode': { type: 'i', format: (v) => ({
0: 'Startup 0',
1: 'Startup 1',
2: 'Startup 2',
3: 'Startup 3',
4: 'Startup 4',
5: 'Startup 5',
6: 'Startup 6',
7: 'Running',
8: 'Standby',
9: 'Boot loading',
10: 'Error',
}[v] || 'unknown'), },
},
meteo: {
Irradiance: { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'W/m2' : '' },
WindSpeed: { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'm/s' : '' },
Expand Down Expand Up @@ -96,7 +144,8 @@ const properties = {
Remaining: { type: 'd' },
Shape: { type: 's' },
Temperature: { type: 'd', format: (v) => v != null ? v.toFixed(1) + 'C' : '' },
BatteryVoltage: { type: 'd', value: 3.3, format: (v) => v != null ? v.toFixed(2) + 'V' : '' }
BatteryVoltage: { type: 'd', value: 3.3, format: (v) => v != null ? v.toFixed(2) + 'V' : '' },
Status: {type: 'i' }
}
}

Expand All @@ -117,7 +166,6 @@ function getIfaceDesc (dev) {

result.DeviceInstance = { type: 'i' }
result.CustomName = { type: 's' }
result.Status = { type: 'i' }
result.Serial = { type: 's' }

return result
Expand Down Expand Up @@ -292,6 +340,10 @@ module.exports = function (RED) {
text = `Virtual ${iface.NrOfPhases}-phase grid meter`
break
}
case 'pvinverter': {
iface.Position = Number(config.position ?? 0)
break
}
case 'tank':
iface.FluidType = Number(config.fluid_type ?? 1) // Fresh water
if (!config.include_tank_battery) {
Expand Down

0 comments on commit 74da818

Please sign in to comment.