#
Version 0.6
Added function Save-FileData
this will allow you to save all requests to file.
Version 0.5
Written by Markus Jakobsson
www.Corepoint.se
This script should run on an X64 computer with Telldus, it will create a web interface that allows you to turn devices on or off from cellphones or computers on the same network
Change the port to a port you like
Change to the ip address to the address on your Telldus server
Add an firewall exception to allow the desired port.
Run this script from Powershell ISE
Access the page from http://”serverip”:”port”
The web engine are rewritten but originally created and described in this book by
Bruce Payette’s, "PowerShell in action", this was the book I learned Powershell from! Read it if you are interested in learning more about Powershell
#>
param ($port=86,$serverIP="172.20.0.25")
$DebugPreference = "continue"
[void][reflection.Assembly]::loadWithPartialName("system.net.sockets")
# This will allow you to save all information.
$LogEnabled = $true
$loggpath = "D:\Test\" # Path where you want files to be saved.
$Loggfilename = "Response.Log" # filename to use
$loggAppend = $true # select if you want the file to be appended or not
function CreateWebHead ($content,$title = "www.Corepoint - Telldus Web Engine")
{
#Följande funktion används för att bygga huvudet på sidan.
@"
$title
"@
}
# This part will allow you to save information to files, it will append data
function Save-FileData {
[cmdletbinding()]
param(
[string]$filepath, # path where you want the file to be saved
[string]$Filename, # name of the file SensorX.log
[string]$FileData # data to send into logfile
)
begin{
if (!(Test-Path $filepath)){New-Item -Path $filepath -ItemType directory | Out-Null; Write-Verbose "Creaded folder $filepath"}
}
process{
if ($loggAppend){
Out-File -InputObject $FileData -FilePath (Join-Path -Path $filepath -ChildPath $Filename) -Append
} else {
Out-File -InputObject $FileData -FilePath (Join-Path -Path $filepath -ChildPath $Filename)
}
}
}
function Change-Telldusstatus {
# This sets the status on the given Telldus device.
[cmdletbinding()]
param(
[string]$givare, # device
[string]$newMode # new mode
)
begin {Write-Debug "[Change-Telldusstatus]`$givare = $givare, `$newMode = $newmode"}
process{
try {
# Verify that the registry key exist before changing mode.
if(Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Telldus\Devices\$givare){
# If the device exist the ON / Off section will run depending on the “newmode” data
if ($newmode -eq "ON"){
Write-Debug "[Change-Telldusstatus] ON $givare"
&"C:\Program Files (x86)\Telldus\tdtool.exe" --on $($givare)
} elseif ($newMode -eq "OFF"){
Write-Debug "[Change-Telldusstatus] OFF $givare"
&"C:\Program Files (x86)\Telldus\tdtool.exe" --off $($givare)
} else {Write-warning "[change-telldusstatus] You written something other then ON or OFF"}
Write-Debug "[Change-Telldusstatus] Changing mode on $givare to $newMode"
} else {
# Missing that Telldus device in registry.
}
}
catch{
}
}
}
function get-KorrektaTecken {
param(
[string]$TextAttKorrigera
)
# This part will replace the Swedish characters ÄÅÖ to correct web characters
$TextAttKorrigera = $TextAttKorrigera -creplace 'Å','Å' #
$TextAttKorrigera = $TextAttKorrigera -creplace 'Ä','Ä' #
$TextAttKorrigera = $TextAttKorrigera -creplace 'Ö','Ö' #
$TextAttKorrigera = $TextAttKorrigera -creplace 'å','å' #
$TextAttKorrigera = $TextAttKorrigera -creplace 'ä','ä' #
$TextAttKorrigera = $TextAttKorrigera -creplace 'ö','ö' #
$TextAttKorrigera
}
function Get-TelldusGivare {
# This part will collect all devices and give them a red or green status color.
begin {
$givare = get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Telldus\Devices | Select-Object -ExpandProperty PSChildName | ForEach-Object {
Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Telldus\Devices\$_ | Select-Object pschildname, state, name
}
}
process {
$Telldus = foreach ($telldusenhet in $($givare | sort-object state, name)){
if ($telldusenhet.state -eq 1){$tablecolor = "#40FF00";$hreflink = "?$($telldusenhet.PSChildName)-OFF";} else {$tablecolor = "red";$hreflink = "?$($telldusenhet.PSChildName)-ON";}
@"
ON |
$($telldusenhet.name) |
OFF |
"@
}
}
end {$Telldus}
}
function CreateWebBody {
# Creating the body of the webpage
@"
"@
}
function CreateWebFotter {
# Creating the bottom of the webpage
@"