Extra API special for Python programmers

Python and python framework
Post Reply
User avatar
Xorfor
Posts: 90
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Extra API special for Python programmers

Post by Xorfor » Thursday 17 May 2018 21:33

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: 512
Joined: Sunday 22 January 2017 12:37
Target OS: Windows
Domoticz version: V3.9056
Contact:

Re: Extra API special for Python programmers

Post by zak45 » Friday 18 May 2018 11:11

Thanks, great idea to not re-invent the Wheel ;-)
will take a look.

febalci
Posts: 317
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 » Friday 18 May 2018 12:26

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

User avatar
Xorfor
Posts: 90
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Extra API special for Python programmers

Post by Xorfor » Sunday 27 May 2018 2:14

Version 0.1.1 available. Look at the initial post for more information.

febalci
Posts: 317
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 » Sunday 27 May 2018 2:27

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.

User avatar
Xorfor
Posts: 90
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Extra API special for Python programmers

Post by Xorfor » Sunday 27 May 2018 2:49

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.

User avatar
Xorfor
Posts: 90
Joined: Sunday 03 December 2017 23:37
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Extra API special for Python programmers

Post by Xorfor » Wednesday 30 May 2018 21:12

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests