Domoticz plugin

Questions and comments specific to a particular plugin should go here.
WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Domoticz plugin

Post by WoLpH » Sun Oct 02, 2016 8:29 pm

Domoticz is a home automation system which allows you to control your lights, curtains and more. http://www.domoticz.com/

With this EventGhost plugin it's now possible to control all of your Domoticz devices. If desired more actions and device types can be added but for now I've kept it reasonably limited.

Bugs and issues They can be reported at the Github project (or here, but it might take longer for me to see it): https://github.com/WoLpH/eventghost-domoticz/issues
Download: https://github.com/WoLpH/eventghost-domoticz/releases


Screenshots

Settings
Image

Adding devices
Image

Configuring dimmers
Image

Configuring regular switches
Image

Configuring all types of switches
Image

For listening to EventGhost the MQTT plugin by krambriw can be used.
Support topic: viewtopic.php?f=9&t=5728
Download link for MQTT: http://krambriw.net/Release/MQTT%20Clie ... 20version/

How to set-up MQTT
  1. Install the MQTT plugin
  2. Add a macro: MQTT Client -> Start a new MQTT subscription
  3. Set topic to "domoticz/out", make the session persistent and set the host name or IP
Image

After that, any domoticz event will be visible in eventghost and can be dragged towards a macro:

Image
Last edited by WoLpH on Wed Apr 12, 2017 9:35 pm, edited 2 times in total.
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

kalinkamaen
Experienced User
Posts: 138
Joined: Wed Dec 26, 2012 9:23 am

Re: Domoticz plugin

Post by kalinkamaen » Sun Oct 02, 2016 8:37 pm

Thank you so much for this plugin :) Looking forward to test this!

kalinkamaen
Experienced User
Posts: 138
Joined: Wed Dec 26, 2012 9:23 am

Re: Domoticz plugin

Post by kalinkamaen » Tue Oct 04, 2016 1:12 am

Looks like I get problems to connect!
I am trying to connect to Admin user with password.

Code: Select all

Traceback (most recent call last) (1722):
  File "C:\EventGhost\eg\Classes\TaskletDialog.py", line 59, in ProcessingTask
    self.Configure(*args, **kwargs)
  File "C:\EventGhost\eg\Classes\ConfigDialog.py", line 165, in Configure
    treeItem.Configure(*args)
  File "C:\EventGhost\eg\Classes\ActionItem.py", line 101, in Configure
    return self.executable.Configure(*args)
  File "C:\EventGhost\plugins\domoticz\__init__.py", line 61, in Configure
    panels.print_error('Unable to connect: %r' % e)
AttributeError: 'module' object has no attribute 'print_error'

kalinkamaen
Experienced User
Posts: 138
Joined: Wed Dec 26, 2012 9:23 am

Re: Domoticz plugin

Post by kalinkamaen » Tue Oct 04, 2016 1:39 am

Got it working now!

Forgot to put in http:// as host. Exmpl: Http://192.168.xx.xxx:port

Any way, I think i found an bug. When I try to dim a unit to 50 or similar the unit becomes 100% or On.

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: Domoticz plugin

Post by WoLpH » Wed Oct 05, 2016 11:57 am

A little update, I've found a method for receiving all events. Apparently Domoticz has MQTT support which enables live events. The EventGhost MQTT plugin does receive these types of events but doesn't understand the json data returned as far as I can see so I'll have to integrate it into the plugin for that to work.

@kalinkamaen: I've created a debug release which should show some more output. Can you try that?
I have no problems dimming here so not sure what's wrong

https://github.com/WoLpH/eventghost-dom ... /0.2.debug
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

kalinkamaen
Experienced User
Posts: 138
Joined: Wed Dec 26, 2012 9:23 am

Re: Domoticz plugin

Post by kalinkamaen » Wed Oct 05, 2016 12:48 pm

Wow you are working fast. Thank you very much. Will test ASAP!

Here you can see what happens.

Image

Code: Select all

Domoticz http://192.168.10.xxx:xxxx: Set 2 etg lys trapp to 70
   Domoticz http://192.168.10.xxx:xxxx: Set 2 etg lys trapp to 70
      http://192.168.10.xxx:xxxx/json.htm {'switchcmd': 'Set Level', 'type': 'command', 'param': 'switchlight', 'idx': 15, 'level': 70}
      connecting to u'http://192.168.10.xxx:xxxx/json.htm'
      using params {'switchcmd': 'Set Level', 'type': 'command', 'param': 'switchlight', 'idx': 15, 'level': 70}
      with timeout 1
Image

What version Domoticz are you working with?
Do you use Stable or Beta?

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: Domoticz plugin

Post by WoLpH » Wed Oct 05, 2016 1:56 pm

I'm running the git release, so... beyond beta but that should make no difference for the API.
According to the docs, the API looks like this: https://www.domoticz.com/wiki/Domoticz_ ... tain_level

Which is close to what we see in your log. The docs specify:
/json.htm?type=command&param=switchlight&idx=99&switchcmd=Set%20Level&level=6
In json format (as the logs show), that looks like:
{'switchcmd': 'Set Level', 'type': 'command', 'param': 'switchlight', 'idx': 99, 'level': 6}

Besides a different idx and level, your command looks the same:
{'switchcmd': 'Set Level', 'type': 'command', 'param': 'switchlight', 'idx': 15, 'level': 70}

To check what Domoticz uses internally you can use the developer tools in your browser. For example, in Chrome it looks like the attached screenshot. As you can see, it's the same command so if it works from your browser it should work from the plugin as well.
Screen Shot 2016-10-05 at 15.57.35.png
Note that the value is always off-by-one since it starts counting at 1 instead of 0. So 60%=61 and 100%=101
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Domoticz plugin

Post by krambriw » Wed Oct 05, 2016 2:23 pm

The EventGhost MQTT plugin does receive these types of events but doesn't understand the json data returned as far as I can see so I'll have to integrate it into the plugin for that to work.
I would not mind if you modified my MQTT Client plugin for this purpose, I think it is not difficult since you know what event format you expect and what output you want
BR Walter

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: Domoticz plugin

Post by WoLpH » Wed Oct 05, 2016 2:28 pm

That's awesome krambriw! Thanks :)

I think it should be simple enough actually, it would just have to be processed as json with some intelligence to only trigger for specific data. I've got some ideas for that, I only hope wx won't make it too difficult for me ;)
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

kalinkamaen
Experienced User
Posts: 138
Joined: Wed Dec 26, 2012 9:23 am

Re: Domoticz plugin

Post by kalinkamaen » Wed Oct 05, 2016 2:54 pm

This is setting dimmer to 46%
http://192.168.xx.xxx:xxxx/json.htm?type=command&param=switchlight&idx=20&switchcmd=Set%20Level&level=8

I will try to set it to level 8 in your plugin



Edit: That worked, it now dimmed to 46%.

Must be some bug in my Domoticz?

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: Domoticz plugin

Post by WoLpH » Wed Oct 05, 2016 3:06 pm

Now I get it. Depending on the dimmer the levels are different. Mine happen to go from 0 to 100 but that's not a guarantee apparently.

I'll create a new release soon :)
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

kalinkamaen
Experienced User
Posts: 138
Joined: Wed Dec 26, 2012 9:23 am

Re: Domoticz plugin

Post by kalinkamaen » Wed Oct 05, 2016 3:23 pm

Thanks, you are awsome ;)

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Domoticz plugin

Post by krambriw » Wed Oct 05, 2016 4:28 pm

I only hope wx won't make it too difficult for me ;)
I don't think it will. The processing is rather straight forward as you can see int the code below. If you would insert a section that identify & formats the incoming event according your ideas, I think it will be fine.

As example, the following code is looking for and formatting events from openHab:

Code: Select all

            if self.topic.find('/openHAB/') != -1:
                event = str(msg.payload).split(',')
                res_key = msg.topic + ', ' + event[0]
                res_base = str(msg.qos)+" "+str(msg.payload)
                ProcessEvent(msg, False, 0.0, res_key, event)
                return
Or you could just give an example of the event and what you expect as output and I can add it

BR Walter

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: Domoticz plugin

Post by WoLpH » Wed Oct 05, 2016 5:53 pm

That would help a lot :)

The domoticz output is in json format and most of the values sent are irrelevant, but the important values depend on the device unfortunately. Here's a documented log:
https://gist.github.com/WoLpH/dd12451e6 ... 064f60b4ff

It would definitely have to filter on the idx and beyond that, depending on the device type on nvalue or svalue it seems.
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Domoticz plugin

Post by krambriw » Thu Oct 06, 2016 7:54 am

Hello,
So I made a first testing version following the json structure you provided. It has a dependency that the word 'domoticz' must be found in the msg.topic in messages from domoticz
__init__.py
(35.12 KiB) Downloaded 276 times
Typically you will receive the following events for Domoticz where now only the values are kept

Code: Select all

09:17:08   MQTT./1wire/domoticz/Light/Switch [255, 12, 'Light/Switch', '00001201', 195, 'licht bureaus', 2, 'Switch', '68', 'Dimmer', 1]
09:17:08   MQTT./1wire/domoticz/General [255, 12, 'General', '00000701', 78, 'kWh pc media', 0, 'kWh', '226.200', '654594.750', 1]
Based on this you could create a macro structure and extract whatever values from the list in the payload using simple python scripts
Skärmklipp.JPG
Skärmklipp.JPG (17.97 KiB) Viewed 6366 times
If you think we need a more specific event suffix to be able to directly trigger individual actions on state changes without using python scripts it can easily be made. Like for instance

MQTT./1wire/domoticz/Light/Switch/On/Off/57/0
and
MQTT./1wire/domoticz/Light/Switch/On/Off/57/1

BR Walter

Post Reply