hi,
i know it exist a cloud connector, but i want to control the device without cloud.
so i tested a little bit and developed a little powershell script, to control the device.
but i don’t know, how to put it in a “integration” to include it to home assistant.
It would be nice, if some one can help me or can take over this task.
##device: mh-ac-wifi-1
$climaip="172.16.218.152"
$prot="http"
$uri="$($prot)://$($climaip)/api.cgi"
$user="admin"
$password="admin"
$climaConfigJson=@"
[
{
"Name": "Power",
"RW": "RW",
"Calc": "0",
"UID": "1"
},
{
"Name": "Mode",
"RW": "RW",
"Calc": "0",
"UID": "2"
},
{
"Name": "LuefterGeschwindigkeit",
"RW": "RW",
"Calc": "0",
"UID": "4"
},
{
"Name": "Vane Up/Down Position",
"RW": "RW",
"Calc": "0",
"UID": "5"
},
{
"Name": "User Setpoint",
"RW": "RW",
"Calc": "0",
"UID": "9"
},
{
"Name": "Return Path Temperature",
"RW": "R",
"Calc": "10",
"UID": "10"
},
{
"Name": "Remote Disable",
"RW": "RW",
"Calc": "0",
"UID": "12"
},
{
"Name": "Laufzeit",
"RW": "RW",
"Calc": "0",
"UID": "13"
},
{
"Name": "Alarm Status",
"RW": "R",
"Calc": "0",
"UID": "14"
},
{
"Name": "Fehler Code",
"RW": "R",
"Calc": "0",
"UID": "15"
},
{
"Name": "Mindesttemperatur",
"RW": "R",
"Calc": "10",
"UID": "35"
},
{
"Name": "MaxTemperatur",
"RW": "R",
"Calc": "10",
"UID": "36"
},
{
"Name": "AussenTemperatur",
"RW": "R",
"Calc": "10",
"UID": "37"
},
{
"Name": "Maintenance time",
"RW": "RW",
"Calc": "0",
"UID": "181"
},
{
"Name": "Maintenance config",
"RW": "RW",
"Calc": "0",
"UID": "182"
},
{
"Name": "Maintenance Filter time",
"RW": "RW",
"Calc": "0",
"UID": "183"
},
{
"Name": "Maintenance Filter config",
"RW": "RW",
"Calc": "0",
"UID": "184"
}
]
"@
$climainfos=(Invoke-RestMethod "http://172.16.218.152/js/data/data.json" )
function get_climaPostData{
param(
$command,
$data
)
$r1 = New-Object PSCustomObject
$r1 | Add-Member -type NoteProperty -name command -Value $command
$r1 | Add-Member -type NoteProperty -name data -Value $data
return ($r1 | ConvertTo-Json)
# | % { [System.Text.RegularExpressions.Regex]::Unescape($_) } )
}
function Clima_Login {
param(
$user,$pwd
)
$r1 = New-Object PSCustomObject
$r1 | Add-Member -type NoteProperty -name username -Value $user
$r1 | Add-Member -type NoteProperty -name password -Value $pwd
$data=get_climaPostData -command "login" -data $r1
$data= $data | ConvertFrom-Json | ConvertTo-Json
try{
$invoke=Invoke-RestMethod -Method post -Uri $uri -Body $data
}
catch{
$invokeerr="$_"
}
if (!($invoke.data.id.sessionID) -or $invokeerr) {
write-host "Error" -ForegroundColor Red
write-host $invokeerr
write-host $invoke
}
return $invoke.data.id.sessionID
}
function Clima_getavailabledatapoints {
param(
$sessionid
)
$r1 = New-Object PSCustomObject
$r1 | Add-Member -type NoteProperty -name sessionID -Value $sessionid
$data=get_climaPostData -command "getavailabledatapoints" -data $r1
$data= $data | ConvertFrom-Json | ConvertTo-Json
try{
$invoke=Invoke-RestMethod -Method post -Uri $uri -Body $data
}
catch{
$invokeerr="$_"
}
if (!($invoke.data.dp.datapoints) -or $invokeerr) {
write-host "Error" -ForegroundColor Red
write-host $invokeerr
write-host $invoke
}
return $invoke.data.dp.datapoints
}
function Clima_All_getdatapointvalue {
param(
$sessionid,
$uid="all"
)
$r1 = New-Object PSCustomObject
$r1 | Add-Member -type NoteProperty -name sessionID -Value $sessionid
$r1 | Add-Member -type NoteProperty -name uid -Value $uid
$data=get_climaPostData -command "getdatapointvalue" -data $r1
$data= $data | ConvertFrom-Json | ConvertTo-Json
try{
$invoke=Invoke-RestMethod -Method post -Uri $uri -Body $data
}
catch{
$invokeerr="$_"
}
if (!($invoke.data.dpval) -or $invokeerr) {
write-host "Error" -ForegroundColor Red
write-host $invokeerr
write-host $invoke
}
return $invoke.data.dpval
}
function Clima_Set_Value {
param(
$sessionid,
$name,
$val
)
$config=$climaConfig |?{$_.name -like $name}
if (!($config) -or ($config.RW -notlike "RW")) {
Write-Host "Config Error or Name wrong" -ForegroundColor Red
return
}
<#
$r1 = New-Object PSCustomObject
$r1 | Add-Member -type NoteProperty -name sessionID -Value $sessionid
$r1 | Add-Member -type NoteProperty -name uid -Value $config.uid
$r1 | Add-Member -type NoteProperty -name value -Value $val
$data=get_climaPostData -command "setdatapointvalue" -data $r1
#>
$data=@"
{
"command": "setdatapointvalue",
"data": {
"sessionID": "$($sessionid)",
"uid": $($config.uid),
"value": $val
}
}
"@
$data= $data | ConvertFrom-Json | ConvertTo-Json
write-host $data
try{
$invoke=Invoke-RestMethod -Method post -Uri $uri -Body $data
}
catch{
$invokeerr="$_"
}
if (!($invoke.success) -or $invokeerr) {
write-host "Error" -ForegroundColor Red
write-host $invokeerr
write-host $invoke
}
return $data
}
$climaConfig=$climaConfigJson | ConvertFrom-Json
$sessionId=Clima_Login -user $user -pwd $password
if ($sessionid) {
$datapoints=Clima_getavailabledatapoints -sessionid $sessionId
$allvalues=Clima_All_getdatapointvalue -sessionid $sessionId
foreach($val in $allvalues) {
$config=$climaConfig|?{$_.uid -eq $val.uid}
$val | Add-Member -MemberType NoteProperty -Name "Name" -Value $config.name -Force
$val | Add-Member -MemberType NoteProperty -Name "RW" -Value $config.rw -Force
if ($config.calc -gt 0) {
if ($config.calc -eq 10) {
$val | Add-Member -MemberType NoteProperty -Name "value" -Value ([int]$val.value/10) -Force
}
}
}
#Clima_Set_Value -sessionid $sessionId -name "LuefterGeschwindigkeit" -val 4
#Aus:
#Clima_Set_Value -sessionid $sessionId -name "Power" -val 0
#an:
#Clima_Set_Value -sessionid $sessionId -name "Power" -val 1
$allvalues| select name,value
}
else{
Write-Host "No Session ID" -ForegroundColor Red
}
best regards
Chris
#>