Welcome to fhem’s documentation!¶
Fhem object¶
- class __init__.Fhem(server, port=7072, use_ssl=False, protocol='telnet', username='', password='', csrf=True, cafile='', loglevel=1)[source]¶
Connects to FHEM via socket communication with optional SSL and password support
- __init__(server, port=7072, use_ssl=False, protocol='telnet', username='', password='', csrf=True, cafile='', loglevel=1)[source]¶
Instantiate connector object.
- Parameters:
server – address of FHEM server
port – telnet/http(s) port of server
use_ssl – boolean for SSL (TLS) [https as protocol sets use_ssl=True]
protocol – ‘telnet’, ‘http’ or ‘https’
username – username for http(s) basicAuth validation
password – (global) telnet or http(s) password
csrf – (http(s)) use csrf token (FHEM 5.8 and newer), default True
cafile – path to public certificate of your root authority, if left empty, https protocol will ignore certificate checks.
loglevel – deprecated, will be removed. Please use standard python logging API with logger ‘Fhem’.
- __weakref__¶
list of weak references to the object (if defined)
- get(name=None, state=None, group=None, room=None, device_type=None, not_name=None, not_state=None, not_group=None, not_room=None, not_device_type=None, case_sensitive=None, filters=None, timeout=0.1, blocking=False, raw_result=None)[source]¶
Get FHEM data of devices, can filter by parameters or custom defined filters. All filters use regular expressions (except full match), so don’t forget escaping. Filters can be used by all other get functions. For more information about filters, see https://FHEM.de/commandref.html#devspec
- Parameters:
name – str or list, device name in FHEM
state – str or list, state in FHEM
group – str or list, filter FHEM groups
room – str or list, filter FHEM room
device_type – str or list, FHEM device type
not_name – not name
not_state – not state
not_group – not group
not_room – not room
not_device_type – not device_type
case_sensitive – bool, use case_sensitivity for all filter functions
filters – dict of filters - key=attribute/internal/reading, value=regex for value, e.g. {“battery”: “ok”}
raw_result – On True: Don’t convert to python types and send full FHEM response
timeout – timeout for reply
blocking – telnet socket mode, default blocking=False
- Returns:
dict of FHEM devices
- get_attributes(*arg, **kwargs)[source]¶
Return attributes of a device, can use filters from get()
- Parameters:
arg – str, Get only specified attribute, return all attributes of device when parameter not given
kwargs – use keyword arguments from
Fhem.get()
function
- Returns:
dict of FHEM devices with attributes
- get_device(device, **kwargs)[source]¶
Get all data from a device
- Parameters:
device – str or list,
kwargs – use keyword arguments from
Fhem.get()
function
- Returns:
dict with data of specific FHEM device
- get_device_attribute(device, *arg, **kwargs)[source]¶
Get attribute(s) of one device
- Parameters:
device – str or list,
arg – str for one attribute, list for special attributes, empty for all attributes
kwargs – use keyword arguments from
Fhem.get()
function
- Returns:
str, int, float when only specific value requested else dict
- get_device_internal(device, *arg, **kwargs)[source]¶
Get internal(s) of one device
- Parameters:
device – str or list,
arg – str for one internal value, list for special internal values, empty for all internal values
kwargs – use keyword arguments from
Fhem.get()
function
- Returns:
str, int, float when only specific value requested else dict
- get_device_reading(device, *arg, **kwargs)[source]¶
Get reading(s) of one device
- Parameters:
device – str or list,
arg – str for one reading, list for special readings, empty for all readings
kwargs – use keyword arguments from
Fhem.get()
andFhem.get_readings()
functions
- Returns:
str, int, float when only specific value requested else dict
- get_device_state(device, **kwargs)[source]¶
Get state of one device
- Parameters:
device – str or list,
kwargs – use keyword arguments from
Fhem.get()
andFhem.get_states()
functions
- Returns:
str, int, float when only specific value requested else dict
- get_internals(*arg, **kwargs)[source]¶
Return internals of a device, can use filters from get()
- Parameters:
arg – str, Get only specified internal, return all internals of device when parameter not given
kwargs – use keyword arguments from
Fhem.get()
function
- Returns:
dict of FHEM devices with internals
- get_readings(*arg, **kwargs)[source]¶
Return readings of a device, can use filters from get().
- Parameters:
arg – str, Get only a specified reading, return all readings of device when parameter not given
value_only – return only value of reading, not timestamp
time_only – return only timestamp of reading
kwargs – use keyword arguments from
Fhem.get()
function
- Returns:
dict of FHEM devices with readings
- get_states(**kwargs)[source]¶
Return only device states, can use filters from get().
- Parameters:
kwargs – Use keyword arguments from
Fhem.get()
function- Returns:
dict of FHEM devices with states
- send_cmd(msg, timeout=10.0)[source]¶
Sends a command to server.
- Parameters:
msg – string with FHEM command, e.g. ‘set lamp on’
timeout – timeout on send (sec).
FhemEventQueue object¶
- class __init__.FhemEventQueue(server, que, port=7072, protocol='telnet', use_ssl=False, username='', password='', csrf=True, cafile='', filterlist=None, timeout=0.1, eventtimeout=60, serverregex=None, loglevel=1, raw_value=False)[source]¶
Creates a thread that listens to FHEM events and dispatches them to a Python queue.
- __init__(server, que, port=7072, protocol='telnet', use_ssl=False, username='', password='', csrf=True, cafile='', filterlist=None, timeout=0.1, eventtimeout=60, serverregex=None, loglevel=1, raw_value=False)[source]¶
Construct an event queue object, FHEM events will be queued into the queue given at initialization.
- Parameters:
server – FHEM server address
que – Python Queue object, receives FHEM events as dictionaries
port – FHEM telnet port
protocol – ‘telnet’, ‘http’ or ‘https’. NOTE: for FhemEventQueue, currently only ‘telnet’ is supported!
use_ssl – boolean for SSL (TLS)
username – http(s) basicAuth username
password – (global) telnet password or http(s) basicAuth password
csrf – (http(s)) use csrf token (FHEM 5.8 and newer), default True (currently not used, since telnet-only)
cafile – path to public certificate of your root authority, if left empty, https protocol will ignore certificate checks.
filterlist – array of filter dictionaires [{“dev”=”lamp1”}, {“dev”=”livingtemp”, “reading”=”temperature”}]. A filter dictionary can contain devstate (type of FHEM device), dev (FHEM device name) and/or reading conditions. The filterlist works on client side.
timeout – internal timeout for socket receive (should be short)
eventtimeout – larger timeout for server keep-alive messages
serverregex – FHEM regex to restrict event messages on server side.
loglevel – deprecated, will be removed. Use standard python logging function for logger ‘FhemEventQueue’, old: 0: no log, 1: errors, 2: info, 3: debug
raw_value – default False. On True, the value of a reading is not parsed for units, and returned as-is.
- __weakref__¶
list of weak references to the object (if defined)