Skip to content

Instantly share code, notes, and snippets.

@ehrnst
Created October 1, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehrnst/49cd1d4cf40a21c6f0964c91a305efe0 to your computer and use it in GitHub Desktop.
Save ehrnst/49cd1d4cf40a21c6f0964c91a305efe0 to your computer and use it in GitHub Desktop.
Azure Funtion to start webasto heater with Altox WBUS
#Azure functions powershell http trigger
#Get input
$input = Get-Content $req -Raw | ConvertFrom-Json
[int]$tempLow = $input.tempLow
[int]$heatingMinutes = $input.heatingMinutes
function send-altoxCommand {
param (
[Parameter(Mandatory = $true)]
$command,
[Parameter(Mandatory = $true)]
$pass,
[Parameter(Mandatory = $true)]
$email,
[Parameter(Mandatory = $true)]
$id
)
$timezone = "+2hour"
$uri = "https://altox.ru/track/app_heater.php?cmd=$command&id=$id&email=$email&pass=$pass&timezone=$timezone"
Invoke-RestMethod -Method Get -Uri $uri
}
# requesting heater status and temperature. letting the controller have 10 seconds to process our command.
send-altoxCommand -command cmd_heater_status -pass $env:heaterPass -email $env:heaterEmail -id $env:heaterID
start-sleep 10
$status = (send-altoxCommand -command 1 -pass $env:heaterPass -email $env:heaterEmail -id $env:heaterID).app
$currentTemp = $status.h_temp
#If heater temperature is below or equal to set low temp. start heater.
#this will prevent heater from starting if parked in garage or similar
if ($currentTemp -le $tempLow) {
send-altoxCommand -command "cmd_time1:$heatingMinutes,start" -pass $env:heaterPass -email $env:heaterEmail -id $heaterID
$Output = "Heater temperature, $currenttemp is low. Sending command to start heater for $heatingMinutes minutes"
}
else {
$output = "Current temp ($currenttemp) is to high. Did not send start command"
}
Out-File -Encoding Ascii -FilePath $res -inputObject $output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment