CVS file (on pi) to virtual sensors
Moderators: leecollings, remb0
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
CVS file (on pi) to virtual sensors
Hi all,
I have a solar boiler with a KM2 Resol interface. This generates no readable data that must be used in VBUS.net only. With a little rust script, thanks to danielwippermann, I am able to create a readable CSV file on my pi with the values of the boiler. (output.csv)
---------
SCRIPT:
#!/bin/bash
wget 192.168.2.9/current/current_packets.vbus. -- local ip of KM2
target/release/formatter csv current_packets.vbus --translates to csv
rm current_packets.vbus -- delete used VBus
-----
Now I need an option to get some (3) of this values into virtual Domoticz sensors. Think this can be done with a script but I lack the knowledge to create one myself. Is someone able to help me please?
This is a sample of the csv file. Need only three columns.
HR Solar BASIC controller [Regler]
Date / Time Systemdatum. Temperatur Sensor 1 Temperatur Sensor 2 Temperatur Sensor 3 Temperatur Sensor 4 T
2019-06-06T20:54:56+02:00 06.06.2019 20:55:57 26,3 35,0 2 0 0 25,8 0
Thank you!
I have a solar boiler with a KM2 Resol interface. This generates no readable data that must be used in VBUS.net only. With a little rust script, thanks to danielwippermann, I am able to create a readable CSV file on my pi with the values of the boiler. (output.csv)
---------
SCRIPT:
#!/bin/bash
wget 192.168.2.9/current/current_packets.vbus. -- local ip of KM2
target/release/formatter csv current_packets.vbus --translates to csv
rm current_packets.vbus -- delete used VBus
-----
Now I need an option to get some (3) of this values into virtual Domoticz sensors. Think this can be done with a script but I lack the knowledge to create one myself. Is someone able to help me please?
This is a sample of the csv file. Need only three columns.
HR Solar BASIC controller [Regler]
Date / Time Systemdatum. Temperatur Sensor 1 Temperatur Sensor 2 Temperatur Sensor 3 Temperatur Sensor 4 T
2019-06-06T20:54:56+02:00 06.06.2019 20:55:57 26,3 35,0 2 0 0 25,8 0
Thank you!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
Happy to help but need some additional informationJoost996me wrote: ↑Thursday 06 June 2019 21:17 I need an option to get some (3) of this values into virtual Domoticz sensors.
- What is the location of the file?
- Which columns do you need?
- What kind of sensors do you want to fill with the data?
- What should be the frequency of reading this data file and update the sensors with it ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Thanks for the reply
This file is located on ~/resol-vbus.rs/examples/formatter$
I need the data from column 3,4, 10, 11 and 14 of the csv file
For the first two sensors a need a temperature reading, then a percentage (pump%) and also a energy meter (WH)
wanted to refresh them once minute. Also use a crontab to create the output file this frequency.
Kind regards
This file is located on ~/resol-vbus.rs/examples/formatter$
I need the data from column 3,4, 10, 11 and 14 of the csv file
For the first two sensors a need a temperature reading, then a percentage (pump%) and also a energy meter (WH)
wanted to refresh them once minute. Also use a crontab to create the output file this frequency.
Kind regards
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
Sorry,Joost996me wrote: ↑Thursday 06 June 2019 22:08 For the first two sensors a need a temperature reading, then a percentage (pump%) and also a energy meter (WH)
still not completely clear. the ~ in the location is a replacement for your home directory. Domoticz needs an absolute path.
You mention column 14 but I only see 8 columns in your example.
csv is short for comma separated values but your example is <tab> separated and the temperatures use a decimal comma.
Will the crontab job create a new file or will it append to the last line of the existing file ?
Is your example really how the data will look like ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Thank you Waaren,
The full -fixed- path is: /home/pi/resol-vbus.rs/examples/formatter
The strange layout is due to a copy-paste in this website. I add the contructed output.csv, as opened in the text editor on my Mac. The extension of the file is CSV. But maybe it is tab separated.
The crontab creates/overwrites the output file, so that is refreshed every minute
------
HR Solar BASIC controller [Regler] HR Solar BASIC controller [WMZ 1]
Date / Time Systemdatum Temperatur Sensor 1 Temperatur Sensor 2 Temperatur Sensor 3 Temperatur Sensor 4 TAGE Volumenstrom Sensor V40 Volumenstrom Sensor VFS Temperatur Sensor VFS Drehzahl Relais 1 Drehzahl Relais 2 Regler Ausgang 1 Wmz1_Wert_Wh SW-Version Betriebsstunden Relais1 Betriebsstunden Relais2 Urlaubsfunktion Blockierschutz 1 Initalisieren Befüllung Stabilisieren Pumpenverzögerung Überwärmeabfuhr Nachlauf Speicherkühlung Frostschutz Kollektorkühlung Einheit Temperatur Speichermaximaltemperatur Neustarts Fehlermaske Wmz1_Wert_Wh Wmz1_Leistung_W Wmz1_WertHeute_Wh Wmz1_WertWoche_Wh
2019-06-06T22:33:38+02:00 06.06.2019 22:34:41 15,3 34,7 888,8 888,8 2 0 0 23,2 0 0 0 10954 2,02 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10954 0 5543 10954
-------
Dropboxlink to Output.csv file:
https://www.dropbox.com/s/02ex45v0uwdav ... t.csv?dl=0
Thank you for the patience...
The full -fixed- path is: /home/pi/resol-vbus.rs/examples/formatter
The strange layout is due to a copy-paste in this website. I add the contructed output.csv, as opened in the text editor on my Mac. The extension of the file is CSV. But maybe it is tab separated.
The crontab creates/overwrites the output file, so that is refreshed every minute
------
HR Solar BASIC controller [Regler] HR Solar BASIC controller [WMZ 1]
Date / Time Systemdatum Temperatur Sensor 1 Temperatur Sensor 2 Temperatur Sensor 3 Temperatur Sensor 4 TAGE Volumenstrom Sensor V40 Volumenstrom Sensor VFS Temperatur Sensor VFS Drehzahl Relais 1 Drehzahl Relais 2 Regler Ausgang 1 Wmz1_Wert_Wh SW-Version Betriebsstunden Relais1 Betriebsstunden Relais2 Urlaubsfunktion Blockierschutz 1 Initalisieren Befüllung Stabilisieren Pumpenverzögerung Überwärmeabfuhr Nachlauf Speicherkühlung Frostschutz Kollektorkühlung Einheit Temperatur Speichermaximaltemperatur Neustarts Fehlermaske Wmz1_Wert_Wh Wmz1_Leistung_W Wmz1_WertHeute_Wh Wmz1_WertWoche_Wh
2019-06-06T22:33:38+02:00 06.06.2019 22:34:41 15,3 34,7 888,8 888,8 2 0 0 23,2 0 0 0 10954 2,02 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10954 0 5543 10954
-------
Dropboxlink to Output.csv file:
https://www.dropbox.com/s/02ex45v0uwdav ... t.csv?dl=0
Thank you for the patience...
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
First version. Can you please check and revert ?Joost996me wrote: ↑Thursday 06 June 2019 21:17 I have a solar boiler with a KM2 Resol interface. I am able to create a readable CSV file on my pi with the values of the boiler.
Now I need an option to get some of this values into virtual Domoticz sensors.
Code: Select all
return {
on =
{
timer = { 'every minute' },
},
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
local dataFile = '/home/pi/resol-vbus.rs/examples/formatter$/output.csv'
local temperatureSensor1 = dz.devices('Temperatur Sensor 1') -- create as virtual temperature sensor
local temperatureSensor2 = dz.devices('Temperatur Sensor 2') -- create as virtual temperature sensor
local temperatureSensorVFS = dz.devices('Temperatur Sensor VFS') -- create as virtual temperature sensor
local drehzahlRelais1 = dz.devices('Drehzahl Relais 1') -- create as virtual percentage sensor
local Wmz1_Wert = dz.devices('Wmz1_Wert_Wh') -- create as Usage Electric
local function stringSplit(text, sep) -- this function is defined in dz.utils for versions >= 2.4.19
local sep = sep or '%s' -- Split a line in separate words. Default separator is space. Return is a table with separate words.
local t = {}
for str in string.gmatch(text, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
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
return stringSplit(line:gsub(',','.'):gsub("\t",";" ),";") -- replace decimal commas with . and replace TABS with ; and split line into columns (table)
end
local function isRecent(csvData)
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 false
end
return true
end
local function dumpCSV(csv)
for i, value in ipairs(csv) do
dz.log(i .. ': ' .. value,dz.LOG_DEBUG)
end
end
local function updateTemperature(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
-- main
csvData = readCSVLine(dataFile)
dumpCSV(csvData) -- Only for debug
if isRecent(csvData) then
-- Sensors will only be updated when old value ~= new value
updateTemperature(temperatureSensor1,csvData[3])
updateTemperature(temperatureSensor2,csvData[4])
updateTemperature(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
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Dear Waaren,
Thank you very much for the effort you put in this script!
I created the virtual sensors in Domoticz with the provided names. Uploaded the script in DzVents. The scripts runs, as can be seen in the logs. But unfortunately no values in the sensors right now.
This is in the log:
2019-06-07 21:42:00.886 Status: dzVents: Info: read CSV data: ------ Start internal script: KM2:, trigger: every minute
2019-06-07 21:42:00.939 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor 1: Temperature device adapter
2019-06-07 21:42:00.942 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor 2: Temperature device adapter
2019-06-07 21:42:00.944 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor VFS: Temperature device adapter
2019-06-07 21:42:00.946 Status: dzVents: Debug: read CSV data: Processing device-adapter for Drehzahl Relais 1: Percentage device adapter
2019-06-07 21:42:00.949 Status: dzVents: Debug: read CSV data: Processing device-adapter for Wmz1_Wert_Wh: Electric usage device adapter
2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: An error occured when calling event handler KM2
2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: /home/pi/domoticz/scripts/dzVents/generated_scripts/KM2.lua:42: attempt to index field '?' (a nil value)
2019-06-07 21:42:00.972 Status: dzVents: Info: read CSV data: ------ Finished KM2
We are getting close!
Your help is very much appreciated!
Joost
Thank you very much for the effort you put in this script!
I created the virtual sensors in Domoticz with the provided names. Uploaded the script in DzVents. The scripts runs, as can be seen in the logs. But unfortunately no values in the sensors right now.
This is in the log:
2019-06-07 21:42:00.886 Status: dzVents: Info: read CSV data: ------ Start internal script: KM2:, trigger: every minute
2019-06-07 21:42:00.939 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor 1: Temperature device adapter
2019-06-07 21:42:00.942 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor 2: Temperature device adapter
2019-06-07 21:42:00.944 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor VFS: Temperature device adapter
2019-06-07 21:42:00.946 Status: dzVents: Debug: read CSV data: Processing device-adapter for Drehzahl Relais 1: Percentage device adapter
2019-06-07 21:42:00.949 Status: dzVents: Debug: read CSV data: Processing device-adapter for Wmz1_Wert_Wh: Electric usage device adapter
2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: An error occured when calling event handler KM2
2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: /home/pi/domoticz/scripts/dzVents/generated_scripts/KM2.lua:42: attempt to index field '?' (a nil value)
2019-06-07 21:42:00.972 Status: dzVents: Info: read CSV data: ------ Finished KM2
We are getting close!
Your help is very much appreciated!
Joost
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
@Joost996me, if you copied / paste the posted script without modification, I expect a lot more in the log before the script logic reach this line.Joost996me wrote: ↑Friday 07 June 2019 21:45 2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: An error occured when calling event handler KM2
2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: /home/pi/domoticz/scripts/dzVents/generated_scripts/KM2.lua:42: attempt to index field '?' (a nil value)
code in line 42
Code: Select all
local csvTime = Time(csvData[1]:gsub('T',' ')) -- convert timestamp in csv file to time object
Code: Select all
2019-06-07 22:10:00.673 Status: dzVents: Info: read CSV data: ------ Start external script: dumper425 (csv read).lua:, trigger: every minute
2019-06-07 22:10:00.676 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor 1: Temperature device adapter
2019-06-07 22:10:00.678 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor 2: Temperature device adapter
2019-06-07 22:10:00.679 Status: dzVents: Debug: read CSV data: Processing device-adapter for Temperatur Sensor VFS: Temperature device adapter
2019-06-07 22:10:00.681 Status: dzVents: Debug: read CSV data: Processing device-adapter for Drehzahl Relais 1: Percentage device adapter
2019-06-07 22:10:00.686 Status: dzVents: Debug: read CSV data: Processing device-adapter for Wmz1_Wert_Wh: Electric usage device adapter
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 1: 2019-06-07T17:33:38+02:00
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 2: 06.06.2019 22:34:41
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 3: 15.3
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 4: 34.7
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 5: 888.8
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 6: 888.8
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 7: 2
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 8: 0
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 9: 0
2019-06-07 22:10:00.709 Status: dzVents: Debug: read CSV data: 10: 23.2
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 11: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 12: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 13: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 14: 10954
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 15: 2.02
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 16: 21
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 17: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 18: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 19: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 20: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 21: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 22: 0
2019-06-07 22:10:00.710 Status: dzVents: Debug: read CSV data: 23: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 24: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 25: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 26: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 27: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 28: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 29: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 30: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 31: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 32: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 33: 10954
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 34: 0
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 35: 5543
2019-06-07 22:10:00.711 Status: dzVents: Debug: read CSV data: 36: 10954
2019-06-07 22:10:00.712 Status: dzVents: Error (2.4.22): read CSV data: Timestamp in /home/pi/resol-vbus.rs/examples/formatter$/output.csv is 16582 seconds old. Please check!
2019-06-07 22:10:00.713 Status: dzVents: Info: read CSV data: ------ Finished dumper425 (csv read).lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
@Joost996me,
Just thinking out loud; why do you need the bash scripts anyway?
Can you please try this small script and post the result ( can be via PM if you prefer)
Just thinking out loud; why do you need the bash scripts anyway?
Can you please try this small script and post the result ( can be via PM if you prefer)
Code: Select all
local scriptVar = 'KM2Resol'
return {
on = {
timer = { 'every minute'},
httpResponses = { scriptVar },
},
logging = {
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
local KM2url = 'http://192.168.2.9/current/current_packets.vbus'
local function getKM2Data()
dz.openURL(
{
url = KM2url,
callback = scriptVar,
})
end
if item.isHTTPResponse then
dz.log("Return from KM2 \n" .. item.data,dz.LOG_DEBUG)
else
getKM2Data()
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
The script is resulting in this log. not sure what is does...
Think i need the conversion from vbus km2 to readable cvs data...
2019-06-07 22:57:52.601 Status: EventSystem: Script event triggered: Consumption
2019-06-07 22:58:00.667 Status: dzVents: Info: KM2Resol: ------ Start internal script: KM2resol:, trigger: every minute
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: url = http://192.168.2.9/current/current_packets.vbus.
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: method = GET
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: post data = nil
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: headers = nil
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: callback = KM2Resol
2019-06-07 22:58:00.669 Status: dzVents: Info: KM2Resol: ------ Finished KM2resol
2019-06-07 22:58:00.670 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-06-07 22:58:00.911 Status: dzVents: Info: Handling httpResponse-events for: "KM2Resol
2019-06-07 22:58:00.912 Status: dzVents: Info: KM2Resol: ------ Start internal script: KM2resol: HTTPResponse: "KM2Resol"
2019-06-07 22:58:00.912 Status: dzVents: Debug: KM2Resol: Return from KM2
2019-06-07 22:58:00.912
2019-06-07 22:58:00.913 Status: dzVents: Info: KM2Resol: ------ Finished KM2resol
Think i need the conversion from vbus km2 to readable cvs data...
2019-06-07 22:57:52.601 Status: EventSystem: Script event triggered: Consumption
2019-06-07 22:58:00.667 Status: dzVents: Info: KM2Resol: ------ Start internal script: KM2resol:, trigger: every minute
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: url = http://192.168.2.9/current/current_packets.vbus.
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: method = GET
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: post data = nil
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: headers = nil
2019-06-07 22:58:00.668 Status: dzVents: Debug: KM2Resol: OpenURL: callback = KM2Resol
2019-06-07 22:58:00.669 Status: dzVents: Info: KM2Resol: ------ Finished KM2resol
2019-06-07 22:58:00.670 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-06-07 22:58:00.911 Status: dzVents: Info: Handling httpResponse-events for: "KM2Resol
2019-06-07 22:58:00.912 Status: dzVents: Info: KM2Resol: ------ Start internal script: KM2resol: HTTPResponse: "KM2Resol"
2019-06-07 22:58:00.912 Status: dzVents: Debug: KM2Resol: Return from KM2
2019-06-07 22:58:00.912
2019-06-07 22:58:00.913 Status: dzVents: Info: KM2Resol: ------ Finished KM2resol
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
I expected something (else) . What do you see if you enter the wget command in the bash script from the CLI ?Joost996me wrote: ↑Friday 07 June 2019 22:59 The script is resulting in this log. not sure what is does...Code: Select all
2019-06-07 22:58:00.912 Status: dzVents: Info: KM2Resol: ------ Start internal script: KM2resol: HTTPResponse: "KM2Resol" 2019-06-07 22:58:00.912 Status: dzVents: Debug: KM2Resol: Return from KM2 2019-06-07 22:58:00.912 2019-06-07 22:58:00.913 Status: dzVents: Info: KM2Resol: ------ Finished KM2resol
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
When I perform " wget 192.168.2.9/current/current_packets.vbus" in the CLI, it returns with:
Connecting to 192.168.2.9:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 282 [application/octet-stream]
Saving to: ‘current_packets.vbus’
current_packets.vbu 100%[=====================>] 282 --.-KB/s in 0s
2019-06-08 08:22:08 (5.52 MB/s) - ‘current_packets.vbus’ saved [282/282]
Connecting to 192.168.2.9:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 282 [application/octet-stream]
Saving to: ‘current_packets.vbus’
current_packets.vbu 100%[=====================>] 282 --.-KB/s in 0s
2019-06-08 08:22:08 (5.52 MB/s) - ‘current_packets.vbus’ saved [282/282]
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
Did send you a PMJoost996me wrote: ↑Friday 07 June 2019 21:45 2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: An error occured when calling event handler KM2
2019-06-07 21:42:00.971 Status: dzVents: Error (2.4.19): read CSV data: /home/pi/domoticz/scripts/dzVents/generated_scripts/KM2.lua:42: attempt to index field '?' (a nil value)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 18
- Joined: Sunday 12 February 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Waaren did help me a lot to get this working! (so thankful!) If someone needs help with this subject please pm me
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 5
- Joined: Thursday 31 December 2015 16:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Hi all,
I Have a similar case with my PV SMA. I'm using a solarlog who work with a ftp server, the available files type is (for example 21.03.20) min200321.js .
It's a file who contained :
m[mi++]="21.03.20 19:00:00|0;0;17003;0|0;0;16956;0"
m[mi++]="21.03.20 18:55:00|0;0;17003;0|0;0;16956;0"
m[mi++]="21.03.20 18:50:00|0;0;17003;0|0;0;16956;0"
m[mi++]="21.03.20 18:45:00|3;12;17003;0|7;26;16956;0"
m[mi++]="21.03.20 18:40:00|15;32;17003;0|17;40;16956;0"
m[mi++]="21.03.20 18:35:00|30;46;17003;0|32;53;16955;0"
m[mi++]="21.03.20 18:30:00|46;61;17000;0|48;66;16952;0"
m[mi++]="21.03.20 18:25:00|53;66;16996;0|54;71;16948;0"
m[mi++]="21.03.20 18:20:00|72;84;16992;0|74;89;16944;0"
the column with the value 17003 is the value for the inverter number 1 and the 16956 value is for the inverter number 2.
So I hope to concatenate the value to make a grafic with a virtual sensor.
I tried to modify your script but it's to difficult for me :/
Could someone help me ?
Thank you,
Kind regards,
Slexik
I Have a similar case with my PV SMA. I'm using a solarlog who work with a ftp server, the available files type is (for example 21.03.20) min200321.js .
It's a file who contained :
m[mi++]="21.03.20 19:00:00|0;0;17003;0|0;0;16956;0"
m[mi++]="21.03.20 18:55:00|0;0;17003;0|0;0;16956;0"
m[mi++]="21.03.20 18:50:00|0;0;17003;0|0;0;16956;0"
m[mi++]="21.03.20 18:45:00|3;12;17003;0|7;26;16956;0"
m[mi++]="21.03.20 18:40:00|15;32;17003;0|17;40;16956;0"
m[mi++]="21.03.20 18:35:00|30;46;17003;0|32;53;16955;0"
m[mi++]="21.03.20 18:30:00|46;61;17000;0|48;66;16952;0"
m[mi++]="21.03.20 18:25:00|53;66;16996;0|54;71;16948;0"
m[mi++]="21.03.20 18:20:00|72;84;16992;0|74;89;16944;0"
the column with the value 17003 is the value for the inverter number 1 and the 16956 value is for the inverter number 2.
So I hope to concatenate the value to make a grafic with a virtual sensor.
I tried to modify your script but it's to difficult for me :/
Could someone help me ?
Thank you,
Kind regards,
Slexik
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
Happy to help but need some additional information
- What is the location of the file?
- What do the values in the columns represent ?
- What kind of sensors do you want to fill with the data?
- What should be the frequency of reading this data file and update the sensors with it ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 5
- Joined: Thursday 31 December 2015 16:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Hi Waaren,
Thank you for your help.
So the location of the file is : /home/pi/domoticz/data but I need to download the file on the ftp server from solarlog
The value of the two columns is the wh (watt per hour) so 17003 + 16956 = 33959 wh of 33.96 kwh -> need to be on the grafic
I would make a grafic for yield in kwh per day, per month, per year and total, like this one : https://ibb.co/DGhq8Sf
Actually my data file log the value every 5 minutes, but 1x hour seems to be good.
Kind regards,
slexik
Thank you for your help.
So the location of the file is : /home/pi/domoticz/data but I need to download the file on the ftp server from solarlog
The value of the two columns is the wh (watt per hour) so 17003 + 16956 = 33959 wh of 33.96 kwh -> need to be on the grafic
I would make a grafic for yield in kwh per day, per month, per year and total, like this one : https://ibb.co/DGhq8Sf
Actually my data file log the value every 5 minutes, but 1x hour seems to be good.
Kind regards,
slexik
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: CVS file (on pi) to virtual sensors
I can only collect the data from the file and update a (to be created) virtual domoticz device with that data.slexik wrote: ↑Sunday 29 March 2020 16:58 So the location of the file is : /home/pi/domoticz/data but I need to download the file on the ftp server from solarlog
The value of the two columns is the wh (watt per hour) so 17003 + 16956 = 33959 wh of 33.96 kwh -> need to be on the grafic
I would make a grafic for yield in kwh per day, per month, per year and total, like this one : https://ibb.co/DGhq8Sf
Actually my data file log the value every 5 minutes, but 1x hour seems to be good.
I also understand there is already a Python plugin available. ( Check this post )
If that does not work for you I need you to share the ftp command you use to collect the file. It would even better if the SAM system has an option to get the data directly in a JSON or XML.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 5
- Joined: Thursday 31 December 2015 16:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: CVS file (on pi) to virtual sensors
Hi waaren,
This python plugin work with an utp connection, my inverter doesn't support that, just bluetooth but dont work perfectly and actually a solar log box with a rs485 port. I just find another way, home assistant can integrate solar log with json (https://www.home-assistant.io/integrations/solarlog/) but i'm not sure that's possible with domoticz.
tnx
This python plugin work with an utp connection, my inverter doesn't support that, just bluetooth but dont work perfectly and actually a solar log box with a rs485 port. I just find another way, home assistant can integrate solar log with json (https://www.home-assistant.io/integrations/solarlog/) but i'm not sure that's possible with domoticz.
tnx
Who is online
Users browsing this forum: No registered users and 1 guest