Author Topic: Domoticz Home Automation and VC  (Read 16469 times)

0 Members and 1 Guest are viewing this topic.

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Domoticz Home Automation and VC
« on: March 04, 2014, 05:49:20 AM »
Hello all,

I am starting my home automation project using Domoticz software and its API/JSON URL`s can be found here: http://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

I was wondering how to access Domoticz from VoxCommando ?! .. as I understand XJSON plugin is intended only to be used with XBMC. Should I be using RoboB ?! If RoboB is the way to go, how would I be able to read info from Domoticz`s interface (i.e.: status of a device).

Thank you so much for your time and the great application.

Nodo

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Domoticz Home Automation and VC
« Reply #1 on: March 04, 2014, 08:07:08 AM »
Hello Nodo. Welcome to the VC forum.

Looks like you'll be able to use the scrape action with little difficulty. http://voxcommando.com/mediawiki/index.php?title=Home_Automation

If you want to do something with the actual results, you'll probably need to use regular expressions (regex). http://voxcommando.com/mediawiki/index.php?title=Actions#RegEx

Give it a whirl, and if you need help with specifics once you've experimented, let us know. If you're having difficulty with the regex, you'll need to post or attach some examples of the results you're getting.
« Last Edit: March 04, 2014, 08:11:24 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Domoticz Home Automation and VC
« Reply #2 on: March 04, 2014, 10:16:56 AM »
... Just noticed the documentation regarding authorization, which may complicate things, but give it a try and get back to us.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #3 on: March 04, 2014, 10:38:53 AM »
You can try including the username and password in the url as shown in the domoticz documentation, or if that does not work, then you can try instead to put the username and pass in the scrape action's optional 2nd and 3rd parameter boxes.  Hopefully one of those two methods will work.

Once (if) you are able to get it working, we can make some suggestions on how to streamline things a little bit.

For one thing, you may want to store the first part of the URL in a map variable so that you don't have to keep writing out the whole thing in all your actions, and so that if your server's IP changes you won't need to edit all your actions; you will be able to just update the map variable once.

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Re: Domoticz Home Automation and VC
« Reply #4 on: March 05, 2014, 09:51:13 AM »
Hello Nodo. Welcome to the VC forum.

Looks like you'll be able to use the scrape action with little difficulty. http://voxcommando.com/mediawiki/index.php?title=Home_Automation

If you want to do something with the actual results, you'll probably need to use regular expressions (regex). http://voxcommando.com/mediawiki/index.php?title=Actions#RegEx

Give it a whirl, and if you need help with specifics once you've experimented, let us know. If you're having difficulty with the regex, you'll need to post or attach some examples of the results you're getting.

You can try including the username and password in the url as shown in the domoticz documentation, or if that does not work, then you can try instead to put the username and pass in the scrape action's optional 2nd and 3rd parameter boxes.  Hopefully one of those two methods will work.

Once (if) you are able to get it working, we can make some suggestions on how to streamline things a little bit.

For one thing, you may want to store the first part of the URL in a map variable so that you don't have to keep writing out the whole thing in all your actions, and so that if your server's IP changes you won't need to edit all your actions; you will be able to just update the map variable once.


First off, Thank you for the quick and informative response nime5ter and jitterjames :).

I will delve into VC`s tutorials today and see what I can come up with and let you guys know how it went.


jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #5 on: March 05, 2014, 10:34:30 AM »
Cool.  FYI we did some tests and it works well.  There is a lot that can be done with domoticZ.  It is possible to scan all your devices and automatically generate maps with their corresponding IDs etc. check current device status etc.  I don't know if it is possible to send events from domoticZ to VC but probably it is.

...but I did not want to overload a newbie with too much information at once.  Walk before you can run.  So try to familiarize yourself with VC and do some simple tests using the scrape actions and then get back to us and we can take it to the next level! :D

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Re: Domoticz Home Automation and VC
« Reply #6 on: March 06, 2014, 09:23:21 AM »
Just as an update, DomoticZ username and password works fine when passed to scrape actions 2nd and 3rd parameters, however I am having a hard time keeping the username and password in a map variable, On the other hand keeping the first part of the url including the port works like a charm.

I have been playing around with VC and I was able to get VC to scan DomoticZ devices and automatically generate a map with their corresponding IDs. I attached the command tree as I was wondering if there is an easier approach to save the IDs rather than using Results.SetVar ?!

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="428" name="Set/Update Devices" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PayloadXML.NewFile</cmdType>
    <cmdString>C:\xx\vox\domoticZ\DZDvcIDx.xml</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PayloadXML.Clear</cmdType>
    <cmdString>C:\xx\vox\domoticZ\DZDvcIDx.xml</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://{M:LightsMap.url}/json.htm?type=devices&amp;filter=light&amp;used=true&amp;order=Name</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <cmdString> "idx"\s:\s"(.)"</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <cmdString>{Var.{i}}&amp;&amp;{Match.{i}}</cmdString>
    <cmdRepeat>{#M}</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <cmdString> "Name"\s:\s"(.*?)"</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PayloadXML.AddPair</cmdType>
    <cmdString>C:\xx\vox\domoticZ\DZDvcIDx.xml&amp;&amp;{Var.{i}}&amp;&amp;{Match.{i}}</cmdString>
    <cmdRepeat>{#M}</cmdRepeat>
  </action>
</command>

« Last Edit: March 06, 2014, 09:40:55 AM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #7 on: March 06, 2014, 09:50:40 AM »
...I am having a hard time keeping the username and password in a map variable, On the other hand keeping the first part of the url including the port works like a charm.
That's weird.  I wonder what you are doing differently.  Obviously you would need a variable for each.

I have been playing around with VC and I was able to get VC to scan DomoticZ devices and automatically generate a map with their corresponding IDs. I attached the command tree as I was wondering if there is an easier approach to save the IDs rather than using Results.SetVar ?!
I like what you have done with the regex.  It looks like it should work fine.  Another method would be to use the python plugin which can parse the json into a data structure and then loop through the items.

I'm not sure which would be "easier", but the python method might allow you more room for error correction if the json returned from domoticZ was not always so predictable.

I feel I should mention: you are scanning DomoticZ devices and automatically generating a payloadXML file, not a map.  They are similar but still two different things.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #8 on: March 06, 2014, 09:58:32 AM »
Here is a method using python. (you must enable the python plugin to use it)

This VC command will scrape the device list, and then call a python script to process it.  You need to put the attached file into your VC\Py folder.

The python script will actually create a map table with your devices in it.  Afterwards, from the map editor you can easily export the map to a payloadXML file.  In future releases I will add an action to export a map to a payloadXML file so you don't have to do it manually.

Apart from being much faster than adding to a payloadXML file, by using a map we can "merge" new devices without overwriting existing ones.

the action Map.Set has an optional parameter for "overwrite".  If this param is set to false, then when a key exists in the map already it will be untouched.  If the key does not exist, then a new item will be created.  This is handy because you might want to edit the names of your devices to make them work better as voice commands, or maybe created aliases for them (using commas) and you would not want to have to redo that editing every time you re-scanned for new devices.


Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="165" name="list devices" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://127.0.0.1:8081/json.htm?type=command&amp;param=getlightswitches&amp;&amp;test&amp;&amp;test</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <cmdString>PY\dzParseData.py</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>
« Last Edit: March 06, 2014, 10:01:53 AM by nime5ter »

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Re: Domoticz Home Automation and VC
« Reply #9 on: March 06, 2014, 10:04:48 AM »
Code: [Select]
<action>
    <cmdType>Results.SetVar</cmdType>
    <cmdString>{Var.{i}}&amp;&amp;{Match.{i}}</cmdString>
    <cmdRepeat>{#M}</cmdRepeat>
 </action>

The odd thing is that at first it worked fine but now somehow Results.SetVar does not pass the variables from {Match.{i}} to {Var.{i}}. I had to use OSD.ShowText to pinpoint that the problem came from Results.SetVar action.

I feel I should mention: you are scanning DomoticZ devices and automatically generating a payloadXML file, not a map.  They are similar but still two different things.

My bad :).. Thank you for mentioning it.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #10 on: March 06, 2014, 10:09:21 AM »
I had to use OSD.ShowText to pinpoint that the problem came from Results.SetVar action.
I would need to see it in action to know what you mean.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #11 on: March 06, 2014, 10:17:18 AM »
It is possible to capture multiple things with the regex usinga a pattern like this:

blahblah(.*?)blahblah(.*?)blahblah

but currently they get concatenated into {Match.1} using the optional joiner between them.  I think I will add the ability to access them individually using {Match.1.1} and {Match.1.2}  ...or {Match{i}.1} and {Match{i}.2}

The way I have solved this in the past would be to send the joined match to a second command using Results.MatchToEvent.  The second command would then slit the two parts of the match into the key and value, and add them to the payloadXML file or to a map table.  Here is an example of the technique: http://voxcommando.com/forum/index.php?topic=1281.msg11068#msg11068

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Domoticz Home Automation and VC
« Reply #12 on: March 06, 2014, 10:30:55 AM »
The odd thing is that at first it worked fine but now somehow Results.SetVar does not pass the variables from {Match.{i}} to {Var.{i}}. I had to use OSD.ShowText to pinpoint that the problem came from Results.SetVar action.

Hi Nodo,

I can't test it, but I think I'm seeing the culprit. It looks like you're calling a variable while initially trying to set the variable. See image to compare to what you have.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Nodo

  • Jr. Member
  • **
  • Posts: 22
  • Karma: 6
    • View Profile
Re: Domoticz Home Automation and VC
« Reply #13 on: March 06, 2014, 10:55:56 AM »
It is possible to capture multiple things with the regex usinga a pattern like this:

blahblah(.*?)blahblah(.*?)blahblah

but currently they get concatenated into {Match.1} using the optional joiner between them.  I think I will add the ability to access them individually using {Match.1.1} and {Match.1.2}  ...or {Match{i}.1} and {Match{i}.2}


Great info.. actually I kept scratching my head for a way to create a separate XML for different types of devices using regex (i.e. Dimmable lights, Switches, Sensors) just like the VERA plugin, I think it would be much easier to be done using Python.. although I admit my experience with Python is quite limited at this stage.

Hi Nodo,

I can't test it, but I think I'm seeing the culprit. It looks like you're calling a variable while initially trying to set the variable. See image to compare to what you have.


Hello nime5ter,

You are spot on, that solved it and regex is now working.. do not know though if I should continue using regex or Python, guess I should continue playing around and see what I can come up with.

Thank you so much for all your help and hopefully you would not be bothered with all the questions that will be coming your way :D.
« Last Edit: March 06, 2014, 10:57:59 AM by Nodo »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Domoticz Home Automation and VC
« Reply #14 on: March 06, 2014, 10:59:53 AM »
Hey no problem.  We are enjoying your questions.

I suggest you try out the python.  I think you will find it is quite easy to modify it to work with other devices as well.

You could even move the scrape action into the python code, and then you could do many requests in a row, first lights, then dimmable, then fans, etc. (not sure if that makes sense for domoticZ but you get the idea) all in one python script.