I'm running two scripts which uses "get_gas_values(domoticzurl, domoticzdeviceid_gas)". These scripts worked fine until May 6th 2025.
Now I get the following error:
Code: Select all
/domoticz/scripts $ python3 gasstanden.py
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/gasstanden.py", line 52, in <module>
GasMeterReading = get_gas_values(domoticzurl, domoticzdeviceid_gas)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/domoticz/scripts/gasstanden.py", line 39, in get_gas_values
device_data = Domoticz(url).get_device(device_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/domoticz/scripts/gasstanden.py", line 31, in get_device
data = json.load(self.__execute__(url))
^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/domoticz/scripts/gasstanden.py", line 24, in __execute__
return urllib.request.urlopen(req, timeout=5)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 525, in open
response = meth(req, response)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 634, in http_response
response = self.parent.error(
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 563, in error
return self._call_chain(*args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
Code: Select all
import sys
import json
import urllib.request, urllib.error, urllib.parse
import re
import time
import datetime
import http.client, urllib.request, urllib.parse, urllib.error
def open_port():
pass
def close_port():
pass
class Domoticz():
def __init__(self, url):
self.baseurl = url
def __execute__(self, url):
req = urllib.request.Request(url)
return urllib.request.urlopen(req, timeout=5)
def get_device(self, xid):
"""
Get the Domoticz device information.
"""
url = "%s/json.htm?type=devices&rid=%s" % (self.baseurl, xid)
data = json.load(self.__execute__(url))
return data
def get_gas_values(url, device_id):
"""
Get gasmeter reading.
"""
device_data = Domoticz(url).get_device(device_id)
data = device_data['result'][0]['Data']
ex = re.compile('^([0-9\.]+)$')
groups = ex.match(data).group
gasstand = float(groups(1)) #/ 1000
return gasstand
# example usage
domoticzurl = "http://192.168.2.44:8084"
domoticzdeviceid_gas = 10
GasMeterReading = get_gas_values(domoticzurl, domoticzdeviceid_gas)
print ("Gasmeterstand:\t\t\t\t"+str(GasMeterReading).replace('.',',')+"m3")
# creeer een bestand met de waarde / create a file with the readings
name = '/home/pi/domoticz/scripts/gasverbruik.csv' # Naam tekstbestand / Name of text file
now = datetime.datetime.now()
try:
file = open(name,'a') # create file / creeer bestand
file.write(str(now.strftime("%Y-%m-%d %H:%M")) + ';' + str(GasMeterReading).replace('.', ',') +'\n')
except: # something went wrong / in het vorige blok is iets niet goed gegaan (error)
print('Something went wrong!')