Autoit3 example scripts to switch circles on Stretch 2.0

Plugwise Forum about Plugwise devices and the Source software.
Post Reply
Phoenix
Starting Member
Starting Member
Posts: 48
Joined: Sun Apr 28, 2013 9:40 pm
Location: Netherlands (Deventer)
Contact:

Autoit3 example scripts to switch circles on Stretch 2.0

Post by Phoenix »

Hi All,

Here i have made some example Autoit3 scripts to switch circles with the Plugwise Stretch 2.0, you can adjust these script easily to VB.NET or PHP!
Also on my website here: http://phoenixinteractive.mine.nu/websi ... f=27&t=117

Have fun!

Autoit3 script to switch Plugwise Circles with a Stretch 2.0 with firmware 1.0.x

Code: Select all

------------------------------------------------------------------------------
; Autoit3 script to switch Plugwise Circles with a Stretch 2.0 with firmware 1.0.x)
; v1.0, 2012-04-28 by Sebastiaan Ebeltjes
; Greetings from Deventer, The Netherlands
; ------------------------------------------------------------------------------

; Stretch 2.0 setup
Global $StretchIp = "192.168.1.102" ;The IP adres of the Stretch 2.0, like: 192.168.1.X
Global $StretchId = "STRETCHID" ; The 8 letters of the Stretch 2.0 ID

; Switch setup (circle)
Global $ApplianceId = "71abf031c54f400ca77c8ae6957ad7cf" ;The ID of the circle, look in http://[STRETCHIP]/minirest/appliances
Global $SwitchStatus = "on" ;on/off

; Kernel
Global $PostAdres = "http://" & $StretchIp & "/minirest/appliances;id=" & $ApplianceId & "/power_state=" & $SwitchStatus

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", $PostAdres, False)
$oHTTP.SetRequestHeader("Host", $StretchIp)
$oHTTP.SetRequestHeader("Authorization", "Basic " & _Base64Encode("stretch:" & $StretchId))
$oHTTP.Send()
Global $PostResponse = $oHTTP.ResponseText

If $oHTTP.Status <> "200" Then MsgBox(64, "Foutmelding", $PostResponse)
Exit


Func _Base64Encode($sData)
    Local $oXml = ObjCreate("Msxml2.DOMDocument")
    If Not IsObj($oXml) Then
        SetError(1, 1, 0)
    EndIf

    Local $oElement = $oXml.createElement("b64")
    If Not IsObj($oElement) Then
        SetError(2, 2, 0)
    EndIf

    $oElement.dataType = "bin.base64"
    $oElement.nodeTypedValue = Binary($sData)
    Local $sReturn = $oElement.Text

    If StringLen($sReturn) = 0 Then
        SetError(3, 3, 0)
    EndIf

    Return $sReturn
EndFunc

Autoit3 script to switch Plugwise Circles with a Stretch 2.0 with firmware 2.0.x

Code: Select all

; ------------------------------------------------------------------------------
; Autoit3 script to switch Plugwise Circles with a Stretch 2.0 with firmware 2.0.x)
; v1.0, 2013-10-07 by Sebastiaan Ebeltjes
; Greetings from Deventer, The Netherlands
; ------------------------------------------------------------------------------

 ; Stretch 2.0 setup
Global $StretchIp = "192.168.1.102" ;The IP adres of the Stretch 2.0, like: 192.168.1.X
Global $StretchId = "STRETCHID" ; The 8 letters of the Stretch 2.0 ID

; Switch setup (circle)
Global $ApplianceId = "71abf031c54f400ca77c8ae6957ad7cf" ;The ID of the circle, look in http://[STRETCHIP]/core/appliances
Global $SwitchStatus = "on" ;on/off

; Kernel
Global $PostAdres = "http://" & $StretchIp & "/core/appliances;id=" & $ApplianceId & "/relay"
Global $PostGegevens = "<relay><state>" & $SwitchStatus & "</state></relay>"

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", $PostAdres, False)
$oHTTP.SetRequestHeader("Host", $StretchIp)
$oHTTP.SetRequestHeader("Connection", "Close")
$oHTTP.SetRequestHeader("Content-Type", "application/xml")
$oHTTP.SetRequestHeader("Authorization", "Basic " & _Base64Encode("stretch:" & $StretchId))
$oHTTP.Send($PostGegevens)
$PostResponse = $oHTTP.ResponseText

If $oHTTP.Status <> "200" Then MsgBox(64, "Foutmelding", $PostResponse)
Exit

Func _Base64Encode($sData)
    Local $oXml = ObjCreate("Msxml2.DOMDocument")
    If Not IsObj($oXml) Then
        SetError(1, 1, 0)
    EndIf

    Local $oElement = $oXml.createElement("b64")
    If Not IsObj($oElement) Then
        SetError(2, 2, 0)
    EndIf

    $oElement.dataType = "bin.base64"
    $oElement.nodeTypedValue = Binary($sData)
    Local $sReturn = $oElement.Text

    If StringLen($sReturn) = 0 Then
        SetError(3, 3, 0)
    EndIf

    Return $sReturn
EndFunc ;_Base64Encode
Huisautomatisering - Domotica - Elektronica - IT consulting - Software ontwikkeling - 3D printing - Maatwerk
Website: domoticx.nl / Webshop: domoticx.nl/webwinkel / Knowledge Center: http://domoticx.com
Post Reply

Return to “Plugwise Forum”