domschl / python-fhem Goto Github PK
View Code? Open in Web Editor NEWPython FHEM (home automation server) API
License: MIT License
Python FHEM (home automation server) API
License: MIT License
Hi, I'm trying to filter on client slide one device and one reading like this:
fhemev = fhem.FhemEventQueue("192.168.0.2",que, filterlist=[{'device':'WeatherAlarms', "reading":"code"}])
Although I see the requested reading, I'm getting the following error:
{'timestamp': datetime.datetime(2020, 3, 24, 14, 52, 13), 'devicetype': 'CustomReadings', 'device': 'WeatherAlarms', 'reading': 'code', 'value': 'Жълт', 'unit': ''}
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/fhem/init.py", line 800, in _event_worker_thread
if vl[0][-1] == ':':
IndexError: string index out of range
The script doesn't break but upon second event, I don't receive any reading anymore. Also I noticed that if reading is string containing few words (e.g. "high temperature"), it gets broken in words and only first one (eg "high") is passed to the returned dictionary and the second is passed into "units". I guess you have done it for your particular case, but it breaks up in the case which I've mentioned.
Hi,
is there a reason why timeout is not used in following line:
python-fhem/fhem/fhem/__init__.py
Line 261 in 4faea79
Unfortunately I have sometimes connections errors and this line causes an infinite wait.
Hi,
first of all, thank you for the python module for fhem.
I like to use it, but have issues with my setup.
I have two separate fhem installations (fhem1 and fhem2) and wanted to query all of my pca301 sockets out of both.
I were creating two connections to fhem1 and fhem2:
fh1 = fhem.Fhem("fhem1", port = "8084", protocol = "https", use_ssl = True, username = "test1", password = 'XYZ', csrf=True)
fh2 = fhem.Fhem("fhem2", port = "8084", protocol = "https", use_ssl = True, username = "test1", password = 'XYZ', csrf=True)
fh1.connected()
fh2.connected()
>>> fh1.connected()
False
>>> fh1.connect()
>>> fh1.connected()
True
>>> fh1.get_readings(name="PCA301_WZ_TV_AVR1")
{'PCA301_WZ_TV_AVR1': {'IODev': {'Value': 'Pwrjee', 'Time': datetime.datetime(2023, 8, 8, 22, 49, 13)}, 'consumption': {'Value': 2.2, 'Time': datetime.datetime(2023, 8, 9, 18, 22, 58)}, 'consumptionTotal': {'Value': 1385.98999999927, 'Time': datetime.datetime(2023, 8, 9, 18, 22, 58)}, 'power': {'Value': 16.7, 'Time': datetime.datetime(2023, 8, 9, 18, 28, 12)}, 'state': {'Value': 'on', 'Time': datetime.datetime(2023, 8, 9, 0, 45, 17)}, 'waitforACK': {'Value': 'ACK:on', 'Time': datetime.datetime(2023, 8, 5, 22, 1, 54)}}}
>>>
>>> fh2.connected()
False
>>> fh2.connect()
>>> fh2.connected()
True
>>> fh2.get_readings(name="PCA301_Buero_MiniPC")
{'PCA301_Buero_MiniPC': {'IODev': {'Value': 'Pwrjee', 'Time': datetime.datetime(2023, 8, 8, 22, 5, 58)}, 'consumption': {'Value': 1.57, 'Time': datetime.datetime(2023, 8, 9, 18, 17, 50)}, 'consumptionTotal': {'Value': 5143.26000000688, 'Time': datetime.datetime(2023, 8, 9, 18, 17, 50)}, 'power': {'Value': 15.8, 'Time': datetime.datetime(2023, 8, 9, 18, 30, 21)}, 'state': {'Value': 'on', 'Time': datetime.datetime(2023, 3, 20, 15, 32, 54)}}}
>>> fh1.get_readings(name="PCA301_WZ_TV_AVR1")
Failed to send msg, len=32, HTTP Error 401: Authorization Required
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/scripts/power/powerenv/lib/python3.10/site-packages/fhem/__init__.py", line 597, in get_readings
return self._response_filter(response, arg, 'Readings', value_only=value_only, time_only=time_only)
File "/scripts/power/powerenv/lib/python3.10/site-packages/fhem/__init__.py", line 460, in _response_filter
for r in response if 'totalResultsReturned' not in response else response['Results']:
TypeError: argument of type 'NoneType' is not iterable
>>> fh1.connected()
False
>>>
As you can see, both can connect and query a socket from fhem1 (PCA301_WZ_TV_AVR1) or fhem2 (PCA301_Buero_MiniPC) successful.
But after I have connected to the second server fhem2, I will lose my connection to the first server fhem1 and cannot query again the socket PCA301_WZ_TV_AVR1 and get the error:
for r in response if 'totalResultsReturned' not in response else response['Results']: TypeError: argument of type 'NoneType' is not iterable
All this happend within 1 minute, so it is no timeout or something.
I also have tried it reverse, so started first with fhem2 and then fhem1 and then will lose connection to fhem2, so the first server, I have made the connection.
Can you please check why this is happening and fix the issue?
Regards,
Jochen
Hi,
Using the following code:
date_1 = str(fh.get_device_reading("myWeather", "fc1_date"))
print ("Date:"+date_1)
I always get a json return with "u", and the datetime not in '':
Date:{u'Value': u'25 Dec 2018', u'Time': datetime.datetime(2018, 12, 25, 16, 46, 8)}
I used str() to convert the dict return as a string.
Thanks
Some parts of the API do not support telnet's blocking=False parameter, and blocking=True cut s all replies to 32000 max. Operation that rely on larger requests (wildcards) fail.
Fix:
allow usage of blocking=False in APIs (e.g. get_readings())
increase default from 32000 for blocking.
deprecate telnet.
Hi,
I am using the Fhem EventQueue to catch all events in python. Sometimes (after hours and thousands of successfully tracked events) I get the following exception and my program stops:
Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.7/dist-packages/fhem/__init__.py", line 765, in _event_worker_thread dt = datetime.datetime(int(dd[0]), int(dd[1]), ValueError: invalid literal for int() with base 10: 'Das'
I think it should be easy to fix by some try/except… ?
I am wondering that I am the first who is experiencing this problem…
Best regards
party-pansen
Hi,
is it possible to get attribut settings like reading a FHEM reading?
AttrVal("<device","verbose",)
ReadingsVal("","",)
For example I would like to get the verbose level of a device, to switch on more or less messages inside my Phython script.
Best regards
Christian
Hi,
If use f.ex.
temp_1_wday = fh.get_device_reading("myWeather", "fc1_day_of_week")
temp_1_wday = temp_1_wday['day_of_week']
temp_1_wday = temp_1_wday['Value']
or
temp_1_code = fh.get_device_reading("myWeather", "fc1_code")
temp_1_code = temp_1_code['fc1_code']
temp_1_code = temp_1_code['Value']
to get a specific reading.
Unfortunately sometimes (not always, and also not everytime the same device) i get all readings.
Not sure if it's FHEM related or python-fhem:
DEBUG:Fhem:Connected, sending...
INFO:Fhem:Sent msg, len=25
ERROR:Fhem:Failed to decode json, exception raised. {
"Arg":"NAME~myWeather",
"Results": [
{
"Name":"myWeather",
"PossibleSets":"update",
"PossibleAttrs":"alias comment:textField-long eventMap:textField-long group room suppressReading userReadings:textField-long verbose:0,1,2,3,4,5 disable event-aggregator event-min-interval event-on-change-reading event-on-update-reading oldreadings stateFormat:textField-long timestamp-on-change-reading DbLogExclude DbLogInclude SplunkLogExclude SplunkLogInclude SyslogLogExclude SyslogLogInclude alexaName alexaRoom cmdIcon devStateIcon devStateStyle fp_Keller fp_Keller_T fp_RDC fp_RDC_T fp_Upstairs fp_Upstairs_T genericDeviceType:security,ignore,switch,outlet,light,blind,thermometer,thermostat,contact,garage,window,lock homebridgeMapping:textField-long icon sortby webCmd webCmdLabel:textField-long widgetOverride userattr",
"Internals": {
"API": "YahooWeatherAPI",
"APIOPTIONS": "transport:https,cachemaxage:600",
"DEF": "979629",
"INTERVAL": "3600",
"LANG": "en",
"LOCATION": "979629",
"NAME": "myWeather",
"NOTIFYDEV": "global",
"NR": "358",
"NTFY_ORDER": "50-myWeather",
"STATE": "T: 1 H: 77 W: 2 P: 995",
"TYPE": "Weather",
"UNITS": "c"
},
"Readings": {
"city": { "Value":"Howald", "Time":"2018-12-26 13:46:36" },
"code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"country": { "Value":"Luxembourg", "Time":"2018-12-26 13:46:36" },
"current_date_time": { "Value":"Wed, 26 Dec 2018 01:00 PM CET", "Time":"2018-12-26 13:46:36" },
"day_of_week": { "Value":"Wed", "Time":"2018-12-26 13:46:36" },
"description": { "Value":"Yahoo! Weather for Howald, Luxemburg, LU", "Time":"2018-12-26 13:46:36" },
"fc10_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc10_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc10_date": { "Value":"04 Jan 2019", "Time":"2018-12-26 13:46:36" },
"fc10_day_of_week": { "Value":"Fri", "Time":"2018-12-26 13:46:36" },
"fc10_high_c": { "Value":"0", "Time":"2018-12-26 13:46:36" },
"fc10_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc10_low_c": { "Value":"-2", "Time":"2018-12-26 13:46:36" },
"fc1_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc1_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc1_date": { "Value":"26 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc1_day_of_week": { "Value":"Wed", "Time":"2018-12-26 13:46:36" },
"fc1_high_c": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"fc1_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc1_low_c": { "Value":"-3", "Time":"2018-12-26 13:46:36" },
"fc2_code": { "Value":"28", "Time":"2018-12-26 1 Unterminated string starting at: line 45 column 42 (char 2883)
temp_1_code:{}
Traceback (most recent call last):
File "own.py", line 75, in <module>
temp_1_code = temp_1_code['fc1_code']
KeyError: 'fc1_code'
or
DEBUG:Fhem:Sending: jsonlist2 NAME~myWeather
DEBUG:Fhem:Connected, sending...
INFO:Fhem:Sent msg, len=25
ERROR:Fhem:Failed to decode json, exception raised. {
"Arg":"NAME~myWeather",
"Results": [
{
"Name":"myWeather",
"PossibleSets":"update",
"PossibleAttrs":"alias comment:textField-long eventMap:textField-long group room suppressReading userReadings:textField-long verbose:0,1,2,3,4,5 disable event-aggregator event-min-interval event-on-change-reading event-on-update-reading oldreadings stateFormat:textField-long timestamp-on-change-reading DbLogExclude DbLogInclude SplunkLogExclude SplunkLogInclude SyslogLogExclude SyslogLogInclude alexaName alexaRoom cmdIcon devStateIcon devStateStyle fp_Keller fp_Keller_T fp_RDC fp_RDC_T fp_Upstairs fp_Upstairs_T genericDeviceType:security,ignore,switch,outlet,light,blind,thermometer,thermostat,contact,garage,window,lock homebridgeMapping:textField-long icon sortby webCmd webCmdLabel:textField-long widgetOverride userattr",
"Internals": {
"API": "YahooWeatherAPI",
"APIOPTIONS": "transport:https,cachemaxage:600",
"DEF": "979629",
"INTERVAL": "3600",
"LANG": "en",
"LOCATION": "979629",
"NAME": "myWeather",
"NOTIFYDEV": "global",
"NR": "358",
"NTFY_ORDER": "50-myWeather",
"STATE": "T: 1 H: 77 W: 2 P: 995",
"TYPE": "Weather",
"UNITS": "c"
},
"Readings": {
"city": { "Value":"Howald", "Time":"2018-12-26 13:46:36" },
"code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"country": { "Value":"Luxembourg", "Time":"2018-12-26 13:46:36" },
"current_date_time": { "Value":"Wed, 26 Dec 2018 01:00 PM CET", "Time":"2018-12-26 13:46:36" },
"day_of_week": { "Value":"Wed", "Time":"2018-12-26 13:46:36" },
"description": { "Value":"Yahoo! Weather for Howald, Luxemburg, LU", "Time":"2018-12-26 13:46:36" },
"fc10_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc10_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc10_date": { "Value":"04 Jan 2019", "Time":"2018-12-26 13:46:36" },
"fc10_day_of_week": { "Value":"Fri", "Time":"2018-12-26 13:46:36" },
"fc10_high_c": { "Value":"0", "Time":"2018-12-26 13:46:36" },
"fc10_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc10_low_c": { "Value":"-2", "Time":"2018-12-26 13:46:36" },
"fc1_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc1_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc1_date": { "Value":"26 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc1_day_of_week": { "Value":"Wed", "Time":"2018-12-26 13:46:36" },
"fc1_high_c": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"fc1_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc1_low_c": { "Value":"-3", "Time":"2018-12-26 13:46:36" },
"fc2_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc2_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc2_date": { "Value":"27 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc2_day_of_week": { "Value":"Thu", "Time":"2018-12-26 13:46:36" },
"fc2_high_c": { "Value":"2", "Time":"2018-12-26 13:46:36" },
"fc2_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc2_low_c": { "Value":"-1", "Time":"2018-12-26 13:46:36" },
"fc3_code": { "Value":"30", "Time":"2018-12-26 13:46:36" },
"fc3_condition": { "Value":"partly cloudy", "Time":"2018-12-26 13:46:36" },
"fc3_date": { "Value":"28 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc3_day_of_week": { "Value":"Fri", "Time":"2018-12-26 13:46:36" },
"fc3_high_c": { "Value":"2", "Time":"2018-12-26 13:46:36" },
"fc3_icon": { "Value":"partly_cloudy", "Time":"2018-12-26 13:46:36" },
"fc3_low_c": { "Value":"-1", "Time":"2018-12-26 13:46:36" },
"fc4_code": { "Value":"26", "Time":"2018-12-26 13:46:36" },
"fc4_condition": { "Value":"cloudy", "Time":"2018-12-26 13:46:36" },
"fc4_date": { "Value":"29 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc4_day_of_week": { "Value":"Sat", "Time":"2018-12-26 13:46:36" },
"fc4_high_c": { "Value":"2", "Time":"2018-12-26 13:46:36" },
"fc4_icon": { "Value":"cloudy", "Time":"2018-12-26 13:46:36" },
"fc4_low_c": { "Value":"0", "Time":"2018-12-26 13:46:36" },
"fc5_code": { "Value":"26", "Time":"2018-12-26 13:46:36" },
"fc5_condition": { "Value":"cloudy", "Time":"2018-12-26 13:46:36" },
"fc5_date": { "Value":"30 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc5_day_of_week": { "Value":"Sun", "Time":"2018-12-26 13:46:36" },
"fc5_high_c": { "Value":"5", "Time":"2018-12-26 13:46:36" },
"fc5_icon": { "Value":"cloudy", "Time":"2018-12-26 13:46:36" },
"fc5_low_c": { "Value":"2", "Time":"2018-12-26 13:46:36" },
"fc6_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc6_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc6_date": { "Value":"31 Dec 2018", "Time":"2018-12-26 13:46:36" },
"fc6_day_of_week": { "Value":"Mon", "Time":"2018-12-26 13:46:36" },
"fc6_high_c": { "Value":"5", "Time":"2018-12-26 13:46:36" },
"fc6_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc6_low_c": { "Value":"2", "Time":"2018-12-26 13:46:36" },
"fc7_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc7_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc7_date": { "Value":"01 Jan 2019", "Time":"2018-12-26 13:46:36" },
"fc7_day_of_week": { "Value":"Tue", "Time":"2018-12-26 13:46:36" },
"fc7_high_c": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"fc7_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc7_low_c": { "Value":"-1", "Time":"2018-12-26 13:46:36" },
"fc8_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc8_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc8_date": { "Value":"02 Jan 2019", "Time":"2018-12-26 13:46:36" },
"fc8_day_of_week": { "Value":"Wed", "Time":"2018-12-26 13:46:36" },
"fc8_high_c": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"fc8_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc8_low_c": { "Value":"-1", "Time":"2018-12-26 13:46:36" },
"fc9_code": { "Value":"28", "Time":"2018-12-26 13:46:36" },
"fc9_condition": { "Value":"mostly cloudy", "Time":"2018-12-26 13:46:36" },
"fc9_date": { "Value":"03 Jan 2019", "Time":"2018-12-26 13:46:36" },
"fc9_day_of_week": { "Value":"Thu", "Time":"2018-12-26 13:46:36" },
"fc9_high_c": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"fc9_icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"fc9_low_c": { "Value":"-2", "Time":"2018-12-26 13:46:36" },
"humidity": { "Value":"77", "Time":"2018-12-26 13:46:36" },
"icon": { "Value":"mostlycloudy", "Time":"2018-12-26 13:46:36" },
"isConverted": { "Value":"0", "Time":"2018-12-26 13:46:36" },
"lastError": { "Value":"", "Time":"2018-12-26 13:46:36" },
"lat": { "Value":"49.584999", "Time":"2018-12-26 13:46:36" },
"long": { "Value":"6.14139", "Time":"2018-12-26 13:46:36" },
"pressure": { "Value":"995", "Time":"2018-12-26 13:46:36" },
"pressure_trend": { "Value":"0", "Time":"2018-12-26 13:46:36" },
"pressure_trend_sym": { "Value":"=", "Time":"2018-12-26 13:46:36" },
"pressure_trend_txt": { "Value":"steady", "Time":"2018-12-26 13:46:36" },
"pubDate": { "Value":"Wed, 26 Dec 2018 01:00 PM CET", "Time":"2018-12-26 13:46:36" },
"pubDateComment": { "Value":"okay", "Time":"2018-12-26 13:46:36" },
"pubDateRemote": { "Value":"Wed, 26 Dec 2018 01:00 PM CET", "Time":"2018-12-26 13:46:36" },
"pubDateTs": { "Value":"1545825600", "Time":"2018-12-26 13:46:36" },
"region": { "Value":" Luxemburg", "Time":"2018-12-26 13:46:36" },
"state": { "Value":"T: 1 H: 77 W: 2 P: 995", "Time":"2018-12-26 13:46:36" },
"temp_c": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"temperature": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"validity": { "Value":"up-to-date", "Time":"2018-12-26 13:46:36" },
"visibility": { "Value":"16", "Time":"2018-12-26 13:46:36" },
"wind": { "Value":"2", "Time":"2018-12-26 13:46:36" },
"wind_chill": { "Value":"1", "Time":"2018-12-26 13:46:36" },
"wind_condition": { "Value":"Wind: SE 2 km/h", "Time":"2018-12-26 13:46:36" },
"wind_direction": { "Value":"135", "Time":"2018-12-26 13:46:36" },
"wind_speed": { "Value":"2", "Time":"2018-12-26 13:46:36" Expecting object: line 125 column 63 (char 8687)
temp_1_wday:{}
Traceback (most recent call last):
File "own.py", line 68, in <module>
temp_1_wday = temp_1_wday['day_of_week']
KeyError: 'day_of_week'
DEBUG:Fhem:Connected, sending...
INFO:Fhem:Sent msg, len=25
ERROR:Fhem:Failed to decode json, exception raised. {
"Arg":"NAME~myWeather",
"Results": [
{
"Name":"myWeather",
"PossibleSets":"update",
"PossibleAttrs":"alias comment:textField-long eventMap:textField-long group room suppressReading userReadings:textField-long verbose:0,1,2,3,4,5 disable event-aggregator event-min-interval event-on-change-reading event-on-update-reading oldreadings stateFormat:textField-long timestamp-on-change-reading DbLogExclude DbLogInclude SplunkLogExclude SplunkLogInclude SyslogLogExclude SyslogLogInclude alexaName alexaRoom cmdIcon devStateIcon devStateStyle fp_Keller fp_Keller_T fp_RDC fp_RDC_T fp_Upstairs fp_Upstairs_T genericDeviceType:security,ignore,switch,outlet,light,blind,thermometer,thermostat,contact,garage,window,lock homebridgeMapping:textField-long icon sortby webCmd webCmdLabel:textField-long widgetOverride userattr",
"Internals": {
"API": "YahooWeatherAPI",
"APIOPTIONS": "transport:https,cachemaxage:600",
"DEF": "979629",
"INTERVAL": "3600",
"LANG": "en",
"LOCATION": "979629",
"NAME": "myWeather",
"NOTIFYDEV": "global",
"NR": "358",
"NTFY_ORDER": "50-myWeather",
"STATE": "T: -3 H: 93 W: 5 P: 994",
"TYPE": "Weather",
"UNITS": "c"
},
"Readings": {
"city": { "Value":"Howald", "Time":"2018-12-26 20:46:45" },
"code": { "Value":"29", "Time":"2018-12-26 20:46:45" },
"condition": { "Value":"partly cloudy", "Time":"20 Unterminated string starting at: line 26 column 54 (char 1445)
Traceback (most recent call last):
File "own.py", line 104, in <module>
temp_2_low = temp_2_low['Value']
KeyError: 'Value'
If server answers too slowly:
Exception in non-blocking. Error: [Errno 11] Resource temporarily unavailable
See: Fhem forum report
This condition is not an error, hence no message should be displayed.
Hello,
I use in front of FHEM a reverse proxy with https and SNI on port 443.
When I try to send a command I get the error ERROR:Fhem:Failed to send msg, len=24, HTTP Error 400: Bad request
.
I found out that urllib
triggers the error when the port is included in the URL.
With the following if
at https://github.com/domschl/python-fhem/blob/master/fhem/fhem/__init__.py#L97 the connection works:
self.baseurlauth = "{}://{}:{}/".format(tmp_protocol, server, port)
changed to:
if port == 443:
self.baseurlauth = "{}://{}/".format(tmp_protocol, server)
else:
self.baseurlauth = "{}://{}:{}/".format(tmp_protocol, server, port)
Probably there is a better solution, but with my Python knowledge it works ;-)
The Traceback of urllib:
>>> urlopen("https://fhem.<domain>:443/fhem?XHR=1&cmd=set%20lamp%20pct%20100")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.10/urllib/request.py", line 525, in open
response = meth(req, response)
File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
response = self.parent.error(
File "/usr/lib/python3.10/urllib/request.py", line 563, in error
return self._call_chain(*args)
File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad request
>>> urlopen("https://fhem.<domain>/fhem?XHR=1&cmd=set%20lamp%20pct%20100")
<http.client.HTTPResponse object at 0x7f14f7e95e40>
Edit*
Another idea came to my mind and it seems to be (also) related to this.
As ReverseProxy I use HAproxy with the following ACL:
acl fhem_host hdr(host) -i fhem.<domain>
use_backend fhem if fhem_host
So I changed the ACL to this and it works without the if
-clause:
acl fhem_host hdr(host) -i fhem.<domain> fhem.<domain>:443
use_backend fhem if fhem_host
Maybe someone helps this.
As described by TK67 in Fhem forum, get_device_reading
returns inconsistent information, if a device has two readings, with one reading-name being a longer version of another reading, e.g. if readings myReading
and myReading2
exist, then asking for myReading2
would wrongly also return results for myReading
.
I use a Windows PC and a Raspberry Pi with an FHEM installation, but I don´t get any events from FHEM on my Windows machine.
I have configured the telnet client on my FHEM instance in the following way (39
is the Windows PC, 24
is the Raspberry Pi):
attr telnetPort allowfrom 127.0.0.1|192.168.178.39
And I use the following code on both systems (I only change the IP address):
import fhem
import queue
import logging
logging.basicConfig()
fh = fhem.Fhem("192.168.178.24")
que = queue.Queue()
fe = fhem.FhemEventQueue("192.168.178.24", que)
if(__name__ == "__main__"):
while(True):
item = que.get()
print('Finished {item}')
print(item)
The code runs without an error on my Raspberry Pi, but the application throws the following error on Windows:
ERROR:Fhem:Failed to connect to 192.168.178.24:7072
WARNING:FhemEventQueue:EventQueueThread: Fhem is not connected!
What´s wrong here?
Hi there,
thank you for your awesome work here! I just have one tiny problem with your module:
Importing your module breaks the logging setup of the importing module because you're calling basicConfig (which cannot be used twice) on import here
python-fhem/fhem/fhem/__init__.py
Line 36 in f466959
I think it would be good practice to remove that call entirely so that the user of the module can decide how he want's to setup his logger. If you insist on setting the logLevel I would suggest using logger.setLevel
which only modifies your own logger.
An alternative would be calling basicConfig in your class initialization, in case the user hasn't done it so far. This ensures that a logger is properly setup but doesn't overwrite anything if the user has already done his own logging setup (which usually happens after importing modules but before initializing any classes).
But as I said, I would leave the choices of logging setup to the user. Everyone has different loggging needs ;)
Hello,
when attr global mseclog 1
is activated, the queue objects are not processed properly:
DEBUG:FhemEventQueue:EventQueue: invalid date format in date=2022-11-09 time=09:00:53.653, event 2022-11-09 09:00:53.653 DOIF DOIF_SonneUndSchatten Richtung.SuedOst.brightness: 1930 ignored
Is there a workaround?
Thx!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.