Page 1 of 1
Manually enter energy data
Posted: Sunday 12 February 2023 16:18
by phenix56
Hi all,
I have a non-smart meter on a remote location which I manually read out every few weeks. Like the title says, I would like to manually enter data into a virtual energy device so I can roughly track how much energy I am using.
I understand this won't be precise, but all I really care about is the difference between the current reading and the previous one. A nice graph would also be great!
I also already have data from the last few months in a Excel spreadsheet, if possible I want to enter it in the sensor to already have some data to work with.
I looked for the function in multiple energy-like sensors, but could not find a manual option. Does this option even exist, and if not, how else can I achieve my goals? Would it be possible to use it in a script with the API?-
Re: Manually enter energy data
Posted: Sunday 12 February 2023 17:53
by willemd
I am not aware of domoticz having any possibility for extensive manual input, so if I were you, I would write a very small python program to either read a csv file or ask for manual input data and then store that onto a domoticz device.
The way to get data onto a device, or into the domoticz dbase, is via json calls (not via sql statements). From the python program you can easily make and activate those json calls and as result get your data onto a device.
Have a look at this page:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
So all you need to do is choose your device, set it up, and know a bit of python.
Below are some bits and pieces out of a larger python program (this extract was not tested) to show you how to update a text device.
It imports the required modules
It sets some global variables
It defines the update function
It calls the update function with a test
Code: Select all
import requests
import json
import urllib.parse
## Domoticz server
domoticzIP="127.0.0.1" # internal IP address of the Domoticz server. This assumes domoticz is run on the same system as this program (if not, use the external IP address).
domoticzPort="8080" # Domoticz port
# all communication with domoticz devices/database is with JSON calls (like domoticz itself is doing)
baseJSON="http://"+domoticzIP+":"+domoticzPort+"/json.htm?" # the base string for any JSON call.
def setTextDevice(textIDX,displayText):
# update the value of a text device and adds an entry to the device log file
try:
if len(displayText)<=200:
urlText=urllib.parse.quote(displayText)
apiCall="type=command¶m=udevice&idx="+str(textIDX)+"&nvalue=0&svalue="+urlText
response=requests.get(baseJSON+apiCall)
responseResult=str(response.json()["status"])
if responseResult=="ERR":
raise Exception
else:
responseResult=True
else:
print("ERROR: displayText too long (max 200 characters).")
raise Exception
except:
print("ERROR: failed to update text device with IDX ",textIDX)
print("Response was : ",response.json())
responseResult=False
return responseResult
setTextDevice(textdeviceIDX,"this is a test") ## replace textdeviceIDX by the IDX number of your device
Re: Manually enter energy data
Posted: Sunday 12 February 2023 22:46
by FireWizard
Hi @phenix56,
As I know you have MQTT and Node-Red running, you could also use these tools.
You can simple use an Inject node and publish the value to a virtual sensor of your choice.
It is even possible to read directly your Excel sheet.
See:
https://flows.nodered.org/node/node-red ... adsheet-in
The biggest issue is how to send a date/time (which is in the past) to the database.
It is possible to send it directly to a sqlite3 database from Node Red, but you have to stop Domoticz in that case. This is probably not what you want.
So any other idea?
Regards
Re: Manually enter energy data
Posted: Sunday 12 February 2023 23:51
by waltervl
I have the same situation and I use a simple excel sheet to create an json.html api link that puts the value into Domoticz.
Re: Manually enter energy data
Posted: Wednesday 11 September 2024 10:25
by Filip
Hi, I assume that it is not possible to give also the date as input for the manual entered data points...
If we import data from an XLS or JSON, I would like that the data point is set in the past on the domoticz device to be able to input historical data... Is this possible?
Re: Manually enter energy data
Posted: Wednesday 11 September 2024 10:30
by waltervl
It is possible, see
https://www.domoticz.com/wiki/Domoticz_ ... n_counters
But I only could get this working on a managed counter, not on a normal counter.