Ny versjon (igjen )!
Velger å bare dele den her og la første post stå som den er.
Den nye versjonen benytter "Pushover"-plugin for meg og IFTTT for samboeren.
Skulle man ønske å endre begge til Pushover, så er det også kurant.
Sub Main(ByVal params as Object)
' @Author: Sven-Ove Bjerkan
' @Version: 5 (2018-02-01)
' @Syntax: him|her|message|priority|deviceid
' Values for "him"/"her":
' 0 = no notify
' 1 = if home
' 2 = if away
' 3 = always notify
' Replacement-variables in "message":
' %name%, %value%, %string%, %loc1%, %loc2%
' priority is default "normal", could be "low", "normal", "high" or "emergency"
' deviceid is optional
' SETTINGS
Dim identifierHim As String = "f.eks iPhone - device må finnes i pushover og i plugin"
Dim identifierHer As String = "IFTTT-key"
Dim deviceHimHome As Integer = 0
Dim deviceHerHome As Integer = 0
Dim isHomeValue as Integer = 1
Dim isAwayValue as Integer = 0
Dim parameters() as String = params.ToString.Split("|")
Dim him As Integer = parameters(0)
Dim her As Integer = parameters(1)
Dim message As String = parameters(2)
Dim deviceid As Integer = 0
Dim pri As String = "normal"
If parameters.length = 4 Then
pri = parameters(3)
End If
If parameters.length = 5 Then
deviceid = parameters(4)
End If
Dim dvName As String
Dim dvString As String
Dim dvLoc1 As String
Dim dvLoc2 As String
Dim dvValue As Long
If deviceid <> 0 Then
dvValue = hs.DeviceValue(deviceid)
' Strip HTML from DeviceString
dvString = System.Text.RegularExpressions.Regex.Replace(hs.DeviceString(deviceid),"<(.|\n)*?>",String.Empty)
Dim dv As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(deviceid)
dvLoc1 = dv.Location(Nothing)
dvLoc2 = dv.Location2(Nothing)
dvName = dv.Name(Nothing)
message = message.Replace("%name%",dvName).Replace("%value%",dvValue).Replace("%string%",dvString).Replace("%loc1%",dvLoc1).Replace("%loc2%",dvLoc2)
End If
Dim urlHer As String = "https://maker.ifttt.com/trigger/notify/with/key/" & identifierHer & "?value1=" & message
Dim alertHim As Boolean = False
Dim alertHer As Boolean = False
'' if he's home
If him = 1 And hs.DeviceValue(deviceHimHome) = isHomeValue Then
alertHim = True
End If
'' if he's away
If him = 2 And hs.DeviceValue(deviceHimHome) = isAwayValue Then
alertHim = True
End If
'' always notify him
If him = 3 Then
alertHim = True
End If
'' if she's home
If her = 1 And hs.DeviceValue(deviceHerHome) = isHomeValue Then
alertHer = True
End If
'' if she's away
If her = 2 And hs.DeviceValue(deviceHerHome) = isAwayValue Then
alertHer = True
End If
'' always notify her
If her = 3 Then
alertHer = True
End If
If alertHim Then
Dim pushArr(8) As Object
pushArr(0) = identifierHim
pushArr(1) = message
pushArr(2) = "HomeSeer"
pushArr(3) = pri
pushArr(4) = Nothing
pushArr(5) = Nothing
pushArr(6) = Nothing
pushArr(7) = Nothing
pushArr(8) = Nothing
hs.PluginFunction("Pushover 3P", "", "Pushscript", pushArr)
hs.WriteLog("Info", "Sending Pushover-notify to him (" & message & " / pri: "& pri & ")")
End If
If alertHer Then
hs.URLAction(urlHer, "GET", "", "")
hs.WriteLog("Info", "Sending IFTTT-notify to her (" & message & ")")
End If
End Sub
Har forresten også funnet ut at det opprinnelig scriptet enkelt kan brukes til å sende SMS i stedet for IFTTT-push - bare sett opp "that" til SMS i stedet for "Notification".