Author Topic: Domoticz switches -- generate payload xml for switches & turn switches on/off  (Read 2084 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
---
Unless you already have a good understanding of http requests, home automation, and VC, please start by reviewing Nodo's great, brief intro to Domoticz + VC:

http://voxcommando.com/forum/index.php?topic=2405.0

--
NOTE: You'll need to replace the Domoticz server IP address and port number in these commands with your own.

Personally, I store this info in a map table and access it as a map variable so that I don't have to type the address manually for every scrape action.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.6-->
<commandGroup open="True" name="Domoticz switches" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="173" name="Domoticz switch {1} to {2}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Scrape</cmdType>
      <params>
        <param>http://{M:Domoticz.serverIP:Port}/json.htm?type=command&amp;param=switchlight&amp;idx={1}&amp;switchcmd={2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Domoticz switch</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\domoticzSwitches.xml</payloadFromXML>
    <phrase optional="true">to</phrase>
    <payloadList>On,Off</payloadList>
  </command>
  <command id="149" name="Domoticz switches GenXML" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PayloadXML.Clear</cmdType>
      <params>
        <param>payloads\domoticzSwitches.xml</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Scrape</cmdType>
      <params>
        <param>http://{M:Domoticz.serverIP:Port}/json.htm?type=command&amp;param=getlightswitches</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegExSingle</cmdType>
      <params>
        <param>"Name"\s:\s"(.*?)".*?"Idx"\s:\s"(.*?)"</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.MatchToXML</cmdType>
      <params>
        <param>payloads\domoticzSwitches.xml</param>
        <param>True</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>GenXML switches</phrase>
  </command>
</commandGroup>
« Last Edit: April 04, 2016, 12:34:19 PM 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: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
I forgot to post this command before, but it's part of the same 'package'.

Ask for the status (i.e. 'on' / 'off') of your switches, once you've generated a payload XML for them. (See above)

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<command id="177" name="Get status of {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <params>
      <param>http://{M:Domoticz.serverIP:Port}/json.htm?type=devices&amp;rid={1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param> result.*?"Status"\s:\s"(.*?)",</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{PF.1} is {Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>TTS.Speak</cmdType>
    <params>
      <param>{PF.1} is {Match.1}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Get status of</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\domoticzSwitches.xml</payloadFromXML>
</command>

Nodo has previously posted a link to the Domoticz documentation, but here is the page I used to figure out the correct Scrape URLs to use for these commands:

https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
« Last Edit: February 28, 2016, 04:15:42 PM 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)