Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KNX Protocol support #2402

Closed
wants to merge 395 commits into from
Closed

Conversation

ascillato
Copy link
Contributor

@ascillato ascillato commented Apr 9, 2018

Sonoff-Tasmota KNX

Sonoff-Tasmota_KNX is a modification for Sonoff-Tasmota to add a basic functionality of the KNX IP Protocol.

KNX Explanation

The KNX IP Protocol is an international open standard for smart homes and smart buildings automation. It is a decentralized system. Each device can talk directly to each other without the need of a central controller or server. Any panel or server is just for telesupervision and for sending requests. KNX IP Protocol uses a UDP multicast on 224.0.23.12 : 3671, so there is no need for a KNX Router unless you want to communicate to KNX Devices that are not in the WIFI Network (Twisted Pair, RF, Powerline).

Each device has a physical address (like a fixed IP) as 1 . 1 . 0 and that address is used for configuration purposes.

Each device can be configured with group addresses as 2 / 2 / 1 and that address can be used for sending/receiving commands. So, for example, if 2 devices that are configured with the 2 / 2 / 1 for turning on/off their outputs, and other device send Turn ON command to 2 / 2 / 1, both devices will turn on their outputs.

Integration

Several home automation systems have KNX support. For example, Home Assistant has a XKNX Python Library to connect to KNX devices using a KNX Router. If you don't have a KNX Router, you can use a Software KNX Router like KNXd on the same Raspberry Pi than Home Assistant. KNXd is used by Home Assistant for reading this UDP Multicast, although KNXd has other cool features that need extra hardware like connect to KNX devices by Twister Pair, Power Line or RF.

If you use the ETS (KNX Configurator Software) you can add any Sonoff Tasmota KNX as a dummy device.

Requirements

A copy of both libraries is available at:

Usage Examples

There are multiple possible configurations. Here are explained just a few as example. The options for selecting relays, buttons, sensors, etc. are only available if were configured on Configure Module Menu.

To configure KNX, enter on the Configuration Menu of Sonoff-Tasmota and select Configure KNX.

config_menu

knx_menu

1) Setting Several Sonoff to be controlled as one by a Home Automation System:

We can set one of the group address to be the same in all the devices so as to turn them on or off at the same time.
In this case, so as to inform the status of all the relays to the Automation System, just one of the devices have to be configured as the responder. If you use the same Group Address for sending and receiving, you have to take into account not to make loops.

DEVICE 1

1

DEVICE 2

2

2) Setting 2 Sonoff to be linked as stair lights:

We can set one device to send the status of its output and another to read that and follow. And the second device can send the status of its button and the first device will toggle. With this configuration we can avoid to make a loop.

DEVICE 1

3

DEVICE 2

4

3) Setting a button as initiator of a scene:

Just setting one device to send the push of a button, and the rest just use that value to turn them on. In this case, there is no toggle. Every time the button is pushed, the turn on command is sent.

DEVICE 1

5

DEVICE 2

6

4) Setting a Temperature sensor:

We can configure to send the value of temperature or humidity every teleperiod. This teleperiod can be configured. See Sonoff Tasmota wiki. It is recommended also to set the reply temperature address.

7

Development Road Map

For Sonoff-Tasmota_KNX:

  • Add Web Menu
  • Add Feature to Receive telegrams and modify Relay Status
  • Add Feature to Receive telegrams from multiple Group Addresses to modify just one relay status (useful for scenes)
  • Add Feature to Send telegrams of relay status change
  • Add Feature to Send telegrams of one relay status to multiple Group Addresses (useful for scenes)
  • Add Feature to Send telegrams of button pressed
  • Add Feature to receive telegrams to toggle relay status
  • Add Feature to read Temperature, Humidity from Tasmota
  • Add Feature to send Temperature, Humidity by a set interval (tasmota teleperiod)
  • Add Feature to receive command to read temperature, Humidity
  • Add Feature to recognize Tasmota config to show the same number of relays, buttons, etc.
  • Add Feature to Save Config
  • Add Feature to Load Config
  • Add Log Info
  • Complete all the language files with keys

Modifications to Sonoff-Tasmota

  • Adding the file /sonoff/xdrv_10_KNX.ino
  • Add the entry #define USE_KNX on /sonoff/user_config.h
  • Add entries to the file /sonoff/webserver.ino
  • Add entries to the file /sonoff/sonoff.ino
  • Add entries to the file /sonoff/sonoff.h
  • Add entries to the file /sonoff/settings.h
  • Add entries to sensor files
  • Add entries to language files

Up to now, enabling KNX uses +23k of code and +3k3 of memory.

There is NO CONFLICT with MQTT, Home Assistant, Web, etc. Tests show fast response of all features running at same time.

Contributors

  • Adrian Scillato @ascillato
  • Sisamiwe @sisamiwe - Thanks for the guide on using KNX.
  • Nico Weichbrodt @envy - Thanks for the patience and help with the modifications to ESP_KNX_IP.

@ascillato
Copy link
Contributor Author

Hi,

I'm testing on Platform.io and have the same output.

I found on http://docs.platformio.org/en/stable/librarymanager/ldf.html#ldf-mode that PIO don't check for preprocessor conditional syntax.

I tried the lib_ldf_mode = chain+ on platformio.ini so as to make platform.io check for that, but no luck.

This platform.io bug is explained on platformio/platformio-core#801 (comment)

Will continue looking for a workaround...

@ascillato
Copy link
Contributor Author

ascillato commented Apr 17, 2018

Found a solution!!!!!

on sonoff_post.h just change to:

//#if defined(USE_KNX)
#include <esp-knx-ip.h>
void KNX_CB_Action(message_t const &msg, void *arg);
//#endif  // USE_KNX

Now compiles 👍

This don't use extra KB.

The normal tasmota without any line that includes <esp-knx-ip.h> and the one with this change are equal in size.

@ascillato
Copy link
Contributor Author

ascillato commented Apr 17, 2018

Tested on Arduino and Platform.io.

Now, in both systems it compiles and works, and in both options:

#define USE_KNX

and

//#define USE_KNX

@arendst
Copy link
Owner

arendst commented Apr 18, 2018

Well done 👍 and thnx for the kudo too ;-) You earned it just as much.

Just tested it and it seems to compile fine. Will now continue with sensor integration.

arendst added a commit that referenced this pull request Apr 18, 2018
5.12.0m
 * Reinit timers to accomodate random window (#2447)
 * Add
random window to timers (#2447)
 * Add optional KNX IP Protocol Support
(#2402)
arendst added a commit that referenced this pull request Apr 18, 2018
5.12.0m
 * Reinit timers to accomodate random window (#2447)
 * Add
random window to timers (#2447)
 * Add optional KNX IP Protocol Support
(#2402)
@arendst
Copy link
Owner

arendst commented Apr 18, 2018

Released. Pls add your info to the wiki and close this one so if you have any updates to the released version it makes things easier to find.

@reloxx13
Copy link
Contributor

reloxx13 commented Apr 18, 2018

Heya,

i get this issue with platformIO now:


Compiling .pioenvs\sonoff-DE\lib839\esp-knx-ip-async-udp-0.4.0.15\esp-knx-ip.cpp.o
lib\ESPAsyncUDP-0.21\src\AsyncUDP.cpp: In member function 'bool AsyncUDP::listenMulticast(ip_addr_t*, uint16_t, uint8_t)':

lib\ESPAsyncUDP-0.21\src\AsyncUDP.cpp:254:57: error: 'udp_set_multicast_netif_addr' was not declared in this scope
udp_set_multicast_netif_addr(_pcb, multicast_if_addr);
^
lib\ESPAsyncUDP-0.21\src\AsyncUDP.cpp:258:36: error: 'udp_set_multicast_ttl' was not declared in this scope
udp_set_multicast_ttl(_pcb, ttl);
^
Compiling .pioenvs\sonoff-DE\lib22b\Adafruit_SGP30-1.0.0.13\Adafruit_SGP30.cpp.o
*** [.pioenvs\sonoff-DE\lib091\ESPAsyncUDP-0.21\AsyncUDP.cpp.o] Error 1
 [ERROR] Took 13.92 seconds

With disabled KNX:
//#define USE_KNX

EDIT2:
Got it, its not compiling with 2.3.0 expressif lib :X

@ascillato
Copy link
Contributor Author

Hi,

Yes, both libraries now requires version 2.4.0 of the esp8266 board libraries.

Will not compile under 2.3.0 as explained on the libraries readme files:
esp-knx-ip readme
ESPAsyncUDP readme

It is needed to update the esp8266 board libraries as explained here

@ascillato
Copy link
Contributor Author

Made the PR #2487 to update Tasmota ReadMe with this requirement for compiling.

@ascillato
Copy link
Contributor Author

Added KNX on the wiki

@ascillato ascillato closed this Apr 19, 2018
@reloxx13
Copy link
Contributor

reloxx13 commented Apr 19, 2018

2.4.0)

  • HUE Emulation still bugged (Issue & Workaround)
  • WIFI Disconnects flooding Router Logs
  • WebUI very unresponsive (cuz of Wifi DC ?)
  • Devices often does not respond to Alexa (cuz of Wifi DC ?)
    => Seems its the sleep/wifi_light_sleep, but its saves alot of money (see Wiki Energy Saving).

coming 2.4.1)

  • Devices still freeze with wifi_light_sleep (tested with latest git)

I would suggest to get 2.3.0 still working without KNX. I just commented out some lines in the lib to get it compiled, but this is a dirty fix :X

@ascillato
Copy link
Contributor Author

Hi, I'm downgrading the esp-knx-ip library to use 2.3.0 so KNX will run on 2.3.0

I will make the PR soon

The fix will be just:

Delete ESPAsyncUDP library
Update ESP-KNX-IP library

No other change will be needed. And everything under ESP8266 v2.3.0

@reloxx13
Copy link
Contributor

no way around to check if knx is commented in and only load the lib than? would w8 for theos feedback maybe he got an idea.

@ascillato
Copy link
Contributor Author

PR #2492 to:

  • Update ESP-KNX-IP library
  • Delete ESPAsyncUDP library that is no longer used by ESP-KNX-IP library

Compiled and Tested under 2.3.0 with and without #define USE_KNX

@arendst
Copy link
Owner

arendst commented Apr 19, 2018

Released just now.

@sisamiwe
Copy link

@ascillato
I would like to say thank you. You have done a great job adding KNX support to tasmota.
Nevertheless I would also like to ask you, whether you see a chance to create a plugin for ESPEasy also to add KNX support?
What do you think?

@ascillato
Copy link
Contributor Author

ascillato commented Apr 25, 2018

Hi,

Thanks 👍

For achiving this KNX support, I have a lot of help from several persons including also you (@sisamiwe) and Nico (@envy) (https://github.com/envy/esp-knx-ip). Some features of the KNX Library were modified by Nico so as to be used like in here.

Now, with this driver, there is just a basic KNX IP support. With this KNX driver you can control relays and send buttons press, communicating device to device. It works, but there are some other needed features to be integrated and to be improved on both, Tasmota KNX Driver and ESP-KNX-IP Library that we are working on. After that, I will take a look at ESPEasy but will take me some time as I have to learn how that software work first.

Again, Thanks a lot and stay tunned for coming updates!

curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.12.0m
 * Reinit timers to accomodate random window (arendst#2447)
 * Add
random window to timers (arendst#2447)
 * Add optional KNX IP Protocol Support
(arendst#2402)
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.12.0m
 * Reinit timers to accomodate random window (arendst#2447)
 * Add
random window to timers (arendst#2447)
 * Add optional KNX IP Protocol Support
(arendst#2402)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants