Page 1 of 1

Hybrid car power consumtion on socket + Wireless presence

Posted: Thursday 05 May 2016 12:39
by martjah
Hello,

I'm bought a Hybrid car and i would like to automate everything in Domoticz so i can see the power consumption/usage. It is a company car so i can get a refund on all the power usage for charging at home.
I would like to have a wireless power meter for that socket only.

I have the following 16A switch: http://www.klikaanklikuit.nl/shop/nl/aws-3500
The car charges at 10A so it should be safe.

The car has build in Wifi but it cannot connect to my Wireless. It is a stand alone AP. So i made a script to detect the presence of the Wifi SSID.

Code: Select all

#!/bin/bash

iwlist wlan0 scan | grep Immagetu_GSM1

if [ $? -eq 0 ]
then
  echo "The car is in the driveway, let's check if we have to do something in Domoticz."
	curl "http://192.168.0.204:8080/json.htm?type=devices&rid=451" | grep '"Status" : "On",'
		if [ $? -eq 0 ]
			then
				echo "The car was allready here :)"
			else 
				echo "Aha! You just got home, let's turn the switch on"
				curl "http://192.168.0.204:8080/json.htm?type=command&param=switchlight&idx=451&switchcmd=On"
		fi
else
  echo "The car is gone, let's check if it was already gone"
	curl "http://192.168.0.204:8080/json.htm?type=devices&rid=451" | grep '"Status" : "Off",'
		if [ $? -eq 0 ]
			then
				echo "The car was already gone"
			else 
				echo "Oh, someone took the car just now, let turn the switch off"
				curl "http://192.168.0.204:8080/json.htm?type=command&param=switchlight&idx=451&switchcmd=Off"
		fi
fi
I will make a Blockly that switches the KAKU switch on/off based on the car presence so that no one can use the socket when the car is not at home.

But i also want to generate an overview in Domoticz giving me the total power usage. Anyone have any suggestions?
I have the RFXCom 433 and the mysensors gateway (but i do not prefer to use home build stuff for 240v appliances)

Re: Hybrid car power consumtion on socket

Posted: Wednesday 11 May 2016 15:10
by dorenberg
Personally I would go for the Z-wave or Plugwise Solution. Plugwise can be found quite easily and rather cheap second hands on "marktplaats" or ebay. I have 13 circles of plugwise in use and that works perfectly. Logging per hour and day.

Re: Hybrid car power consumtion on socket

Posted: Wednesday 08 June 2016 11:43
by martjah
I have an update. I have the car and created a charging circuit.

I bought:
DD238-4 energy meter (Ebay)(i will make a Mysensors sensor in te future)
KlikaanKlikuit AWS-3500 (rated up to 3500watt, the car charges at 2400watt max)

But, can someone help me with my script? It detects te car Wifi, but it is not consistant when the car is at home. I would like to do 3 checks with a interval of a few minutes before the car is marked as gone. But my linux knowledge is to limited to create it.

Image

The car has been on the driveway until +/- 9:45 and then i've been away for a few short times. But as you can see it is on/off all night.
I want to switches the driveway socket based on the car presence but it is not reliable.


Nevermind, i was able to edit the script of Chopper Rob. Credits go to him:

Code: Select all

#!/usr/bin/python
#   Title: Car_wireless_presence.sh
#   Original scripts Author: Chopper Rob
#   Original script: check_device_online.py
#   Edit: Martjah
#   Date: 08-05-2016
#   Info: Check the presence of a certain wireless network. Example: A car with build in access point.
#   Version : 3
 
import sys
import datetime
import time
import os
import subprocess
import urllib2
import json
 
# Settings for the domoticz server
domoticzserver="192.168.0.204:8080"
 
 
# DO NOT CHANGE BEYOND THIS LINE
if len(sys.argv) != 5 :
  print "Not enough parameters. Needs %Host %Switchid %Interval %Cooldownperiod."
  sys.exit(0)
 
wireless_ssid=sys.argv[1]
switchid=sys.argv[2]
interval=sys.argv[3]
cooldownperiod=sys.argv[4]
previousstate=-1
lastsuccess=datetime.datetime.now()
lastreported=-1
domoticzurl = 'http://'+domoticzserver+'/json.htm?type=devices&filter=all&used=true&order=Name'
 
if int(subprocess.check_output('ps x | grep \'' + sys.argv[0] + ' ' + sys.argv[1] + '\' | grep -cv grep', shell=True)) > 2 :
 print datetime.datetime.now().strftime("%H:%M:%S") + "- script already running. exiting."
 sys.exit(0)
 
def domoticzstatus ():
  request = urllib2.Request(domoticzurl)
  response = urllib2.urlopen(request)
 
  json_object = json.loads(response.read())
 
  if json_object["status"] == "OK":
    for i, v in enumerate(json_object["result"]):
      if json_object["result"][i]["idx"] == switchid and "Lighting" in json_object["result"][i]["Type"] :
        if json_object["result"][i]["Status"] == "On": 
          status = 1
        if json_object["result"][i]["Status"] == "Off": 
          status = 0
  return status
 
print datetime.datetime.now().strftime("%H:%M:%S") + "- script started."
 
lastreported = domoticzstatus()
if lastreported == 1 :
  print datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + wireless_ssid + " is online"
if lastreported == 0 :
  print datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + wireless_ssid + " is offline"
 
while 1==1:
  currentstate = subprocess.call('iwlist wlan0 scan | grep '+ wireless_ssid +' > /dev/null', shell=True)
 
  if currentstate == 0 : lastsuccess=datetime.datetime.now()
  if currentstate == 0 and currentstate != previousstate and lastreported == 1 : 
    print datetime.datetime.now().strftime("%H:%M:%S") + "- " + wireless_ssid + " online, no need to tell domoticz"
  if currentstate == 0 and currentstate != previousstate and lastreported != 1 :
    if domoticzstatus() == 0 :
      print datetime.datetime.now().strftime("%H:%M:%S") + "- " + wireless_ssid + " online, tell domoticz it's back"
      urllib2.urlopen("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=On&level=0")
    else:
      print datetime.datetime.now().strftime("%H:%M:%S") + "- " + wireless_ssid + " online, but domoticz already knew" 
    lastreported=1
 
  if currentstate == 1 and currentstate != previousstate :
    print datetime.datetime.now().strftime("%H:%M:%S") + "- " + wireless_ssid + " offline, waiting for it to come back"
 
  if currentstate == 1 and (datetime.datetime.now()-lastsuccess).total_seconds() > float(cooldownperiod) and lastreported != 0 :
    if domoticzstatus() == 1 :
      print datetime.datetime.now().strftime("%H:%M:%S") + "- " + wireless_ssid + " offline, tell domoticz it's gone"
      urllib2.urlopen("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=Off&level=0")
    else:
      print datetime.datetime.now().strftime("%H:%M:%S") + "- " + wireless_ssid + " offline, but domoticz already knew"
    lastreported=0
 
  time.sleep (float(interval))
 
  previousstate=currentstate