Author Topic: Trigger VC events from Domoticz  (Read 3387 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Trigger VC events from Domoticz
« on: February 28, 2016, 04:06:20 PM »
There are a variety of ways to trigger events in VC from Domoticz.  One way is to use a lua script together with udpsender.exe, which is part of the"Extra utilities" package available on VoxCommando's Downloads page (http://voxcommando.com/home/downloads/)

In the lua script, you can call on the udpsender.exe, which will then send a UDP message to VC (in this case, to trigger events).

Attached to this post is an example lua script called "script_device_VcNotifications".

DO NOT change the name of the attached lua file unless you know what you're doing.

1. If you haven't yet done so, then download the Extra utilities package and put the udpsender program somewhere accessible on your Domoticz machine such as C:\Users\USERNAME\...
2. Put the lua file in C:\Program Files (x86)\Domoticz\scripts\lua (or whatever the correct file path is for your Domoticz installation).
3. Edit the script in Notepad or whatnot, to correct the filepath in the line:
Code: [Select]
UDPfilepath = 'C:/Users/USERNAMEHERE/udpsender.exe' --REPLACE WITH THE CORRECT FILE PATH ON YOUR COMPUTER

That's all you should need to do. Whenever you switch a device on or off, a "Domoticz.state" event should now be generated in VC. It will have 2 payloads: {1} the name of the device, {2} the state of the device.

Here is a very basic example of using an event-triggered command:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<command id="266" name="announcing all state changes" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Change &quot;Living Room Light&quot; to name of your switch. *case sensitive*!">
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>The device {1} is now:</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{2}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>Domoticz.state</event>
</command>
« Last Edit: February 29, 2016, 10:22:16 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: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Trigger VC events from Domoticz
« Reply #1 on: January 28, 2017, 07:04:43 PM »
I keep forgetting to provide the alternative method. This way is probably better.

You need to have VC's TCP plugin enabled, and within the TCP plugin settings enable the Simple Web Server.

Use the attached lua file instead of the one above. As always, the lua file goes in C:\Program Files (x86)\Domoticz\scripts\lua (or whatever the correct file path is for your Domoticz installation).

Some silly commands demonstrating how these events work:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.4-->
<commandGroup open="True" name="Domoticz event-triggered examples" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="261" name="Say hello if living room light is switched on" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Change &quot;Living Room Light&quot; to name of your switch. *case sensitive*!">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{1} {2}&amp;&amp;Living Room Light On</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>Hi there! {1} is now {2}. I guess you must be in the room. :)</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Hi there! {1} is now {2}. I guess you must be in the room.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <event>Domoticz.Device*</event>
  </command>
  <command id="266" name="announcing all state changes" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Change &quot;Living Room Light&quot; to name of your switch. *case sensitive*!">
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>The device {1} is now:</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>{2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Domoticz.Device*</event>
  </command>
</commandGroup>
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)