Measure device consumption cheap way?

Others (MiLight, Hue, Toon etc...)
Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Saturday 13 February 2016 16:21

Also, I know that the sockets can be switched on or of through webcalls, I want to implement this through a a script and a switch in domoticz, do you have any examples for this?
Otherwise I will start on one but if there is something out there that I can use it will save me a lot of time.
I posted full instructions here: http://www.domoticz.com/forum/viewtopic ... 823#p74823

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Sunday 14 February 2016 20:53

Based on Thinkpad's code, I extended it in order to support all 6 outlets of one mPower Pro and 3 outlets of one mPower mini (Wifi only).
It is running every 30 sec. The Crontab is set with two entries

Code: Select all

* * * * * /home/domoticz/scripts/mFIGetValues.sh
* * * * * ( sleep 30 ; /home/domoticz/scripts/mFIGetValues.sh)
Don't forget to set the execution flag
Attachments
mFIGetValues.zip
(1.5 KiB) Downloaded 69 times

lassiko
Posts: 16
Joined: Tuesday 04 October 2016 22:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by lassiko » Tuesday 04 October 2016 22:52

I am trying to get this working but for some reason, i cannot see anything in Domoticz. Script works OK and it prints values to command line when i run the script, but for some reason it does not send anything to Domoticz. I have a single plug in use, without controller at the moment.

Domoticz log tells nothing after executing the script in command line. Can it be a permission issue etc?
I hope to get some help to this issue.

Thanks in advance!

EDIT: Actually, what i see in a log of domoticz is this : 2016-10-05 00:18:06.610 Incoming connection from: 192.168.0.220
this is a localhost IP, from where i am running a script from a command line. It shows this line only once after rebooting the domoticz, not after that at all even script is executed.

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Wednesday 05 October 2016 7:47

make sure the owner of the script is root

lassiko
Posts: 16
Joined: Tuesday 04 October 2016 22:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by lassiko » Wednesday 05 October 2016 9:32

Thanks for the fast reply! I changed the owner of the script to root, still nothing in domo. I assume that script should be added also to root's crontab?

From Chrome:

Code: Select all

http://192.168.0.220:8080/json.htm?type=command&param=udevice&idx=78&svalue=100
this updates the device in Domoticz just fine.

But this does not send anything..:

Code: Select all

#!/bin/bash                                                                     
#PLUGNAME=MPBureau #Not needed it looks, works fine without
PLUGIP=192.168.0.81
PLUGUSER=ubnt			#default "ubnt"
PLUGPASSWORD=ubnt		#default "ubnt"
SESSIONID=01234567890123456789012345678901

DOMOTICZSERVER=192.168.0.220
DOMOTICZPORT=8080

#Create virtual sensors in Domoticz and enter their IDX's here. For the sensor types, see Domoticz JSON wiki
IDX_POWER=78			
IDX_VOLT=80			
IDX_CURRENT=			
IDX_PF=					


if ping -c 1 $PLUGIP > /dev/null ; then  # if host is online then:
	
	#Login to webinterface of plug
	curl --silent -X POST -d "username=$PLUGUSER&password=$PLUGPASSWORD" -b "AIROS_SESSIONID=$SESSIONID" $PLUGIP/login.cgi

	#Turn outlet no1 on
	#curl --silent -X PUT -d output=1 -b "AIROS_SESSIONID="$SESSIONID 192.168.4.22/sensors/1 > /dev/null

	#Wait for 2 seconds to let plug measure the load
	#sleep 2
	
	#Retrieve all data from JSON-output
	SENSOR=$(curl --silent -b "AIROS_SESSIONID=$SESSIONID" $PLUGIP/sensors) 


	#Grab power (Watt) from retrieved values and leave 1 decimal, stripoff rest (change printf %.1f if you want more/less decimals)
	MPPOWER=$(echo $SENSOR | cut -d "," -f3 | cut -d ":" -f2 | awk '{printf("%.1f\n", $1)}')
	#Send data to Domoticz sensor without displaying any curl output on commandline
	curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_POWER'&svalue='$MPPOWER > /dev/null 
	#Display powerconsumption (Watt) on commandline
	echo $MPPOWER 'Watt'


	#Grab current (Ampère) from retrieved values and leave 1 decimal, stripoff rest (change printf %.3f if you want more/less decimals)
	MPCURRENT=$(echo $SENSOR | cut -d "," -f5 | cut -d ":" -f2 | awk '{printf("%.1f\n", $1)}')
	#Send data to Domoticz sensor without displaying any curl output on commandline
	#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_CURRENT'&svalue='$MPCURRENT > /dev/null 
	#Display current (Ampère) on commandline
	echo $MPCURRENT 'A'


	#Grab voltage (Volts) from retrieved values and leave 3 decimals, stripoff rest (change printf %.3f if you want more/less decimals)
	MPVOLTAGE=$(echo $SENSOR | cut -d "," -f6 | cut -d ":" -f2 | awk '{printf("%.3f\n", $1)}')
	curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_VOLT'&svalue='$MPVOLTAGE > /dev/null 
	#Display mains voltage (Volt) on commandline
	echo $MPVOLTAGE 'Volt'

	#Grab powerfactor (cos phi) from retrieved values and leave 2 decimals, stripoff rest (change printf %.2f if you want more/less decimals)
	MPPOFA=$(echo $SENSOR | cut -d "," -f7 | cut -d ":" -f2 | awk '{printf("%.2f\n", $1)}')
	#Send data to Domoticz sensor without displaying any curl output on commandline
	#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_PF'&svalue='$MPPOFA > /dev/null 
	#Display mains voltage (Volt) on commandline
	echo $MPPOFA 'cos phi'

	#Display info message
	#echo "Sensors in Domoticz should be updated with new values, have a look at them"
	
	#Turn outlet no1 off
	#curl --silent -X PUT -d output=0 -b "AIROS_SESSIONID="$SESSIONID 192.168.4.22/sensors/1 > /dev/null

	#Logout from plug
	curl -b "AIROS_SESSIONID=$SESSIONID" $PLUGIP/logout.cgi


else #Plug not responding to ping, display error message
	echo "Plug not responding to ping, is it connected to your WLAN?"
fi
It is most probably something very small that i am missing here to get it working, but cannot figure out what it is... :?

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Wednesday 05 October 2016 9:37

before adding it to the crontab I would create a dummy switch and see how things are going when the switch is set to ON for instance

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Wednesday 05 October 2016 10:08

sorry I answered too quickly. yes the script should be added in the crontab. But before doing that you have to make sure the Domoticz is updated when the script is run from the console. It seems it is not the case. just make a little script in order to make sure this command line works

Code: Select all

curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_POWER'&svalue='$MPPOWER > /dev/null 
Best thing to do is to go step by step. You may have an issue with quotes or whatever

lassiko
Posts: 16
Joined: Tuesday 04 October 2016 22:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by lassiko » Wednesday 05 October 2016 14:11

I got it working! What i needed to add was a $DOMOTICZUSER:$DOMOTICZPSW@ before IP_address:port.

If i understand correctly, i cannot get cumulative kWh info displayed without controller? I have a spare Raspberry which i am plan to install mfi controller into, but there seems to be some issues with DB size limits in Raspberry etc. Is there any other way to get cumulative kWh working?

Thanks!

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Wednesday 05 October 2016 16:12

Yes you can, use the P1 smartmeter device instead
I don't use any controller.
You may have noticed that these unify devices are discontinued

lassiko
Posts: 16
Joined: Tuesday 04 October 2016 22:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by lassiko » Wednesday 05 October 2016 18:06

Thanks for your help. Anyhow, it seems that after adding a Pi smartmeter it makes domoticz to crash. I need to restart it from a command line and then remove device to get it back to work. No errors on a log.

I tried to send data to smart meter manually, same result, domoticz crashes.
Last edited by lassiko on Wednesday 05 October 2016 18:22, edited 1 time in total.

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Wednesday 05 October 2016 18:09

Pretty strange. I have one dummy P1 smartmeter that works like a charm. Are you running the latest version of Domoticz? Or may be you are trying to update some data that does not exist?

lassiko
Posts: 16
Joined: Tuesday 04 October 2016 22:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by lassiko » Wednesday 05 October 2016 18:45

I am running a version 3.4834. I think that you are correct on that i am trying to update it with wrong data.
What i would want to see, is a data from this mFi plug:

Code: Select all

{"sensors":[{"port":1,"output":1,"power":96.558162569,"enabled":0,"current":0.426679849,"voltage":236.47731328,"powerfactor":0.956967914,"relay":1,"lock":0,"thismonth":0}],"status":"success"}
Or what i would need is a "power" to be shown and cumulative kWh data on that P1 Smartmeter. Any chance you could point me how to get this done with the script i am using currently?

Thanks!

Number8
Posts: 288
Joined: Friday 23 May 2014 7:55
Target OS: Raspberry Pi
Domoticz version: 3.5103
Location: Saint Pierre de Jards
Contact:

Re: Measure device consumption cheap way?

Post by Number8 » Wednesday 05 October 2016 19:21

are you using this API?
https://www.domoticz.com/wiki/Domoticz_ ... mart_meter

Here is a code where I'm using a smartmeter

Code: Select all

#!/bin/bash
ECODEVICE=192.168.21.231
#ECODEVICEUSERNAME=admin
#ECODEVICEPASSWORD=

LOGFILE="/mnt/usbkey/tmp/ecodevice.log"

DOMOTICZSERVER=192.168.21.240
DOMOTICZPORT=8080

#Create virtual sensors in Domoticz and enter their IDX's here. For the sensor types
IDX_SMARTMETER_1=211 # smartmeter 1
IDX_CONSO_1=210 # conso 1

if ping -c 1 $ECODEVICE > /dev/null ; then  # if host is online then
	
	#Retrieve teleinfo1
	curl --silent http://$ECODEVICE/protect/settings/teleinfo1.xml > $LOGFILE

	T1_PPAP_1=$(cat $LOGFILE | grep "<T1_PPAP>" | cut -d ">" -f 2 | cut -d "<" -f 1)
	#echo $T1_PPAP_1

	T1_HCHC_1=$(cat $LOGFILE | grep "<T1_HCHC>" | cut -d ">" -f 2 | cut -d "<" -f 1)
	#echo $T1_HCHC_1

	T1_HCHP_1=$(cat $LOGFILE | grep "<T1_HCHP>" | cut -d ">" -f 2 | cut -d "<" -f 1)
	#echo $T1_HCHP_1

	for i in 1
		do
			# report TELEINFO 1
			eval IDX='$'IDX_CONSO_$i
			#eval TEMP='$'T1_PPAP_$i
			curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$T1_PPAP_1 > /dev/null

#/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=USAGE1;USAGE2;RETURN1;RETURN2;CONS;PROD
#
#    IDX = id of your device (This number can be found in the devices tab in the column "IDX")
#    USAGE1= energy usage meter tariff 1
#    USAGE2= energy usage meter tariff 2
#    RETURN1= energy return meter tariff 1
#    RETURN2= energy return meter tariff 2
#    CONS= actual usage power (Watt)
#    PROD= actual return power (Watt)
#
#USAGE and RETURN are counters (they should only count up).
#For USAGE and RETURN supply the data in total Wh with no decimal point.
#(So if your meter displays f.i. USAGE1= 523,66 KWh you need to send 523660)
			eval IDX='$'IDX_SMARTMETER_$i
			curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&nvalue=0&svalue='$T1_HCHP_1';'$T1_HCHC_1';0;0;'$T1_PPAP_1';0' > /dev/null
		done

else
	echo "ECODEVICE not responding to ping, is it connected to LAN?"
fi




hexigen
Posts: 2
Joined: Monday 14 November 2016 23:56
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by hexigen » Thursday 17 November 2016 21:10

Hi, everyone.
Thank you ThinkPad for your script, it took me some time but it was fairly easy to figure out thanks to comments.
What's the consensus on the monthly or any other historical totals? Can this be done by someone who's a novice at coding?

Thank you,
- Serg

hexigen
Posts: 2
Joined: Monday 14 November 2016 23:56
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by hexigen » Thursday 01 December 2016 20:40

I was able to modify ThinkPad's script enough to make it work for my needs. I'll leave it here, maybe it'll help someone in my situation.
I am new to bash scripting and domoticz but it works. I needed to collect electrical reading from 2 mPower 8 port strips and store it historically using domoticz counters.

Using Domoticz' "Counter Incremental" virtual sensor I noticed that Domoticz automatically increments values and creates graph based on hourly averages. My script runs every minute using cron. It increments electric usage on a per/minute basis and updates the IDX of the Counter sensor. And then it resets electric reading value every hour so that the graph looks correct.

I have created two custom variables in Domoticz to keep track
CountOneHour (type = integer)
ElectricMeter (type = float)

Also I created a domoticz event to reset custom variables every day at 00:00 in case the script delays gradually and starts accumulating wrong reading.
ThinkPad's script is capable of outputting voltage and other values from mPower strips, but I didn't need those so I commented them out.

Code: Select all

#!/bin/bash
#PLUGNAME=MPBureau
#Not needed it looks, works fine without
mPowerDownstairs=192.168.99.8
mPowerUpstairs=192.168.99.9
PLUGUSER=admin         #default "ubnt"
PLUGPASSWORD=yourpassword      #default "ubnt"
SESSIONID=01234567890123456789080234567890

DOMOTICZSERVER=192.168.99.10
DOMOTICZPORT=8084

#Create virtual sensors in Domoticz and enter their IDX's here. For the sensor types, see Domoticz JSON wiki
IDX_POWER_1=43  # modem
#IDX_VOLT_1=
#IDX_CURRENT_1=
#IDX_PF_1=
#IDX_STATE_1=

IDX_POWER_2=58 # empty
#IDX_VOLT_2=
#IDX_CURRENT_2=
#IDX_PF_2=
#IDX_STATE_2=

IDX_POWER_3=45 # synology
#IDX_VOLT_3=
#IDX_CURRENT_3=
#IDX_PF_3=
#IDX_STATE_3=

IDX_POWER_4=46 # dell pc
#IDX_VOLT_4=
#IDX_CURRENT_4=
#IDX_PF_4=
#IDX_STATE_4=

IDX_POWER_5=47 # rpi
#IDX_VOLT_5=
#IDX_CURRENT_5=
#IDX_PF_1=
#IDX_STATE_5=

IDX_POWER_6=48  # maxtor
#IDX_VOLT_6=
#IDX_CURRENT_6=
#IDX_PF_6=
#IDX_STATE_6=

IDX_POWER_7=49   # netgear
#IDX_VOLT_7=
#IDX_CURRENT_7=
#IDX_PF_7=
#IDX_STATE_7=

IDX_POWER_9=51 # cablebox
#IDX_VOLT_9=
#IDX_CURRENT_9=
#IDX_PF_9=
#IDX_STATE_9=

IDX_POWER_10=52 #TV
#IDX_VOLT_10=
#IDX_CURRENT_10=
#IDX_PF_10=
#IDX_STATE_10=

IDX_POWER_11=53 # receiver
#IDX_VOLT_11=
#IDX_CURRENT_11=
#IDX_PF_11=
#IDX_STATE_11=

IDX_POWER_12=54 # roku
#IDX_VOLT_12=
#IDX_CURRENT_12=
#IDX_PF_12=
#IDX_STATE_12=

IDX_POWER_13=59 #P2 empty
#IDX_VOLT_13=
#IDX_CURRENT_13=
#IDX_PF_13=
#IDX_STATE_13=

IDX_POWER_14=55 # lamps
#IDX_VOLT_14=
#IDX_CURRENT_14=
#IDX_PF_14=
#IDX_STATE_14=

IDX_POWER_15=56 # subwoofer
#IDX_VOLT_15=
#IDX_CURRENT_15=
#IDX_PF_15=
#IDX_STATE_15=

IDX_POWER_16=57 # wdtv
#IDX_VOLT_16=
#IDX_CURRENT_16=
#IDX_PF_16=
#IDX_STATE_16=

onehourcount=$(curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=getuservariable&idx=3' | grep "Value" | cut -d '"' -f4)
if ((onehourcount == 60)); then
#Resetting one hour counter, setting energy usage var to 0
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=updateuservariable&vname=CountOneHour&vtype=0&vvalue=1' > /dev/null
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=updateuservariable&vname=ElectricMeter&vtype=1&vvalue=0' > /dev/null
else
onehourcount=$((onehourcount + 1))
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=updateuservariable&vname=CountOneHour&vtype=0&vvalue='$onehourcount > /dev/null
fi

if ping -c 1 $mPowerDownstairs > /dev/null ; then  # if host is online then:
#Login to webinterface of plug
curl --silent -X POST -d "username=$PLUGUSER&password=$PLUGPASSWORD" -b "AIROS_SESSIONID=$SESSIONID" $mPowerDownstairs/login.cgi

#Turn outlet no1 on
#curl --silent -X PUT -d output=1 -b "AIROS_SESSIONID="$SESSIONID 192.168.4.22/sensors/1 > /dev/null

#Retrieve all data from JSON-output
SENSOR=$(curl --silent -b "AIROS_SESSIONID=$SESSIONID" $mPowerDownstairs/sensors)
counter=0
for i in 1 2 3 4 5 6 7 8
do
#compute offset between lines
line=$(((i-1)*9))
#Current=$((line+5))
#Volt=$((line+6))
Power=$((line+3))
#PowerFactor=$((line+7))
#State=$((line+2))
#VoltPosition="f"$Volt
#CurrentPosition="f"$Current
PowerPosition="f"$Power
#StatePosition="f"$State
#PowerFactorPosition="f"$PowerFactor
#MPVOLTAGE=$(echo $SENSOR | cut -d "," -$VoltPosition | cut -d ":" -f2  | awk '{printf("%.3f\n", $1)}')
#MPCURRENT=$(echo $SENSOR | cut -d "," -$CurrentPosition | cut -d ":" -f2 | awk '{printf("%.2f\n", $1)}')
MPPOWER=$(echo $SENSOR | cut -d "," -$PowerPosition | cut -d ":" -f2  | awk '{printf("%.4f\n", $1)}')
#this value is processed in a specific script
#MPSTATE=$(echo $SENSOR | cut -d "," -$StatePosition | cut -d ":" -f2  | awk '{printf("%.0f\n", $1)}')
#if [ "$MPSTATE" = "1" ] ; then
#MPSTATE=On
#else
#MPSTATE=Off
#fi
#echo $MPVOLTAGE 'Volt-new'
#echo $MPCURRENT 'Current-new'
#echo $MPPOWER 'Power-new'
#echo $MPSTATE 'Relay state'
#report Voltage
#eval IDX='$'IDX_VOLT_$i
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$MPVOLTAGE > /dev/null
#report Power
eval IDX='$'IDX_POWER_$i
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$MPPOWER > /dev/null
counter=`awk "BEGIN {print $counter + $MPPOWER}"`
#report Current
#eval IDX='$'IDX_CURRENT_$i
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$MPCURRENT > /dev/null
##report Report relay state
#eval IDX='$'IDX_STATE_$i
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=switchlight&idx='$IDX'&switchcmd='$MPSTATE > /dev/null
done
echo "mPowerDownstairs total energy usage - $counter"

#Grab powerfactor (cos phi) from retrieved values and leave 2 decimals, stripoff rest (change printf %.2f if you want more/less decimals)
#MPPOFA=$(echo $SENSOR | cut -d "," -f7 | cut -d ":" -f2 | awk '{printf("%.4f\n", $1)}')
#Send data to Domoticz sensor without displaying any curl output on commandline
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_PF'&svalue='$MPPOFA > /dev/null
#Display mains voltage (Volt) on commandline
#echo $MPPOFA 'cos phi'

#Display info message
#echo "Sensors in Domoticz should be updated with new values, have a look at them"

#Turn outlet no1 off
#curl --silent -X PUT -d output=0 -b "AIROS_SESSIONID="$SESSIONID 192.168.4.22/sensors/1 > /dev/null

#Logout from plug
curl -b "AIROS_SESSIONID=$SESSIONID" $mPowerDownstairs/logout.cgi


else #Plug not responding to ping, display error message
echo "Plug not responding to ping, is it connected to your WLAN?"
fi


if ping -c 1 $mPowerUpstairs > /dev/null ; then  # if host is online then:
#Login to webinterface of plug
curl --silent -X POST -d "username=$PLUGUSER&password=$PLUGPASSWORD" -b "AIROS_SESSIONID=$SESSIONID" $mPowerUpstairs/login.cgi

#Turn outlet no1 on
#curl --silent -X PUT -d output=1 -b "AIROS_SESSIONID="$SESSIONID 192.168.4.22/sensors/1 > /dev/null

#Retrieve all data from JSON-output
SENSOR=$(curl --silent -b "AIROS_SESSIONID=$SESSIONID" $mPowerUpstairs/sensors)

for i in 9 10 11 12 13 14 15 16
do
#compute offset between lines
line=$(((i-9)*9))
#Current=$((line+5))
#Volt=$((line+6))
Power=$((line+3))
#PowerFactor=$((line+7))
#State=$((line+2))
#VoltPosition="f"$Volt
#CurrentPosition="f"$Current
PowerPosition="f"$Power
#StatePosition="f"$State
#PowerFactorPosition="f"$PowerFactor
#MPVOLTAGE=$(echo $SENSOR | cut -d "," -$VoltPosition | cut -d ":" -f2  | awk '{printf("%.3f\n", $1)}')
#MPCURRENT=$(echo $SENSOR | cut -d "," -$CurrentPosition | cut -d ":" -f2 | awk '{printf("%.2f\n", $1)}')
MPPOWER=$(echo $SENSOR | cut -d "," -$PowerPosition | cut -d ":" -f2  | awk '{printf("%.4f\n", $1)}')
#MPSTATE=$(echo $SENSOR | cut -d "," -$StatePosition | cut -d ":" -f2  | awk '{printf("%.0f\n", $1)}')
#if [ "$MPSTATE" = "1" ] ; then
#MPSTATE=On
#else
#MPSTATE=Off
#fi
#echo $MPVOLTAGE 'Volt-new'
#echo $MPCURRENT 'Current-new'
#echo $MPPOWER 'Power-new'
#echo $MPSTATE 'Relay state'
#report Voltage
#eval IDX='$'IDX_VOLT_$i
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$MPVOLTAGE > /dev/null
#report Power
eval IDX='$'IDX_POWER_$i
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$MPPOWER > /dev/null
counter=`awk "BEGIN {print $counter + $MPPOWER}"`
#report Current
#eval IDX='$'IDX_CURRENT_$i
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX'&svalue='$MPCURRENT > /dev/null
#report state of the switch
#eval IDX='$'IDX_STATE_$i
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=switchlight&idx='$IDX'&switchcmd='$MPSTATE > /dev/null
done
#counter=$(($counter/60))
echo "mPowerUpstairs total energy usage - $counter"
counter=`awk "BEGIN {print $counter / 60}"`
oldcounter=$(curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=getuservariable&idx=1' | grep "Value" | cut -d '"' -f4)
echo "Total energy used this hour in Wh - $oldcounter"
counter=`awk "BEGIN {print $counter + $oldcounter}"`
echo "Energy used in the last minute in Wh - $counter"
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=updateuservariable&vname=ElectricMeter&vtype=1&vvalue='$counter > /dev/null
counter=`awk "BEGIN {print $counter / 1000}"`
curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx=60&svalue='$counter > /dev/null

#Grab powerfactor (cos phi) from retrieved values and leave 2 decimals, stripoff rest (change printf %.2f if you want more/less decimals)
#MPPOFA=$(echo $SENSOR | cut -d "," -f7 | cut -d ":" -f2 | awk '{printf("%.4f\n", $1)}')
#Send data to Domoticz sensor without displaying any curl output on commandline
#curl --silent $DOMOTICZSERVER:$DOMOTICZPORT'/json.htm?type=command&param=udevice&idx='$IDX_PF'&svalue='$MPPOFA > /dev/null
#Display mains voltage (Volt) on commandline
#echo $MPPOFA 'cos phi'

#Display info message
#echo "Sensors in Domoticz should be updated with new values, have a look at them"

#Turn outlet no1 off
#curl --silent -X PUT -d output=0 -b "AIROS_SESSIONID="$SESSIONID 192.168.4.22/sensors/1 > /dev/null

#Logout from plug
curl -b "AIROS_SESSIONID=$SESSIONID" $mPowerUpstairs/logout.cgi


else #Plug not responding to ping, display error message
echo "Plug not responding to ping, is it connected to your WLAN?"
fi

jorcat
Posts: 5
Joined: Sunday 10 April 2016 23:04
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by jorcat » Wednesday 04 January 2017 12:38

digiwiz wrote:I use dlink dsp-w215 which are pretty good and cheap. (I bought them 25€ / plug)
Is there a way to use them through domoticz?
I use this smart plug DLink DSP-W215 through IFTT Maker Channel + DLink Smart Plug (https://ifttt.com/dlink_smart_plug).
But I don't find how to retrieve device consuption through Domoticz.

Did you find a way to use it through Domoticz?

DebgBill
Posts: 42
Joined: Tuesday 21 February 2017 17:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by DebgBill » Tuesday 21 February 2017 17:56

Hi

I have reworked the EcoDevices code to extend functionality. All 4 sensors should now work and most common subscription plans too. EJP and Tempo contracts are still not working as I lack test data.

You should not need external scripts anymore and run the native EcoDevice hardware instead.
Please upgrade to at least v3.6765 and tell me if it works for you

Blaise

sion
Posts: 122
Joined: Friday 08 January 2016 13:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Measure device consumption cheap way?

Post by sion » Monday 30 July 2018 17:15

Hi Guys,
appologies for digging up an old thread.
I am too looking for a way to measure a devices consumption.
Not looking to go zwave at the moment - but could look into that in the future.
I only really want this on 1 socket - so alexa can remind us when the washing machine has finished :)

I have heard that the Xiaomi sockets will work - but form what i can find they dont make uk ones?

Does anyone know of anf RF, or wifi ones that have come out recently that work with domoticz?

Cheers,
Sion.
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests