Originally posted by bmccluskey
View Post
Would love to see how you do it. Also the windows scripts sound nice.
import urllib2 from evohomeclient2 import EvohomeClient client = EvohomeClient('[B]EVOHOMEUSERNAME[/B]', '[B]EVOHOMEPASSWORD[/B]') posturl='http://emoncms.org/input/post.json?apikey=[B]EMONCMSAPIKEY[/B]&node=3&json={' for device in client.temperatures(): posturl=posturl+','+device['name']+' Temp:'+str(device['temp']) posturl=posturl+','+device['name']+' SetPoint:'+str(device['setpoint']) posturl=posturl+ '}' posturl=posturl.replace("{,", "{") posturl=posturl.replace(" ", "") response = urllib2.urlopen(posturl)
$UserName="[B]EVOHOMEUSERNAME[/B]" $Password="[B]EVOHOMEPASSWORD[/B]" $BaseURL="https://tccna.honeywell.com/WebAPI/emea/api/v1/" Function GetAccessToken { #Logon to the site and get the Access Token $url="https://tccna.honeywell.com/Auth/OAuth/Token" $postHeader = @{ "Authorization"="Basic YjAxM2FhMjYtOTcyNC00ZGJkLTg4OTctMDQ4YjlhYWRhMjQ5OnRlc3Q="; "Accept"="application/json, application/xml, text/json, text/x-json, text/javascript, text/xml" } $postParams = @{ "Content-Type"="application/x-www-form-urlencoded; charset=utf-8"; "Host"="rs.alarmnet.com/"; "Cache-Control"="no-store no-cache"; "Pragma"="no-cache"; "grant_type"="password"; "scope"="EMEA-V1-Basic EMEA-V1-Anonymous EMEA-V1-Get-Current-User-Account"; "Username"=$UserName; "Password"=$Password; "Connection"="Keep-Alive" } $Result=Invoke-WebRequest -Uri $url -Method POST -Body $postParams -Headers $postHeader return (ConvertFrom-Json $Result.Content).access_token } Function GetRequest ($RequestURL) { $postHeader = @{ "Authorization"="bearer " + $AccessToken; "applicationId"="b013aa26-9724-4dbd-8897-048b9aada249"; "Accept"="application/json, application/xml, text/json, text/x-json, text/javascript, text/xml" } $URL=$BaseURL+$RequestURL $Result=Invoke-WebRequest -Uri $URL -Headers $postHeader return ConvertFrom-Json $Result.Content } Function PutRequest ($RequestURL,$PutData) { $postHeader = @{ "Authorization"="bearer " + $AccessToken; "applicationId"="b013aa26-9724-4dbd-8897-048b9aada249"; "Accept"="application/json, application/xml, text/json, text/x-json, text/javascript, text/xml" } $URL=$BaseURL+$RequestURL $Result=Invoke-RestMethod -Uri $URL -Method PUT -Body $PutData -Headers $postHeader -ContentType "application/json" } Function ExportSchedule ($Filename) { if ($Filename -eq $Null) { $Date=Get-Date -UFormat "%Y%m%d%H%M" $Filename="Schedule-$Date.csv" } $OutputZones=@() foreach ($Zone in $ZonesStatus){ Write-Host "Exporting" $Zone.name $ZoneId=$Zone.zoneId $Output=$Output+$Zone.name+"`t"+$ZoneId+"`t" $DailySchedules=GetRequest "temperatureZone/$ZoneId/schedule" $Schedule=$DailySchedules.dailySchedules $obj=new-object psobject Add-Member -InputObject $obj -MemberType NoteProperty -Name ZoneName -Value $Zone.Name Add-Member -InputObject $obj -MemberType NoteProperty -Name ZoneId -Value $ZoneId for($i=0;$i -lt 7;$i++) { switch ($i) { 0 {$Day="Mon"} 1 {$Day="Tue"} 2 {$Day="Wed"} 3 {$Day="Thu"} 4 {$Day="Fri"} 5 {$Day="Sat"} 6 {$Day="Sun"} } for($j=1;$j -lt 7;$j++) { Add-Member -InputObject $obj -MemberType NoteProperty -Name "$Day-$J-Temp" -Value $Schedule[$i].switchpoints[$j-1].temperature Add-Member -InputObject $obj -MemberType NoteProperty -Name $Day-$J-Time -Value $Schedule[$i].switchpoints[$j-1].timeOfDay } } $OutputZones+=$obj } $OutputZones | sort-object -property zonename | export-csv -notype $Filename } Function ImportSchedule ($Filename) { if ($Filename -eq $Null) { $Filename="Schedule.csv" } $ImportZones=import-csv $Filename $ZoneArray=@() foreach ($Line in $ImportZones) { $ZoneObj = New-Object System.Object $ZoneObj | Add-Member -type NoteProperty -name ZoneId -Value $Line.ZoneId $ZoneObj | Add-Member -type NoteProperty -name ZoneName -Value $Line.ZoneName $DailySchedules=@() for($i=0;$i -lt 7;$i++) { switch ($i) { 0 {$Day="Mon"} 1 {$Day="Tue"} 2 {$Day="Wed"} 3 {$Day="Thu"} 4 {$Day="Fri"} 5 {$Day="Sat"} 6 {$Day="Sun"} } $SwitchPoints=@() for($j=1;$j -lt 7;$j++) { if ($Line."$Day-$J-Temp" -ne "") {$SwitchPoints+=@{TargetTemperature=$Line."$Day-$J-Temp";TimeOfDay=$Line."$Day-$J-Time"}} } $DailySchedules+=@{DayOfWeek=$i;Switchpoints=$SwitchPoints} } $DailySchedules=@{DailySchedules=$DailySchedules} $ZoneObj | Add-Member -type NoteProperty -name ZoneSchd -Value $DailySchedules $ZoneArray+=$ZoneObj } foreach ($Zone in $ZoneArray){ $ScheduleJSON=ConvertTo-Json $Zone.ZoneSchd -Depth 10 $ZoneID=$Zone.ZoneId write-host "Setting Schedule for" $Zone.ZoneId $Zone.ZoneName PutRequest "temperatureZone/$ZoneId/schedule" $ScheduleJSON } } $AccessToken=GetAccessToken $UserDetails=GetRequest "userAccount" $UserId=$UserDetails.userId $Locations=GetRequest "location/installationInfo?userId=$UserId&includeTemperatureControlSystems=True" #assuming only 1 $LocationInfo=$Locations[0].locationInfo $LocationId=$LocationInfo.locationId $GateWayInfo=$Locations[0].gateways.gatewayInfo $AllowedSystemModes=$Locations[0].gateways.temperatureControlSystems.allowedSystemModes $ZonesCapabilities=$Locations[0].gateways.temperatureControlSystems.zones $GateWays=GetRequest "location/$LocationId/status?includeTemperatureControlSystems=True" $HeatingSystem=$GateWays.gateways.temperatureControlSystems $GatewayActiveFaults=$GateWays.gateways.activeFaults $SystemId=$HeatingSystem.systemId $ZonesStatus=$HeatingSystem.zones $SystemActiveFaults=$HeatingSystem.activeFaults $SystemModeStatus=$HeatingSystem.systemModeStatus $SystemMode=$SystemModeStatus.mode
import-module .\Evohome.ps1
ExportSchedule
ImportSchedule MySchedule.csv
Function ChangeZoneScheduleTemps ($Filter,$Diff) { if($Filter -eq "All"){ $ZoneList=$ZonesStatus } else { $ZoneList=$ZonesStatus| where-object {$_.name -match $Filter} } foreach ($Zone in $ZoneList){ Write-Host "Changing" $Zone.name $ZoneId=$Zone.zoneId $DailySchedules=GetRequest "temperatureZone/$ZoneId/schedule" $Schedule=$DailySchedules.dailySchedules foreach ($Day in $Schedule){ foreach ($Switch in $Day.switchpoints){ $Switch.temperature=$Switch.temperature+$Diff } } $DailySchedules=@{DailySchedules=$Schedule} $ScheduleJSON=ConvertTo-Json $DailySchedules -Depth 10 $ScheduleJSON=$ScheduleJSON -Replace "temperature","TargetTemperature" PutRequest "temperatureZone/$ZoneId/schedule" $ScheduleJSON } }
ChangeZoneScheduleTemps All -1.5 ChangeZoneScheduleTemps Bed 2.5
Comment