manwithavan wrote:Yes please! Keen to try it out....
No problem...
A little background. On the Denkovi model I am using, DO 9 to 13 correspond to Relays 1 to 5. I used DO 9 to control Relay 1. I used the Common (COM) and Normally Open (NO) contacts to switch the power to my real device, a pump. There are two external interfaces available for controlling the Denkovi products: HTTP (json or xml) and SNMP. I chose SNMP mostly because I was not that familiar with it and wanted a chance to see how it worked, But, I could have just as easily used HTTP (via
curl.
Since I was going to use the Indigo built-in
Virtual Device type, I first needed to create Action Groups to perform the necessary functions: On, Off, Toggle, and Status. I also needed to create a variable for Indigo to watch to update the virtual device's state.
For the Action Groups I used the action type
Run Shell Script (Sscipt and File Actions). For the On action Group, the "Shell Script*" I entered was:
- Code: Select all
/usr/bin/snmpset -v1 -c private 192.168.1.10 .1.3.6.1.4.1.42505.1.2.3.1.11.8 i 1
Where:
/usr/bin/snmpset is a command included in MacOS that can send SNMP requests.
192.168.1.10 is the IP address of my Denkovi switch.
.1.3.6.1.4.1.42505.1.2.3.1.11.8 is the OID (SNMP Object) for DO 9 (the DOs are internally numbered starting with 0, so .8 is DO 9 and DO 1 would end with .0)
i indicates that the value to be assigned to the OID is an integer
1 is the actual value to assign (0 = off, 1 = on and 2 = toggle)
So, executing this Action Group will turn on DO 9 and, on my switch, the associated Relay, 1.
The Off action is similar except the final digit is a
0.
For the status Action Group I used another command,
snmpget. This is similar to snmpset, but is intended to read information rather than set information. The "Shell Script" I used here was:
- Code: Select all
/usr/bin/snmpget -v1 -Ovq -c private 192.168.1.10 .1.3.6.1.4.1.42505.1.2.3.1.11.8|/usr/bin/tr -d "\n"
The extra option
-Ovq is used to suppress all output except the actual state value (0 or 1). The tr command at the end is to remove the trailing newline character - which confuses Indigo. Again, the last digit corresponds to the DO number, starting with 0. I also check the
Store result in variable option to use to track the device state. I created the Indigo variable:
pumpState. Note: This command will log an error in the Indigo log, just ignore it. it is due to the way the newline is removed.
The Toggle Action Group was slightly more complicated, since the end-state of the DO is not directly determined by the snmpset command. So, I used two Run Shell Script commands in the Action group. The first was:
- Code: Select all
/usr/bin/snmpget -v1 -c private 192.168.1.10 .1.3.6.1.4.1.42505.1.2.3.1.11.8
Note there is no value since it is not required for the toggle function. The second "Shell Script" command was the same as used in the Status Action Group, and the save results option was also checked. So, after toggling the DO state, the second scripts checks to see what the new state is and saves it to a variable.
Finally, you need to create the Indigo Virtual Device. All you have to do for the various options is select the Action Groups and variable you created.
Let me know if you have any questions. Also, there is a way around the "status" error. But, it requires using a Python script in place of the snmpget command and, other than suppressing the error, adds no functionality.
* Although the Action option is named "Run Shell Script" it actually executes a Unix command line and is not limited to shell scripts. That is why it works with the snmpset and snmpget commands.