Page 1 of 1

Energy meter python to domoticz.

Posted: Friday 31 January 2020 10:30
by progresive
Hello

I connected a sensor to the domoticz that counts the blinks of the energy meter diode. It works almost very well, but I have some doubts.

I have a dual tariff meter, so I created three counter types in domoticz.
1- suamrically IDX 66
2 - first tariff IDX 67
3 - second tariff IDX 68
licznikw1.JPG
licznikw1.JPG (67.22 KiB) Viewed 287 times

Python script :

Code: Select all

#!/usr/bin/python
 
#licznik1
import RPi.GPIO as GPIOL1

import time
import urllib
import datetime
 
sensorL1 = 12
 
GPIOL1.setmode(GPIOL1.BCM)
GPIOL1.setup(sensorL1, GPIOL1.IN, GPIOL1.PUD_DOWN)

previous_stateL1 = False
current_stateL1 = False


time13 = datetime.time(13,00,00)
time15 = datetime.time(15,00,00)
time22 = datetime.time(22,00,00)
time24 = datetime.time(23,59,59)
time00 = datetime.time(00,00,00)
time06 = datetime.time(6,00,00)
 
while True:
  time.sleep(0.1)
  #licz1
  previous_stateL1 = current_stateL1
  current_stateL1 = GPIOL1.input(sensorL1)
  if current_stateL1 != previous_stateL1:
    #new_state = "HIGH" if current_state else "LOW"
    #print ("GPIO pin %s is %s" % (sensor, new_state))
    nowtime = datetime.datetime.now().time()
    print ("Prad sumarycznie"), nowtime
    httpresponse = urllib.urlopen ("http://192.168.1.249:8080/json.htm?type=command&param=udevice&idx=66&svalue=1")

    if (nowtime > time13 and nowtime < time15) or (nowtime > time22 and nowtime < time24) or (nowtime > time00 and nowtime < time06):
      httpresponse = urllib.urlopen ("http://192.168.1.249:8080/json.htm?type=command&param=udevice&idx=68&svalue=1")
      print ("Prad 2 taryfa"), nowtime
    else:
      httpresponse = urllib.urlopen ("http://192.168.1.249:8080/json.htm?type=command&param=udevice&idx=67&svalue=1")
      print ("Prad 1 taryfa"), nowtime
In general, it works only I do not understand the rules of saving data in domoticz. For example, if we have a transition between tariffs, when a tariff begins, devices in domoticz that theoretically should not count anymore, be able to count SOMETHING.

Tariff 1 IDC 67
licznikw2.JPG
licznikw2.JPG (66.71 KiB) Viewed 287 times
Tariff 2 IDC 68
licznikw3.JPG
licznikw3.JPG (71.65 KiB) Viewed 287 times
For example, after 6 am the 2nd tariff (IDX68) should not have entries in the database, meanwhile some entries in the domoticz test appear even until 6:55 and I do not know what is caused. Sometimes, as below, these are the same values ​​of 2931 - theoretically nothing, sometimes a few "Wh" will fall in the wrong hour.

Code: Select all

sqlite> select * from meter where DeviceRowID = 68 and Date between "2020-01-31 05:00:00" and "2020-01-31 08:00:00";
68|2653|0|2020-01-31 05:00:03
68|2661|0|2020-01-31 05:05:06
68|2691|0|2020-01-31 05:10:04
68|2718|0|2020-01-31 05:15:10
68|2741|0|2020-01-31 05:20:03
68|2773|0|2020-01-31 05:25:06
68|2791|0|2020-01-31 05:30:04
68|2793|0|2020-01-31 05:35:06
68|2809|0|2020-01-31 05:40:02
68|2819|0|2020-01-31 05:45:06
68|2829|0|2020-01-31 05:50:05
68|2873|0|2020-01-31 05:55:03
-- counter should stop here
68|2931|0|2020-01-31 06:00:00
68|2931|0|2020-01-31 06:05:02
68|2931|0|2020-01-31 06:10:05
68|2931|0|2020-01-31 06:15:10
68|2931|0|2020-01-31 06:20:04
68|2931|0|2020-01-31 06:25:03
68|2931|0|2020-01-31 06:30:03
68|2931|0|2020-01-31 06:35:00
68|2931|0|2020-01-31 06:40:00
68|2931|0|2020-01-31 06:45:01
68|2931|0|2020-01-31 06:50:01
68|2931|0|2020-01-31 06:55:01
sqlite> 

OR IDX 67

Code: Select all

sqlite> select * from meter where DeviceRowID = 67 and Date between "2020-01-30 12:00:00" and "2020-01-30 16:00:00";
67|1007|0|2020-01-30 12:00:06
67|1021|0|2020-01-30 12:05:02
67|1033|0|2020-01-30 12:10:08
67|1037|0|2020-01-30 12:15:07
67|1047|0|2020-01-30 12:20:06
67|1063|0|2020-01-30 12:25:08
67|1081|0|2020-01-30 12:30:03
67|1112|0|2020-01-30 12:35:07
67|1159|0|2020-01-30 12:40:03
67|1196|0|2020-01-30 12:45:05
67|1255|0|2020-01-30 12:50:02
67|1293|0|2020-01-30 12:55:08
-- counter should stop here
67|1339|0|2020-01-30 13:00:07
67|1339|0|2020-01-30 13:05:09
67|1339|0|2020-01-30 13:10:07
67|1339|0|2020-01-30 13:15:09
67|1339|0|2020-01-30 13:20:02
67|1339|0|2020-01-30 13:25:01
67|1339|0|2020-01-30 13:30:06
67|1339|0|2020-01-30 13:35:03
67|1339|0|2020-01-30 13:40:09
67|1339|0|2020-01-30 13:45:03
67|1339|0|2020-01-30 13:50:01
67|1339|0|2020-01-30 13:55:04
-- counter should start here adn its OK
67|1441|0|2020-01-30 15:05:00
67|1482|0|2020-01-30 15:10:07
67|1513|0|2020-01-30 15:15:08
67|1542|0|2020-01-30 15:20:07
67|1586|0|2020-01-30 15:25:06
67|1613|0|2020-01-30 15:30:07
67|1635|0|2020-01-30 15:35:08
67|1671|0|2020-01-30 15:40:07
67|1701|0|2020-01-30 15:45:04
67|1729|0|2020-01-30 15:50:09
67|1776|0|2020-01-30 15:55:05
What i Do wrong ?