Thanks again for your help and not just showing me the easy way. This way I learn a lot more.
This is what I have managed to do so far.
First I created two variables.
Function: Variable
Name:
DoorLockState Value:
0 or
255Function: Variable
Name:
DoorLockStateReadable Value:
On or
OffThen I created 3 action group items.
1.
Function: Action Group
Name:
Lock the main doorType1: Embedded Python Script
- Code: Select all
import urllib, urllib2
urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x62].Set(255)")
Type2: Modify Variable (Variable Actions)
Variable:
DoorLockStateReadableSet to:
On 2.
Function: Action Group
Name:
Unlock the main doorType1: Embedded Python Script
- Code: Select all
import urllib, urllib2
urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x62].Set(0)")
Type2: Modify Variable (Variable Actions)
Variable:
DoorLockStateReadableSet to:
Off 3
Function: Action Group
Name:
DoorLock - state queryType: Embedded Python Script
- Code: Select all
import urllib, urllib2
urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.Get()")
The
DoorLock - state query will force the RaZberry controller to query the door lock state and update itself.
I then created a scheduled event called
Door Lock - State Update that will read the state of the DoorLock on the RaZberry and then update the
DoorLockState variable with either
0 or
255 depending on the lock state (0 = Unlocked 255=Locked) every minute. I will try to decrease the time to 30 seconds or less for a more accurate result, but for now I just want to see that it works and I will do the tweaking later.
Function: Scheduled Event
Name:
DoorLock - read stateTime: Every
1 minute
Type: Embedded Python Script
- Code: Select all
import urllib2
import simplejson
var1 = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")
var2 = var1.read()
indigo.variable.updateValue(1740577043, value=str(var2))
I also created two trigger events that will update the
DoorLockStateReadable variable with On or Off depending on the
DoorLockState variable. This is to make the result readable for the Virtual On/Off device.
Function: Trigger Event
Name:
DoorLockState - LockedTrigger: Variable Changed
Variable:
DoorLockStateBecomes equal to:
255Condition: Always
Actions: Modify Variable (Variable Actions)
Variable:
DoorLockStateReadableSet to:
OnFunction: Trigger Event
Name:
DoorLockState - UnlockedTrigger: Variable Changed
Variable:
DoorLockStateBecomes equal to:
0Condition: Always
Actions: Modify Variable (Variable Actions)
Variable:
DoorLockStateReadableSet to:
OffLastly, I created a Virtual Device called
Door Lock with these preferences:
Function: Virtual On/Off Device
Name:
Door LockExecution Model: Action Groups
On Group:
Lock the main doorOff Group:
Unlock the main doorStatus Variable:
DoorLockStateReadableStatus Group:
DoorLock - state queryLocking and unlocking the door works good and the link between RaZberry and Indigo is very reliable. If the state of the door lock changes manually by human interference the status on the virtual device will also update within 1 minute (I will try to decrease this number when I get some time for tweaking).
I believe there is something I can do better with the state update so I don't need 2 variables and two triggers to get a readable result for the Virtual Device, but for me to do that I need some help with Python Scripting and JSON.
In the script below as I understand it json reads the output from urllib2 and then adds the value to the indigo.variable. Now, is there a way to get json to convert the value depending on the output from urllib2 before it adds the value to the indigo.variable? So if output is 0 json will convert that to Off and then add it to indigo.variable, but if its 255 it will be converted to On instead. Is this possible
- Code: Select all
import urllib2
import simplejson
var1 = urllib2.urlopen("http://192.168.11.9:8083/ZWaveAPI/Run/devices[2].DoorLock.data.mode.value")
var2 = var1.read()
indigo.variable.updateValue(1740577043, value=str(var2))
And as I understand it the Virtual On/Off Device can only use On/Off as status? So if I want to use Locked/Unlocked I need to create a plugin. Is that correct?
PS: Please take into consideration that this is my first Virtual Device I have ever created with Indigo and if you see something wrong or stupid then don't hesitate to speak your mind about it. That is the only way I can learn.