Re: No data from sbfspot to Domoticz
Posted: Friday 23 October 2020 20:58
A great!
Was already screenshotting my code
Was already screenshotting my code
Open source Home Automation System
https://forum.domoticz.com/
I just tested your script and it worksbontwoody wrote: ↑Friday 22 November 2019 18:04 Virtualdevice.png
OK, so I havent been able to get the inbuilt import function to work properly but I have managed to use a virtual sensor and a python script to do what is required. There are a couple of glitches with the data in the image but Im very close. Im still fiddling with it to get the best results but Im happy to share how I did it with you if you want. Basically I an querying the SBFspot database directly and then inserting the values into the Domoticz database through the python code which is run every 5 minutes via crontab.
Code: Select all
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sqlite3 import connect
from datetime import datetime
## Obtenir les 20 dernières lignes du fichier du jour pour les dernières lecture de la production solaire.
## Obtenir plus de 1 en cas de mauvaise connexion Bluetooth
conn = connect('/home/pi/smadata/SBFspot.db')
curs = conn.cursor()
curs.execute("select Timestamp, Power, TotalYield from vwDayData ORDER BY Timestamp DESC LIMIT 20")
rows1=curs.fetchall()
print(rows1)
curs.close
conn.close
conn = connect('/home/pi/domoticz/domoticz.db')
curs = conn.cursor()
## Obtenir la dernière lecture ajoutée à domoticz
curs.execute("select Date from Meter ORDER BY Date DESC LIMIT 1")
rows2=curs.fetchall()
if len(rows2)==0: #check there is some data in Meter table
now=datetime.now()
DT=now.strftime("%d/%m/%Y %H:%M:%S")
else:
## Obtenir le dernier horodatage ajouté à domoticz
print(rows2)
DT =rows2[0][0]
a=0 ## variable pour l'indicateur d'ajout de la date - 0=ajouter, 1=ne pas ajouter
for n in range (19) :
if DT !=rows1[n][0] and a== 0: ## append data
print("append", DT, rows1[n][0],a, rows1[n][1], rows1[n][2])
val=rows1[n][1]
tot =rows1[n][2]
params = (497,val*10,tot,rows1[n][0])
curs.execute("INSERT INTO Meter(DeviceRowID,Usage,Value,Date) VALUES (?,?, ?,?)", params)
conn.commit()
elif DT==row1[n][0] and a==0 : ## set 'dont append'flag
print("set flag", DT, rows1[n][0],a)
a=1
else :
print ("Ne rien faire", DT, row1[n][0],a)
curs.close()
conn.close()
Code: Select all
pi@raspberrypi-185:~/domoticz/scripts/python $ python SBFSpot_db_2.py
Code: Select all
[(u'2022-08-12 17:00:00', 1464, 21718773), (u'2022-08-12 16:55:00', 1464, 21718651), (u'2022-08-12 16:50:00', 1500, 21718529), (u'2022-08-12 16:45:00', 1512, 21718404), (u'2022-08-12 16:40:00', 1524, 21718278), (u'2022-08-12 16:35:00', 1524, 21718151), (u'2022-08-12 16:30:00', 1548, 21718024), (u'2022-08-12 16:25:00', 1560, 21717895), (u'2022-08-12 16:20:00', 1572, 21717765), (u'2022-08-12 16:15:00', 1584, 21717634), (u'2022-08-12 16:10:00', 1596, 21717502), (u'2022-08-12 16:05:00', 1608, 21717369), (u'2022-08-12 16:00:00', 1596, 21717235), (u'2022-08-12 15:55:00', 1620, 21717102), (u'2022-08-12 15:50:00', 1596, 21716967), (u'2022-08-12 15:45:00', 1608, 21716834), (u'2022-08-12 15:40:00', 1488, 21716700), (u'2022-08-12 15:35:00', 1620, 21716576), (u'2022-08-12 15:30:00', 1632, 21716441), (u'2022-08-12 15:25:00', 1644, 21716305)]
[(u'2022-08-13 08:15:03',)]
('append', u'2022-08-13 08:15:03', u'2022-08-12 17:00:00', 0, 1464, 21718773)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:55:00', 0, 1464, 21718651)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:50:00', 0, 1500, 21718529)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:45:00', 0, 1512, 21718404)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:40:00', 0, 1524, 21718278)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:35:00', 0, 1524, 21718151)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:30:00', 0, 1548, 21718024)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:25:00', 0, 1560, 21717895)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:20:00', 0, 1572, 21717765)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:15:00', 0, 1584, 21717634)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:10:00', 0, 1596, 21717502)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:05:00', 0, 1608, 21717369)
('append', u'2022-08-13 08:15:03', u'2022-08-12 16:00:00', 0, 1596, 21717235)
('append', u'2022-08-13 08:15:03', u'2022-08-12 15:55:00', 0, 1620, 21717102)
('append', u'2022-08-13 08:15:03', u'2022-08-12 15:50:00', 0, 1596, 21716967)
('append', u'2022-08-13 08:15:03', u'2022-08-12 15:45:00', 0, 1608, 21716834)
('append', u'2022-08-13 08:15:03', u'2022-08-12 15:40:00', 0, 1488, 21716700)
('append', u'2022-08-13 08:15:03', u'2022-08-12 15:35:00', 0, 1620, 21716576)
('append', u'2022-08-13 08:15:03', u'2022-08-12 15:30:00', 0, 1632, 21716441)
Code: Select all
sudo /etc/init.d/domoticz.sh stop
cd domoticz
sqlite3 domoticz.db
DELETE from Meter where DeviceRowId = 497;
DELETE from Meter_Calendar where DeviceRowId = 497;
.quit
sudo /etc/init.d/domoticz.sh start