Import external data as device

Moderator: leecollings

Post Reply
Donald
Posts: 2
Joined: Tuesday 22 November 2016 13:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Import external data as device

Post by Donald »

Hi,

Just started with Domoticz using some Zwave devices and wired thermometers, but I want more :)

I already use a RaspberryPi with "123solar" and "Metern" for my solar pannels and P1 energy meter and want to keep on using this system since it contains a 3-4 year old database.

Is it possible to import the values of these energy meters? Can I, for example, make a dummy meter with "value gas meter = cat /var/log/gas.txt" as device?

Grtz Don
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Import external data as device

Post by Egregius »

Sure, what data is in the txt file?

As example, I read a CSV file created by SBFSpot and use the response from domoticz as a service online check:

Code: Select all

#!/bin/bash
while :
do
	SECOND=$(date +%S)
	if [ $SECOND -eq 0 ]
	then
		H=$(date +%H)
		if (( 8 <= 10#$H && 10#$H < 23 )); then
			string=$(tail -1 $(/bin/ls -1t /volume1/files/temp/SBFSPOT/Zon-Spot*.csv | /bin/sed q))
			var=$(echo $string | awk -F";" '{print $1,$2,$3,$4,$5,$6,$7,$8,$9}')
			set -- $var
			oost=$8
			west=$9
			var=$(echo $oost | awk -F"," '{print $1}')
			set -- $var
			oostint=$1
			var=$(echo $west | awk -F"," '{print $1}')
			set -- $var
			westint=$1
			sum=$((oostint + westint))
		else
			sum=0
		fi
		DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command&param=udevice&idx=6&nvalue=0&svalue=$sum"`
		STATUS=`echo $DOMOTICZ | jq -r '.status'`
		if [ "$STATUS" == "OK" ] ; then
			#curl -s --connect-timeout 60 --max-time 60 "http://127.0.0.1/secure/phones.php"
			exit
		else
			sleep 5
			DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command&param=udevice&idx=6&nvalue=0&svalue=$sum"`
			STATUS2=`echo $DOMOTICZ | jq -r '.status'`
			if [ "$STATUS2" == "OK" ] ; then
				exit
			else
				sleep 5
				DOMOTICZ=`curl -s --connect-timeout 2 --max-time 5 "http://127.0.0.1:8084/json.htm?type=command&param=udevice&idx=6&nvalue=0&svalue=$sum"`
				STATUS3=`echo $DOMOTICZ | jq -r '.status'`
				if [ "$STATUS3" == "OK" ] ; then
					exit
				else
					curl -s --connect-timeout 2 --max-time 5 --data-urlencode "text=Domoticz Bad - Restarting" --data "silent=false" http://127.0.0.1/secure/telegram.php
					NOW=$(date +"%Y-%m-%d_%H%M%S")
					cp /volume1/appstore/domoticz/var/domoticz.log /volume1/files/temp/domoticz-$NOW.txt
					sudo /var/packages/domoticz/scripts/start-stop-status stop
					sleep 8
					sudo kill $(sudo netstat -anp | awk '/ LISTEN / {if($4 ~ ":8084$") { gsub("/.*","",$7); print $7; exit } }')
					sleep 8
					sudo /var/packages/domoticz/scripts/start-stop-status start
				fi
			fi
		fi
	fi
	sleep 0.8
done
The CSV looks like this:

Code: Select all

sep=;
Version CSV1|Tool SBFspot3.3.1 (Linux)|Linebreaks CR/LF|Delimiter semicolon|Decimalpoint comma|Precision 3

;;;;Watt;Watt;Amp;Amp;Volt;Volt;Watt;Watt;Watt;Amp;Amp;Amp;Volt;Volt;Volt;Watt;Watt;%;kWh;kWh;Hz;Hours;Hours;%;Status;Status;degC
dd.MM.yyyy HH:mm;DeviceName;DeviceType;Serial;Pdc1;Pdc2;Idc1;Idc2;Udc1;Udc2;Pac1;Pac2;Pac3;Iac1;Iac2;Iac3;Uac1;Uac2;Uac3;PdcTot;PacTot;Efficiency;EToday;ETotal;Frequency;OperatingTime;FeedInTime;BT_Signal;Condition;GridRelay;Temperature
22.11.2016 08:36;SN: 2100035823;SB 5000TL-20;2100035823;24,000;7,000;0,123;0,037;202,810;215,850;22,000;0,000;0,000;0,098;0,000;0,000;235,920;0,000;0,000;31,000;22,000;0,000;0,000;37574,581;50,000;33066,151;32189,152;72,941;Ok;Closed;23,570
22.11.2016 08:37;SN: 2100035823;SB 5000TL-20;2100035823;26,000;8,000;0,129;0,038;202,830;215,830;25,000;0,000;0,000;0,109;0,000;0,000;236,150;0,000;0,000;34,000;26,000;0,000;0,000;37574,581;50,000;33066,168;32189,168;72,549;Ok;Closed;23,570
22.11.2016 08:38;SN: 2100035823;SB 5000TL-20;2100035823;27,000;8,000;0,135;0,039;202,830;215,850;27,000;0,000;0,000;0,117;0,000;0,000;235,730;0,000;0,000;35,000;27,000;0,000;0,001;37574,582;49,990;33066,184;32189,185;74,118;Ok;Closed;23,570
22.11.2016 08:39;SN: 2100035823;SB 5000TL-20;2100035823;28,000;8,000;0,142;0,042;202,830;215,850;29,000;0,000;0,000;0,126;0,000;0,000;236,090;0,000;0,000;36,000;29,000;0,000;0,001;37574,582;50,000;33066,201;32189,202;72,157;Ok;Closed;23,570
22.11.2016 08:40;SN: 2100035823;SB 5000TL-20;2100035823;30,000;9,000;0,153;0,048;202,830;215,850;31,000;0,000;0,000;0,133;0,000;0,000;236,190;0,000;0,000;39,000;31,000;0,000;0,002;37574,583;50,000;33066,218;32189,218;72,549;Ok;Closed;23,780
22.11.2016 08:41;SN: 2100035823;SB 5000TL-20;2100035823;31,000;10,000;0,159;0,050;202,830;215,850;32,000;0,000;0,000;0,141;0,000;0,000;236,440;0,000;0,000;41,000;32,000;0,000;0,002;37574,583;50,000;33066,234;32189,235;73,725;Ok;Closed;23,780
22.11.2016 08:42;SN: 2100035823;SB 5000TL-20;2100035823;32,000;10,000;0,163;0,048;202,830;215,850;35,000;0,000;0,000;0,150;0,000;0,000;236,250;0,000;0,000;42,000;35,000;0,000;0,003;37574,584;49,980;33066,251;32189,252;73,333;Ok;Closed;23,780
22.11.2016 08:43;SN: 2100035823;SB 5000TL-20;2100035823;34,000;10,000;0,171;0,053;202,830;215,850;36,000;0,000;0,000;0,155;0,000;0,000;236,240;0,000;0,000;44,000;36,000;0,000;0,003;37574,584;49,990;33066,268;32189,268;74,118;Ok;Closed;23,780
22.11.2016 08:44;SN: 2100035823;SB 5000TL-20;2100035823;35,000;10,000;0,175;0,052;202,810;215,850;39,000;0,000;0,000;0,166;0,000;0,000;236,240;0,000;0,000;45,000;39,000;0,000;0,004;37574,585;49,980;33066,284;32189,285;73,333;Ok;Closed;23,780
Donald
Posts: 2
Joined: Tuesday 22 November 2016 13:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Import external data as device

Post by Donald »

Thnx, I am not a programmer. It will take some time to have it functional I suppose.
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: Import external data as device

Post by pj-r »

@Egregius: your script wont work in this case. Donald needs to "upload" all the historical data he has for 3-4 years to domoticz.
Domoticz JSON api supports only sending of current value no historical value..

Yes its possible. And no its not easy task. It has to be done by calculating daily values and uploading the data directly to domoticz.db. Its sqlite database. Check out tables: DeviceStatus, Multimeter and Multimeter_Calendar
And this code: https://github.com/domoticz/domoticz/bl ... .cpp#L4515

I think there is no ready made functionality for this. Some one could correct if I'm wrong.
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Import external data as device

Post by Egregius »

I missed the part for the history :P
Script is only for actual data.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest