Skip to content
Avatar
Block or Report

Block or report fhempy

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
fhempy/README.md

Download python Version LastCommit BuyCoffee

fhempy

fhempy allows the usage of Python 3 (NOT 2!) language to write FHEM modules. Python 3.9 or higher is required, therefore I recommend using bullseye.

This repository includes following working modules:

Module Description
arp_presence ARP based presence detection, works also for iOS
ble_monitor Supports a lot of BLE devices
ble_presence Presence detection incl. RSSI for Bluetooth Low Energy
ble_reset Resets all Bluetooth interfaces every X hours
bt_presence Presence detection incl. RSSI for Bluetooth
blue_connect Blue Connect
ddnssde Dynamic DNS updater for free ddnss.de service
discover_mdns Discover mDNS (e.g. googlecast) devices
discover_ble Discover Bluetooth LE devices
discover_upnp Discover UPnP devices
dlna_dmr Control DLNA MediaRenderer devices
energie_gv_at Retrieve current Austrian energy status
eq3bt Control EQ3 Bluetooth thermostat
erelax_vaillant Control eRelax Vaillant
esphome Installs and starts the ESP Home dashboard for easy ESP Home device management
fusionsolar Retrieve values from FusionSolar Kiosk
geizhals Retrieve prices from geizhals
gfprobt Control GF Pro Bluetooth irrigation control
github_backup Backup FHEM config to github
googlecast Control Cast devices and stream Spotify
google_weather Retrieve weather from Google
gree_climate Control gree HVAC devices
helloworld Hello World example for developers to start writing their own module
kia_hyundai Control your Kia/Hyundai car
meross Control Meross devices
miscale Xiaomi Mi Scale V1/2 support
miflora Xiaomi BLE Plant Sensor
miio Control Xiaomi WiFi devices
mitemp Xiaomi BLE Temperature/Humidity Sensor
nefit Control nefit devices
nespresso_ble Nespresso Bluetooth coffee machine
object_detection TensorFlow Lite object detection
pyit600 Control Salus iT600 devices
rct_power RCT Power inverter
ring Ring doorbell/chime/cam
seatconnect Control your Seat/Cupra car
spotify Control Spotify Connect and use FHEM as Spotify Connect player
skodaconnect Control your skoda car
tuya Control tuya devices localy incl. real-time updates (only WiFi devices)
tuya_cloud Control tuya devices via cloud incl. real-time updates (WiFi & ZigBee)
warema Control Warema devices
websitetests Do some basic website checks
wienerlinien Wiener Linien departure times
xiaomi_gateway3 Xiaomi Gateway V3 (only V3!)
xiaomi_tokens Retrieve all Xiaomi Tokens from Cloud
volvo_software_update Get notified about Volvo software updates
zigbee2mqtt Install, update and run Zigbee2MQTT server

Installation

Python >=3.8 is required, Python 2 won't work!

Console

Debian 11 (Bullseye)

Copy & paste this command if you are running Debian Bullseye.

sudo apt install python3 python3-pip python3-dev libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libglib2.0-dev libdbus-1-dev bluez libbluetooth-dev git libprotocol-websocket-perl

Others

Use the following 2 commands if you run Debian 10 (Buster) or older (e.g. stretch, jessie, ...).

sudo apt install python3 python3-pip python3-dev libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libglib2.0-dev libdbus-1-dev bluez libbluetooth-dev git
sudo cpan Protocol::WebSocket

FHEM

update add https://raw.githubusercontent.com/fhempy/fhempy/master/controls_pythonbinding.txt
update
shutdown restart
define fhempy_local BindingsIo fhempy

Wait a few minutes until fhempy is installed. This might take up to 15 minutes! fhempy_local will show up with a green circle when finished. All further requirements are installed automatically via pip as soon as the specific module is used the first time.

Usage in FHEM (examples)

This are just a few examples for some modules, please see the modules readme linked in the table above for more details

  • define castdevice fhempy googlecast "Living Room"
  • define eq3bt fhempy eq3bt 00:11:22:33:44:66:77
  • define upnp fhempy discover_upnp

fhempy peers (e.g. extend Bluetooth range)

fhempy allows to run modules locally (same device as FHEM runs on) or on remote peers. Those remote peers only make sense if you want to extend the range of bluetooth or want to distribute the load of some modules to other more powerfull devices (e.g. video object detection).

Peer setup (short version)

Only on remote peers, do not run this commands on the FHEM instance. Run this commands with user "pi".

### WARNING: DO THIS COMMAND ONLY ON REMOTE PEER, NOT ON YOUR FHEM INSTANCE ###
pip3 install --upgrade fhempy
# systemd service installation
curl -sL https://raw.githubusercontent.com/fhempy/fhempy/master/install_systemd_fhempy.sh | sudo -E bash -

Peer setup (long version)

Only needed if you didn't run Peer setup (short version). The following steps are only needed if you want to install fhempy on a remote peer, you should not run them on your FHEM installation.

  • Install fhempy with user pi: pip3 install --upgrade fhempy
  • Make sure your main fhempy instance (within FHEM) is running
  • Test fhempy by just running it with user pi, type fhempy and enter. Wait a few seconds until it gets discovered and you see the incoming FHEM connection.
  • Systemd configuration for autostart
    • curl -sL https://raw.githubusercontent.com/fhempy/fhempy/master/install_systemd_fhempy.sh | sudo -E bash -
    • fhempy is run with user pi, you can change that in the fhempy.service file in /etc/systemd/system/
  • FHEM configuration
    • The remote peer is autodiscovered and will show up in FHEM as device e.g. fhempy_peer_192_168_1_50
    • You can move any device to the remote peer by changing the IODev of the device.
    • If autodiscovery doesn't work (it's based on zeroconf), you can define it with define fhempy_peer_IP BindingsIo IP:15733 fhempy

Log file

journalctl -u fhempy.service -f

Update

Just do set remote_pybinding update and the remote peer will install the new package via pip and restart afterwads.

Functionality

10_BindingsIo

This module is a DevIo device which builds a language neutral communicaton bridge in JSON via websockets.

10_fhempyServer

This module just starts the fhempy server instance

10_fhempy

This module is used as the bridge to BindingsIo. It calls BindingsIo with IOWrite.

fhempy

This is the Python server instance which handles JSON websocket messages from BindingsIo. Based on the message it executes the proper function and replies to BindingsIo via websocket.

Call flow

This example shows how Define function is called from the Python module.

  1. define castdevice fhempy googlecast "Living Room"
  2. fhempy sends IOWrite to BindingsIo
  3. BindingsIo sends a JSON websocket message to fhempy
  4. fhempy loads the corresponding module (e.g. googlecast), creates an instance of the object (e.g. googlecast) and calls the Define function on that instance
  5. Define function is executed within the Python context, as long as the function is executed, FHEM waits for the answer the same way as it does for Perl modules
  6. Python Define returns the result via JSON via websocket to BindingsIo

At any time within the functions FHEM functons like readingsSingleUpdate(...) can be called by using the fhem.py module (fhem.readingsSingleUpdate(...)). There are just a few functions supported at the moment.

Flow Chart

Write your own module

Check helloworld example for writing an own module. Be aware that no function which is called from FHEM is allowed to run longer than 1s. In general no blocking code should be used with asyncio. If you want to call blocking code, use utils.run_blocking.

Pinned

  1. fhempy Public

    fhempy is a FHEM binding to write modules in Python language

    Python 29 16

1,274 contributions in the last year

No contributions on January 9, 2022 No contributions on January 10, 2022 No contributions on January 11, 2022 No contributions on January 12, 2022 No contributions on January 13, 2022 No contributions on January 14, 2022 7 contributions on January 15, 2022 No contributions on January 16, 2022 No contributions on January 17, 2022 No contributions on January 18, 2022 No contributions on January 19, 2022 No contributions on January 20, 2022 No contributions on January 21, 2022 22 contributions on January 22, 2022 16 contributions on January 23, 2022 No contributions on January 24, 2022 No contributions on January 25, 2022 No contributions on January 26, 2022 No contributions on January 27, 2022 No contributions on January 28, 2022 No contributions on January 29, 2022 No contributions on January 30, 2022 No contributions on January 31, 2022 3 contributions on February 1, 2022 1 contribution on February 2, 2022 No contributions on February 3, 2022 3 contributions on February 4, 2022 No contributions on February 5, 2022 21 contributions on February 6, 2022 6 contributions on February 7, 2022 7 contributions on February 8, 2022 6 contributions on February 9, 2022 6 contributions on February 10, 2022 8 contributions on February 11, 2022 19 contributions on February 12, 2022 22 contributions on February 13, 2022 10 contributions on February 14, 2022 11 contributions on February 15, 2022 10 contributions on February 16, 2022 2 contributions on February 17, 2022 11 contributions on February 18, 2022 4 contributions on February 19, 2022 7 contributions on February 20, 2022 6 contributions on February 21, 2022 3 contributions on February 22, 2022 3 contributions on February 23, 2022 No contributions on February 24, 2022 No contributions on February 25, 2022 No contributions on February 26, 2022 4 contributions on February 27, 2022 No contributions on February 28, 2022 No contributions on March 1, 2022 7 contributions on March 2, 2022 6 contributions on March 3, 2022 12 contributions on March 4, 2022 13 contributions on March 5, 2022 9 contributions on March 6, 2022 3 contributions on March 7, 2022 No contributions on March 8, 2022 6 contributions on March 9, 2022 No contributions on March 10, 2022 No contributions on March 11, 2022 No contributions on March 12, 2022 No contributions on March 13, 2022 No contributions on March 14, 2022 No contributions on March 15, 2022 No contributions on March 16, 2022 No contributions on March 17, 2022 No contributions on March 18, 2022 No contributions on March 19, 2022 1 contribution on March 20, 2022 No contributions on March 21, 2022 No contributions on March 22, 2022 No contributions on March 23, 2022 No contributions on March 24, 2022 No contributions on March 25, 2022 No contributions on March 26, 2022 No contributions on March 27, 2022 1 contribution on March 28, 2022 No contributions on March 29, 2022 No contributions on March 30, 2022 No contributions on March 31, 2022 No contributions on April 1, 2022 No contributions on April 2, 2022 No contributions on April 3, 2022 No contributions on April 4, 2022 No contributions on April 5, 2022 No contributions on April 6, 2022 No contributions on April 7, 2022 No contributions on April 8, 2022 No contributions on April 9, 2022 28 contributions on April 10, 2022 3 contributions on April 11, 2022 No contributions on April 12, 2022 2 contributions on April 13, 2022 1 contribution on April 14, 2022 No contributions on April 15, 2022 No contributions on April 16, 2022 2 contributions on April 17, 2022 No contributions on April 18, 2022 No contributions on April 19, 2022 15 contributions on April 20, 2022 No contributions on April 21, 2022 No contributions on April 22, 2022 2 contributions on April 23, 2022 No contributions on April 24, 2022 9 contributions on April 25, 2022 24 contributions on April 26, 2022 No contributions on April 27, 2022 No contributions on April 28, 2022 16 contributions on April 29, 2022 No contributions on April 30, 2022 23 contributions on May 1, 2022 3 contributions on May 2, 2022 3 contributions on May 3, 2022 No contributions on May 4, 2022 4 contributions on May 5, 2022 6 contributions on May 6, 2022 34 contributions on May 7, 2022 40 contributions on May 8, 2022 16 contributions on May 9, 2022 21 contributions on May 10, 2022 No contributions on May 11, 2022 No contributions on May 12, 2022 12 contributions on May 13, 2022 23 contributions on May 14, 2022 6 contributions on May 15, 2022 7 contributions on May 16, 2022 No contributions on May 17, 2022 9 contributions on May 18, 2022 19 contributions on May 19, 2022 No contributions on May 20, 2022 No contributions on May 21, 2022 No contributions on May 22, 2022 3 contributions on May 23, 2022 No contributions on May 24, 2022 No contributions on May 25, 2022 No contributions on May 26, 2022 No contributions on May 27, 2022 No contributions on May 28, 2022 No contributions on May 29, 2022 No contributions on May 30, 2022 No contributions on May 31, 2022 No contributions on June 1, 2022 No contributions on June 2, 2022 No contributions on June 3, 2022 7 contributions on June 4, 2022 No contributions on June 5, 2022 No contributions on June 6, 2022 No contributions on June 7, 2022 No contributions on June 8, 2022 No contributions on June 9, 2022 7 contributions on June 10, 2022 No contributions on June 11, 2022 No contributions on June 12, 2022 5 contributions on June 13, 2022 3 contributions on June 14, 2022 3 contributions on June 15, 2022 3 contributions on June 16, 2022 3 contributions on June 17, 2022 No contributions on June 18, 2022 No contributions on June 19, 2022 5 contributions on June 20, 2022 No contributions on June 21, 2022 1 contribution on June 22, 2022 No contributions on June 23, 2022 No contributions on June 24, 2022 No contributions on June 25, 2022 No contributions on June 26, 2022 No contributions on June 27, 2022 No contributions on June 28, 2022 No contributions on June 29, 2022 No contributions on June 30, 2022 No contributions on July 1, 2022 No contributions on July 2, 2022 No contributions on July 3, 2022 No contributions on July 4, 2022 No contributions on July 5, 2022 No contributions on July 6, 2022 No contributions on July 7, 2022 No contributions on July 8, 2022 6 contributions on July 9, 2022 3 contributions on July 10, 2022 No contributions on July 11, 2022 18 contributions on July 12, 2022 6 contributions on July 13, 2022 No contributions on July 14, 2022 3 contributions on July 15, 2022 3 contributions on July 16, 2022 No contributions on July 17, 2022 1 contribution on July 18, 2022 No contributions on July 19, 2022 No contributions on July 20, 2022 No contributions on July 21, 2022 No contributions on July 22, 2022 No contributions on July 23, 2022 No contributions on July 24, 2022 No contributions on July 25, 2022 No contributions on July 26, 2022 No contributions on July 27, 2022 No contributions on July 28, 2022 No contributions on July 29, 2022 No contributions on July 30, 2022 1 contribution on July 31, 2022 No contributions on August 1, 2022 1 contribution on August 2, 2022 7 contributions on August 3, 2022 10 contributions on August 4, 2022 5 contributions on August 5, 2022 12 contributions on August 6, 2022 7 contributions on August 7, 2022 6 contributions on August 8, 2022 5 contributions on August 9, 2022 28 contributions on August 10, 2022 12 contributions on August 11, 2022 23 contributions on August 12, 2022 42 contributions on August 13, 2022 No contributions on August 14, 2022 No contributions on August 15, 2022 No contributions on August 16, 2022 No contributions on August 17, 2022 No contributions on August 18, 2022 No contributions on August 19, 2022 42 contributions on August 20, 2022 12 contributions on August 21, 2022 4 contributions on August 22, 2022 No contributions on August 23, 2022 3 contributions on August 24, 2022 No contributions on August 25, 2022 No contributions on August 26, 2022 No contributions on August 27, 2022 3 contributions on August 28, 2022 4 contributions on August 29, 2022 3 contributions on August 30, 2022 3 contributions on August 31, 2022 3 contributions on September 1, 2022 4 contributions on September 2, 2022 6 contributions on September 3, 2022 7 contributions on September 4, 2022 16 contributions on September 5, 2022 4 contributions on September 6, 2022 No contributions on September 7, 2022 3 contributions on September 8, 2022 10 contributions on September 9, 2022 No contributions on September 10, 2022 No contributions on September 11, 2022 3 contributions on September 12, 2022 No contributions on September 13, 2022 1 contribution on September 14, 2022 1 contribution on September 15, 2022 3 contributions on September 16, 2022 No contributions on September 17, 2022 12 contributions on September 18, 2022 4 contributions on September 19, 2022 13 contributions on September 20, 2022 6 contributions on September 21, 2022 No contributions on September 22, 2022 1 contribution on September 23, 2022 9 contributions on September 24, 2022 10 contributions on September 25, 2022 7 contributions on September 26, 2022 18 contributions on September 27, 2022 12 contributions on September 28, 2022 4 contributions on September 29, 2022 1 contribution on September 30, 2022 11 contributions on October 1, 2022 17 contributions on October 2, 2022 8 contributions on October 3, 2022 3 contributions on October 4, 2022 8 contributions on October 5, 2022 No contributions on October 6, 2022 1 contribution on October 7, 2022 1 contribution on October 8, 2022 12 contributions on October 9, 2022 4 contributions on October 10, 2022 8 contributions on October 11, 2022 No contributions on October 12, 2022 No contributions on October 13, 2022 3 contributions on October 14, 2022 2 contributions on October 15, 2022 4 contributions on October 16, 2022 No contributions on October 17, 2022 No contributions on October 18, 2022 No contributions on October 19, 2022 No contributions on October 20, 2022 No contributions on October 21, 2022 No contributions on October 22, 2022 No contributions on October 23, 2022 No contributions on October 24, 2022 No contributions on October 25, 2022 No contributions on October 26, 2022 No contributions on October 27, 2022 No contributions on October 28, 2022 No contributions on October 29, 2022 No contributions on October 30, 2022 No contributions on October 31, 2022 No contributions on November 1, 2022 1 contribution on November 2, 2022 No contributions on November 3, 2022 No contributions on November 4, 2022 No contributions on November 5, 2022 No contributions on November 6, 2022 No contributions on November 7, 2022 No contributions on November 8, 2022 No contributions on November 9, 2022 No contributions on November 10, 2022 No contributions on November 11, 2022 6 contributions on November 12, 2022 No contributions on November 13, 2022 No contributions on November 14, 2022 1 contribution on November 15, 2022 No contributions on November 16, 2022 No contributions on November 17, 2022 No contributions on November 18, 2022 13 contributions on November 19, 2022 6 contributions on November 20, 2022 4 contributions on November 21, 2022 No contributions on November 22, 2022 No contributions on November 23, 2022 No contributions on November 24, 2022 No contributions on November 25, 2022 4 contributions on November 26, 2022 No contributions on November 27, 2022 No contributions on November 28, 2022 No contributions on November 29, 2022 No contributions on November 30, 2022 No contributions on December 1, 2022 No contributions on December 2, 2022 No contributions on December 3, 2022 4 contributions on December 4, 2022 3 contributions on December 5, 2022 No contributions on December 6, 2022 No contributions on December 7, 2022 No contributions on December 8, 2022 1 contribution on December 9, 2022 No contributions on December 10, 2022 2 contributions on December 11, 2022 No contributions on December 12, 2022 No contributions on December 13, 2022 No contributions on December 14, 2022 No contributions on December 15, 2022 No contributions on December 16, 2022 16 contributions on December 17, 2022 4 contributions on December 18, 2022 No contributions on December 19, 2022 2 contributions on December 20, 2022 No contributions on December 21, 2022 No contributions on December 22, 2022 No contributions on December 23, 2022 1 contribution on December 24, 2022 No contributions on December 25, 2022 No contributions on December 26, 2022 No contributions on December 27, 2022 No contributions on December 28, 2022 No contributions on December 29, 2022 No contributions on December 30, 2022 No contributions on December 31, 2022 1 contribution on January 1, 2023 11 contributions on January 2, 2023 No contributions on January 3, 2023 2 contributions on January 4, 2023 2 contributions on January 5, 2023 4 contributions on January 6, 2023 4 contributions on January 7, 2023 4 contributions on January 8, 2023 No contributions on January 9, 2023 11 contributions on January 10, 2023 No contributions on January 11, 2023 5 contributions on January 12, 2023 5 contributions on January 13, 2023 No contributions on January 14, 2023 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Mon Wed Fri

Contribution activity

January 2023

Created 49 commits in 1 repository

Seeing something unexpected? Take a look at the GitHub profile guide.