Skip to main content

Python API for FHEM home automation server

Project description

PyPI version Codacy Badge

python-fhem

Python FHEM (home automation server) API

Simple API to connect to the FHEM home automation server via sockets or http(s), using the telnet or web port on FHEM with optional SSL (TLS) and password or basicAuth support.

Installation:

PIP installation (PyPI):

See the PyPI page for additional information about the package.

pip install [-U] fhem

From source

In python-fhem/fhem:

pip install [-U] .

or, as developer installation, allowing inplace editing:

pip install [-U] -e .

History

  • 0.5.5 (2018-08-26): Documentation cleanup, automatic documentation with sphinx.
  • 0.5.3 (2018-08-26): Fix syntax in exception handler
  • 0.5.2 (2018-06-09): Fix for crash on invalid csrf-return
  • 0.5.1 (2018-01-29): Removed call to logging.basicConfig(), since it was unnecessary and causes breakage if other modules use this too. (heilerich #8)
  • 0.5: API cleanup (breaking change!). Removed deprecated functions: sendCmd, sendRcvCmd, getDevState, getDevReading (replaced with PEP8 conform names, s.b.). Renamed parameter ssl= -> use_ssl=
  • 0.4.4: Merged python logger support (ChuckMoe, #6)
  • 0.4.3: Merged API extensions for getting time of last reading change (logi85, #5)
  • 0.4.2: deprecation error message fixed (Ivermue, #4)
  • 0.4.0: csrf token support (FHEM 5.8 requirement)

Usage

Set and get transactions

Default telnet connection without password and without encryption:

import fhem

# Connect via default protocol telnet, default port 7072:
fh = fhem.Fhem("myserver.home.org")
# Send a command to FHEM (this automatically connects() in case of telnet)
fh.send_cmd("set lamp on")
# Get a specific reading from a device
temp = fh.get_dev_reading("LivingThermometer", "temperature")

To connect via telnet with SSL and password:

fh = fhem.Fhem("myserver.home.org", port=7073, use_ssl=True, password='mysecret')
fh.connect()
if fh.connected():
    # Do things

To connect via https with SSL and basicAuth:

fh = fhem.Fhem('myserver.home.org', port=8086, protocol='https', loglevel=3,
               cafile=mycertfile, username="myuser", password="secretsauce")

Event queues (currently telnet only)

The library can create an event queue that uses a background thread to receive and dispatch FHEM events:

try:
    # Python 3.x
    import queue
except:
    # Python 2.x
    import Queue as queue
import fhem

que = queue.Queue()
fhemev = fhem.FhemEventQueue("myserver.home.org", que)

while True:
    ev = que.get()
    # FHEM events are parsed into a Python dictionary:
    print(ev)
    que.task_done()

Documentation

see: fhem documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhem-0.5.5.tar.gz (8.8 kB view details)

Uploaded Source

File details

Details for the file fhem-0.5.5.tar.gz.

File metadata

  • Download URL: fhem-0.5.5.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for fhem-0.5.5.tar.gz
Algorithm Hash digest
SHA256 c72617ef95aa26113f899f7f7d720982611d6467ccfcf5da858048f99a176388
MD5 270742f224ab689ae8e8f687ce8def4a
BLAKE2b-256 93165938e59eced8499c5f2c06bb47b44a866280ab726fcc11bdd8dd5624ee6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page