Git Product home page Git Product logo

tasmohab's Introduction

TasmoHAB - OpenHAB Things and Items Generator via GUI

What is it for?

TasmoHAB is a Python program with GUI which can read Tasmota devices and automatically integrate and configure them in OpenHab by TXT files or by REST API.


Note
Please check the template and adapt it to your own OpenHab if necessary (f.e.:'set mqttUID'). Also check 'tasmohab.cfg' for following parameters:
Openhab_Instances
OpenHab_User
OpenHab_Pass
Thing_Path
Item_Path
and so on ...


Not yet implemented:

  • metadata api (set metadata via API, txt files should work)

Features:

  • Readout of Tasmota devices
  • Inspect settings of tasmota devices
  • Display, edit and save tasmota rules
  • change tasmota settings
  • usage of tasmota backlog command
  • possibility to create and save a device config from any tasmota device and load it later on
  • display all components of the tasmota device
  • name, configure and create openhab things and items and linke them
  • create things,items and links via text-based files (.items or .things) or via REST API

Usage

I was inspired by the project https://github.com/jimtng/ohgen to easily link a Tasmota device with OpenHab through a GUI. The programme uses the almost identical code of 'ohgen' to generate the things and items files. In the first step, all tasmota gpios of a device are queried and the peripherals are displayed in a table. Then the user can select or deselect individual actuators or sensors in the table. In the next step, a yaml config for 'ohgen' is generated, which contains the objects selected by the user. This config can still be edited here. In the last step, the things and items objects for openhab are displayed. These can either be copied or saved as files or saved via REST API. All read-in and processed data (sensors, device status, actuators, user settings, etc.) can be conveniently viewed in JSON format.

I would like to invite everyone to participate in the project to improve the tool!

tasmohab tasmohab3

How it works

Json data

The program uses

json_config_data = {}                       # data from YAML config file. later it holds all relevant data to generate a thing an item
json_dev_status = {}                        # all device data from device (http or serial)
json_tasmota_objects = {}                   # this object contains only gpio data (name, value and possible sensor) coming from tasmota device

json_tasmota_objects will be used later to fill the gui with content (gpios, sensors and actuators).

For example, here is the program flow when you click "Get from serial":

TasmoHab UI Functions

Show whole data (gpio information, openhab items, peripheral name, sensors, etc.) in a table/grid. The program differences between sensors and actuators. Sensors are objects, which are appear under 'StatusSNS' from the json response of the tasmota device. All other objects that do not appear there are actuators.

def add_ui_widgets(self):

Add the user specific widgets behind the corresponding object:

def add_ui_widgets_user(self, layout, row, label, peripheral_no='default'):

The values for every widget about an item comes from: [openhab.py](The values for every widget about an item comes from:)

All relevant data is stored in json_config_data[dict]. The function takes these data to generate things and items. It appends some additional data and then use ohgen.py to format the output data in a way that openhab can use it. Therefore ohgen needs a 'template of format'. You have to choose these template before you can generate any thing or output. These templates muste be named '*.tpl' and can be edited while runtime. The template have to be stored under ohgen/templates/test.tpl. The data is then shown in the last tab and can be saved to a thing and an item file.

What is the feature line for?

The 'feature' line is not an openhab item or so. It is a special user-defined option for every item to distinguish it from normal item types (switch, number, ...). It is only used by the previously selected template. This can be used, for example, to control whether an element of the type 'Dimmer' has additional properties such as 'colourtemperature' or 'RGB'. This can be easily queried e.g. with an if-clause in the template.

Use and edit your template

The program uses all files with '*.tpl' extension in the directory 'ohgen/templates' for the output of the data. Here the format of the output can be predefined for each item type (Number, Contact, String, ...). The syntax rules for Jinja2 apply. If item types are omitted here, they are also ignored in the output. So e.g. several templates for different devices can be generated and used.

##Develop

Adding more commands to send

Add a new widget 'QLineEdit' with 'objectname' = 'tasmota commandname' (f.e.: 'ssid1') to the QFrame with the objectname 'frame'. The function get this object (and its name) and put the name with its value to the backlog command.

Example in Qt Designer:
Add a new widget to 'gridLayout_cmds' layout.

Example in python script:

self.ssid1 = QtWidgets.QLineEdit(self.frame)
self.ssid1.setObjectName("ssid1")
self.gridLayout_cmds.addWidget(self.ssid1, 1, 1, 1, 1)          # caution with the position!

In the future ...

Theoretically, it is relatively easy to adapt the output format to other smarthome systems (e.g. homeassistant, etc.). Among other things, the file openhab.py, the function add_ui_openhab_widgets and of course the function gen_fin_objects must be adapted or replaced to adapt the output format. The third tab "Object output" can be filled with content e.g. at runtime to generate a different layout for other smarthome systems.

Debugging

Check your txt output

Go to Openhab-DEMO and validate your output. if erros exists, check your template first.

Convert to .exe

####PyQT5:

  • python -m PyQt5.uic.pyuic tasmohabUI.ui -o tasmohabUI.py # for UI components
  • pyrcc5 resource.qrc -o resource_rc.py # for resource items f.e. images (ressource.qrc) ####PyQT6:
  • pyuic6 -x tasmohabUI.ui -o tasmohabUI.py
  • pyuic6 -x dev_config.ui -o dev_config.py ####PyQt6 Designer:
  • pyqt6-tools designer

PyInstaller:

  • pyinstaller --onefile --windowed --icon=icon.ico --noconsole --clean --paths=...\TasmoHAB --pat hs=...\TasmoHAB\ohgen tasmohab.py

with virtualenv path:

  • pyinstaller --onefile --windowed --icon=icon.ico --noconsole --clean --paths=...\PyCharm\venv\Lib\site-packages --paths=...\PyCharm\TasmoHAB --pat hs=...\PyCharm\TasmoHAB\ohgen tasmohab.py

For Debug (not windowed):

  • pyinstaller --onefile --debug all --icon=icon.ico --clean --paths=...\PyCharm\venv\Lib\site-packages --paths=...\PyCharm\TasmoHAB --pat hs=...\PyCharm\TasmoHAB\ohgen tasmohab.py
  • And then: ".\dist\tasmohab.exe"

after successfull build (uses last build config in spec file):

  • pyinstaller tasmohab.spec

Requirements:

  • tasmota device tested with firmware >8.3.1
  • pip install -r requirements.txt

Credits

tasmohab's People

Contributors

gifford47 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tasmohab's Issues

Hot to run tasmotahab from console on macos?

This project looks very interesting!
Unfortunately I can't get it to work.

My System:
macOS Montery
Python:
Python 3.8.2 (default, Oct 2 2020, 10:45:42) [Clang 12.0.0 (clang-1200.0.32.27)] on darwin

After installation of the dependencies, execution of
python3 tasmohabUI.py
results in the GUI to be started, but it does not do anything.
I tried to discover a tasmota device via http without success.
Bildschirmfoto 2022-11-08 um 19 43 21

Trying to run
python3 tasmohab.py
leads to a crash:

sven@iMac tasmohab % python3 tasmohab.py
objc[90940]: Class QMacAutoReleasePoolTracker is implemented in both /Users/sven/Library/Python/3.8/lib/python/site-packages/PyQt6/Qt6/lib/QtCore.framework/Versions/A/QtCore (0x10d29d940) and /Library/Python/3.8/site-packages/PyQt5/Qt5/lib/QtCore.framework/Versions/5/QtCore (0x111841198). One of the two will be used. Which one is undefined.
objc[90940]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /Users/sven/Library/Python/3.8/lib/python/site-packages/PyQt6/Qt6/lib/QtCore.framework/Versions/A/QtCore (0x10d29d9b8) and /Library/Python/3.8/site-packages/PyQt5/Qt5/lib/QtCore.framework/Versions/5/QtCore (0x111841210). One of the two will be used. Which one is undefined.
objc[90940]: Class KeyValueObserver is implemented in both /Users/sven/Library/Python/3.8/lib/python/site-packages/PyQt6/Qt6/lib/QtCore.framework/Versions/A/QtCore (0x10d29d9e0) and /Library/Python/3.8/site-packages/PyQt5/Qt5/lib/QtCore.framework/Versions/5/QtCore (0x111841238). One of the two will be used. Which one is undefined.
objc[90940]: Class RunLoopModeTracker is implemented in both /Users/sven/Library/Python/3.8/lib/python/site-packages/PyQt6/Qt6/lib/QtCore.framework/Versions/A/QtCore (0x10d29da30) and /Library/Python/3.8/site-packages/PyQt5/Qt5/lib/QtCore.framework/Versions/5/QtCore (0x111841288). One of the two will be used. Which one is undefined.
Running threads:
MainThread
UI_Thread


WARNING: QApplication was not created in the main() thread.
qt.qpa.drawing: Layer-backing is always enabled.  QT_MAC_WANTS_LAYER/_q_mac_wantsLayer has no effect.
2022-11-08 19:46:55.624 Python[90940:1972387] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007ff81d9d0773 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff81d730bc3 objc_exception_throw + 48
	2   CoreFoundation                      0x00007ff81d9f9056 -[NSException raise] + 9
	3   AppKit                              0x00007ff8203b50a4 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 321
	4   AppKit                              0x00007ff8203a1054 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1288
	5   AppKit                              0x00007ff8203a0b46 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
	6   AppKit                              0x00007ff820681aa7 -[NSWindow initWithContentRect:styleMask:backing:defer:screen:] + 50
	7   libqcocoa.dylib                     0x0000000110c8a2be _ZN20QCocoaSystemTrayIcon17statusItemClickedEv + 232222
	8   libqcocoa.dylib                     0x0000000110c60948 _ZN20QCocoaSystemTrayIcon17statusItemClickedEv + 61864
	9   libqcocoa.dylib                     0x0000000110c597a3 _ZN20QCocoaSystemTrayIcon17statusItemClickedEv + 32771
	10  libqcocoa.dylib                     0x0000000110c5923c _ZN20QCocoaSystemTrayIcon17statusItemClickedEv + 31388
	11  QtGui                               0x000000010f8efd8e _ZN14QWindowPrivate6createEby + 206
	12  QtWidgets                           0x0000000110655f38 _ZN14QWidgetPrivate6createEv + 1096
	13  QtWidgets                           0x0000000110653940 _ZN7QWidget6createEybb + 320
	14  QtWidgets                           0x00000001107ec407 _ZNK8QMenuBar15initStyleOptionEP20QStyleOptionMenuItemPK7QAction + 1783
	15  QtWidgets                           0x00000001107ebf85 _ZNK8QMenuBar15initStyleOptionEP20QStyleOptionMenuItemPK7QAction + 629
	16  QtWidgets.abi3.so                   0x000000010f0cf664 _ZL18init_type_QMenuBarP17_sipSimpleWrapperP7_objectS2_PS2_S3_S3_ + 116
	17  sip.cpython-38-darwin.so            0x000000010c3e7ae9 sipSimpleWrapper_init + 505
	18  Python3                             0x000000010babc054 type_call + 292
	19  Python3                             0x000000010ba66dd6 _PyObject_MakeTpCall + 374
	20  Python3                             0x000000010bb4713c call_function + 652
	21  Python3                             0x000000010bb436d6 _PyEval_EvalFrameDefault + 29782
	22  Python3                             0x000000010ba6778d function_code_fastcall + 237
	23  Python3                             0x000000010ba6a14b method_vectorcall + 171
	24  Python3                             0x000000010bb47012 call_function + 354
	25  Python3                             0x000000010bb436d6 _PyEval_EvalFrameDefault + 29782
	26  Python3                             0x000000010bb48097 _PyEval_EvalCodeWithName + 3287
	27  Python3                             0x000000010ba6790d _PyFunction_Vectorcall + 253
	28  Python3                             0x000000010ba66c0a _PyObject_FastCallDict + 218
	29  Python3                             0x000000010ba682f3 _PyObject_Call_Prepend + 131
	30  Python3                             0x000000010bac0b74 slot_tp_init + 180
	31  Python3                             0x000000010babc054 type_call + 292
	32  Python3                             0x000000010ba66dd6 _PyObject_MakeTpCall + 374
	33  Python3                             0x000000010bb4713c call_function + 652
	34  Python3                             0x000000010bb4378a _PyEval_EvalFrameDefault + 29962
	35  Python3                             0x000000010ba6778d function_code_fastcall + 237
	36  Python3                             0x000000010ba67124 PyVectorcall_Call + 100
	37  Python3                             0x000000010bb43a34 _PyEval_EvalFrameDefault + 30644
	38  Python3                             0x000000010ba6778d function_code_fastcall + 237
	39  Python3                             0x000000010bb47012 call_function + 354
	40  Python3                             0x000000010bb436b9 _PyEval_EvalFrameDefault + 29753
	41  Python3                             0x000000010ba6778d function_code_fastcall + 237
	42  Python3                             0x000000010bb47012 call_function + 354
	43  Python3                             0x000000010bb436b9 _PyEval_EvalFrameDefault + 29753
	44  Python3                             0x000000010ba6778d function_code_fastcall + 237
	45  Python3                             0x000000010ba6a1e2 method_vectorcall + 322
	46  Python3                             0x000000010ba67124 PyVectorcall_Call + 100
	47  Python3                             0x000000010bbe900a t_bootstrap + 74
	48  Python3                             0x000000010bb9a829 pythread_wrapper + 25
	49  libsystem_pthread.dylib             0x00007ff81d88e4e1 _pthread_start + 125
	50  libsystem_pthread.dylib             0x00007ff81d889f6b thread_start + 15
)
libc++abi: terminating with uncaught exception of type NSException
zsh: abort      python3 tasmohab.py

Running the command in CLI mode for bulk / batch operation

This is a great tool, for sure, no doubt about it.

I would like to run this tool in a command line, so i can perform a batch operation. I have about 50 Tasmota Devices (NodeMCU, ESP32, SONOFF Basic, SONOFF Pow R2, etc).

Currently i have configured the things, and items files manually. This tool will help automate greatly.

I tried to run tasmohab.py on a headless ubuntu, but there is a hard requirement of PyQT6. Which i cannot install on a headless Ubuntu.

So an option to run this over a batch process would be awesome.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.