Extra API special for Python programmers

Python and python framework

Moderator: leecollings

Post Reply
Xorfor

Extra API special for Python programmers

Post by Xorfor »

During development of Python plugins, I got requests if it was possible to send notifications, access user variables, etc.

For that reason I started to write an global API in Python based on Domoticz API/JSON URL's which can be used in Python Plugins. At this moment it is possible to:
  • Get all kind of properties from Domoticz, like sunset, sunrise, Domoticz version, update available, etc.
  • Add Dummy hardware in Domoticz
  • Update, delete and check existence Hardware
  • Add, update, delete and check existence of Devices
  • Update values of the Devices
  • Create, update, delete and check existance User variables
  • Send Notifications
  • Execute server commands, like Reboot, Shutdown, and Log a message in Domoticz log
  • And much more!!!
Look at the Wiki for more information. Also look at the test scripts for examples to use this api.

Please feel free to use this and add the missing functionality.

Source can be found at: Xorfor/Domoticz-API

Version 0.2.0:
API has now a beta status. Device class is ready. I am now able to add hardware and add devices to that hardware. Look on the Device wiki for more information. Description of the found values of the Device is not complete and examples of updating different device types will be completed in the near future.
Also some general functions are added to convert temperature to other units.

Version 0.1.1:
Still strugling to get the Hardware and Devices classes clear. I added a Warnings page for other developers to avoid pitfalls in the naming conventions of the Domoticz JSON URL's and unexpected/inconsequent values returned by the Domoticz JSON API. Also a brief description of the 'undocumented' Domoticz JSON API URL's can be found on this Wiki page.
Last edited by Xorfor on Wednesday 30 May 2018 21:03, edited 6 times in total.
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Extra API special for Python programmers

Post by zak45 »

Thanks, great idea to not re-invent the Wheel ;-)
will take a look.
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Extra API special for Python programmers

Post by febalci »

Wow, this solves all problems l had with plugin development. Thanks a lot Xorfor...
Xorfor

Re: Extra API special for Python programmers

Post by Xorfor »

Version 0.1.1 available. Look at the initial post for more information.
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Extra API special for Python programmers

Post by febalci »

Xorfor, is there any way you can also include the variables for :
- installation directory of domoticz (/home/user/domoticz or c:\domoticz)
- custom web page directory (/home/user/domoticz/www/templates or c:\www\)

since these directories differ in every installation of domoticz namely on linux, windows, synology and osx OSes. I want the plugin to write extra details to a custom webpage but this directory is different on every OS.

A second question is, is this API works also with Domoticz 3.8153 stable or only on beta?

Thanks for the good work once again.
Xorfor

Re: Extra API special for Python programmers

Post by Xorfor »

Hmm. By searching the source code and hacking the javascripts, I almost found 20 'undocumented' api URL's, but none of them contains these directories. Fortunately I didn't need these directories :) , but perhaps I can find a workaround.

I am using the 'standard' URL's which are used by Domoticz by 'curl' instead of 'requests', etc. If a user is using a very old version, may be attributes like 'astrtwilightstart', etc. may have the None value. But as far as I can see in the source code and have tested, this API should work on the latest stable and beta version.
Xorfor

Re: Extra API special for Python programmers

Post by Xorfor »

Version 0.2.0 is available now.
In fact the complete set of adding hardware and devices is now possible. Also possible to rename devices, add or remove from the Domoticz tabs, etc. is now possible. Also some functions are available to identify the type of device (thermometer, hydrometer, etc). Look at the Wiki for more information.
Xorfor

Re: Extra API special for Python programmers

Post by Xorfor »

It is a couple of months ago, but this Python API is already on version 0.4.2 :D

It makes it easier for you to develop your own plugins or scripts. The API now also supports the control of switches/lights to switch on/off/toggle, or set level and color. Please look at:

https://github.com/Xorfor/Domoticz-API

for the source and look at the Wiki for more information.

Please add your own functionality and give me some feedback.
Tonio16
Posts: 45
Joined: Friday 23 February 2018 20:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: France
Contact:

Re: Extra API special for Python programmers

Post by Tonio16 »

Hello

How to install it on my Pi? I launch the setup.py but I have an egg file and DomoticzAPI.py file or directory. How should I go further?

Tx

Antoine
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest