Thank you for al the info.
I can decode my vbus file with manual codes. But automatic doenst work yet.
Which codes have you added in crontab?
0/1 * * * * wget -O /home/pi/resol-vbus.rs/vbus/current_packets.vbus http://192.168.2.19/current/current_packets.vbus
0/1 * * * * /home/pi/resol-vbus.rs/examples/formatter/target/release/formatter csv /home/pi/resol-vbus.rs/vbus/current_packets.vbus
the second code doesnt work, only when you are in the formatter folder. Do you have an solution?
The next step. How have you uploaded your .lua script in domoticz. I have added it to the dzvents folder but nnothing happens.
Thanks Sander
waaren wrote: ↑Monday 17 June 2019 17:41 Almost forgot to post the final working version here.![]()
Code: Select all
--[[ get values from csv file and store in virtual sensors (dzVents >= 2.4.19) Based on <TAB> separated data file: HR Solar BASIC controller [Regler] HR Solar BASIC controller [WMZ 1] [01] Date / Time [02] Systemdatum [03] Temperatur Sensor 1 [04] Temperatur Sensor 2 [05] Temperatur Sensor 3 [06] Temperatur Sensor 4 [07] TAGE [08] Volumenstrom Sensor V40 [09] Volumenstrom Sensor VFS [10] Temperatur Sensor VFS [11] Drehzahl Relais 1 [12] Drehzahl Relais 2 [13] Regler Ausgang 1 [14] Wmz1_Wert_Wh [15] SW-Version [16] Betriebsstunden Relais1 [17] Betriebsstunden Relais2 [18] Urlaubsfunktion [19] Blockierschutz 1 [20] Initalisieren [21] Befüllung [22] Stabilisieren [23] Pumpenverzögerung [24] Überwärmeabfuhr [25] Nachlauf [26] Speicherkühlung [27] Frostschutz [28] Kollektorkühlung [29] Einheit Temperatur [30] Speichermaximaltemperatur [31] Neustarts [32] Fehlermaske [33] Wmz1_Wert_Wh [34] Wmz1_Leistung_W [35] Wmz1_WertHeute_Wh [36] Wmz1_WertWoche_Wh ]]-- return { on = { timer = { 'every minute' }, -- change to the interval suited for your situation }, logging = { level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when script is working as expected marker = 'read CSV data' }, execute = function( dz ) local maxAge = 300 -- max Age of data file in seconds local round = dz.utils.round -- shorthand local dataFile = '/home/pi/resol-vbus.rs/examples/formatter/Output.csv' -- location/csfFile local temperatureSensor1 = dz.devices('temperature Solar collector') -- create as virtual temperature sensor local temperatureSensor2 = dz.devices('temperature Boilervat') -- create as virtual temperature sensor local temperatureSensorVFS = dz.devices('temperature outlet') -- create as virtual temperature sensor local drehzahlRelais1 = dz.devices('pump-speed Solar collector') -- create as virtual percentage sensor local Wmz1_Wert = dz.devices('total power Solar collector') -- create as Usage Electric local VolumenstromSensorVFS = dz.devices('Boiler outlet') -- create as waterflow (l/m) local Wmz1_WertHeute = dz.devices('daily total Solar collector') -- create as Usage Electric local function readCSVLine(OSfile) local f = assert(io.popen('tail -1 '.. OSfile)) -- OS command to read last line of file local line = assert(f:read('*a')) -- read the complete result into string variable f:close() -- close the file dz.log('line: ' .. line,dz.LOG_DEBUG) return dz.utils.stringSplit(line:gsub(',','.'),'%\t') -- replace decimal commas with . ; use TAB as delimiter and split line into columns (table) end local function isRecent(csvData) if csvData == nil or #csvData < 15 then dz.log("Problem with reading and converting to table of the data" ,dz.LOG_ERROR) return end local Time = require('Time') local csvTime = Time(csvData[1]:gsub('T',' ')) -- convert timestamp in csv file to time object local now = dz.time -- Get current time into time object if now.compare(csvTime).secs > maxAge then dz.log('Timestamp in ' .. dataFile .. ' is ' .. now.compare(csvTime).secs .. ' seconds old. Please check!',dz.LOG_ERROR) return end return true end local function updateTemperatureCheckFirst(device, temperature) if round(device.temperature,1) ~= round(temperature,1) then dz.log('---------' .. temperature ..' ==>> ' .. device.temperature ,dz.LOG_DEBUG) device.updateTemperature(round(temperature,1)) end end local function updateSensorsCheckFirst(csvData) -- Sensors will only be updated when old value ~= new value updateTemperatureCheckFirst(temperatureSensor1,csvData[3]) updateTemperatureCheckFirst(temperatureSensor2,csvData[4]) updateTemperatureCheckFirst(temperatureSensorVFS,csvData[10]) if round(drehzahlRelais1.percentage,1) ~= round(csvData[11],1) then drehzahlRelais1.updatePercentage(round(csvData[11],1)) end if round(Wmz1_Wert.WhActual,1) ~= round(csvData[14],1) then Wmz1_Wert.updateEnergy(round(csvData[14],1)) end if round(VolumenstromSensorVFS.flow,1) ~= round(csvData[9],1) then VolumenstromSensorVFS.updateWaterflow(round(csvData[9],1)) end if round(Wmz1_WertHeute.WhActual,1) ~= round(csvData[35],1) then WertHeute.updateEnergy(round(csvData[35],1)) end end -- main csvData = readCSVLine(dataFile) if isRecent(csvData) then updateSensorsCheckFirst(csvData) else dz.log("Something was not OK. Skipping device updates",dz.LOG_ERROR) end end }