Ipx800 + X-4VR intégration Home Assistant

Pour info j’ai fait un custom component également pour Home Assistant : Intégration IPX800 Home Assistant
Je peux facilement ajouter d’autres extensions si ça intéressent des gens

1 « J'aime »

Bonsoir,
je n’avais besoin que de piloter les fonctions de l’IPX800v4 et je n’ai pas d’autres équipement à part un X400 Analog et un X200pH qui apparaissent comme des entrées virtuelles donc je n’ai pas codé le support de ces autres équipements mais ça ne doit pas être bien difficile à ajouter quand on peut tester sur l’équipement.

Point 1

  • platform: command_line
    switches:
    ipx800_1_relay_1:
    command_on: C:\Data\Batch\lib\GnuWin32\bin\wget --read-timeout=60 --auth-no-challenge --http-user=user --http-passwd=password -d http://our_ipx800_v3-1:8001/preset.htm?set1=1 -a R:\logs_dani_be\Applications\IPX-1\ipx800-1.log -O R:\logs_dani_be\Applications\IPX-1\ipx800-1.response.log
    command_off: C:\Data\Batch\lib\GnuWin32\bin\wget --read-timeout=60 --auth-no-challenge --http-user=user --http-passwd=password -d http://our_ipx800_v3-1:8001/preset.htm?set1=0 -a R:\logs_dani_be\Applications\IPX-1\ipx800-1.log -O R:\logs_dani_be\Applications\IPX-1\ipx800-1.response.log
    friendly_name: ‹ Chauffage ›

Point 2 dans l’IPX pour chauque switch

<?php $url = "http://localhost:8160/api/states/switch.ipx800_1_relay_" . $_GET['relay_num']; $data = array( 'state' => $_GET['relay_state'], 'attributes' => array('friendly_name' => $_GET['relay_name'], 'assumed_state' => 'true') ); // use key 'http' even if you send the request to https://... $options = array( 'http' => array( 'header' => array( "Content-type: application/json", "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI2YzU2MDVlYzY1MDk0ZGQxYmY0M2FmMjc2ZTM1MzA0ZCIsImlhdCI6MTU3NTgwNzQ3MSwiZXhwIjoxODkxMTY3NDcxfQ.28KKEXKLf5wDqOgXf1ldV1L0HiIW2Gc0QzTB-ti7Rug" ), 'method' => 'POST', 'content' => json_encode( $data ) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { /* Handle error */ } var_dump($result);

Point 3 Initialisation au démarrage

<#
.Synopsis
Initilize HASS at starting phase
.Notes
Name: Hass_Initialisation.ps1
Author: Thierry Lenoir
Created: 14/10/2019
Last Edit:
.Description
Based on the Autmation « alias: ‹ IPX initialisation › » a script is launched via the shell_command
Initialisation:
1 - IPX switch statuses

#>

#----------------------------------------------------------------------------------------------------

Initialisation

#----------------------------------------------------------------------------------------------------
#param($msg, $timeCreated, $accountName, $ipAddress)

loading Push Bullet lib & configs

. $Env:ScriptsLib\PushBullet\SendMsgPushBullet.ps1;
. $Env:ScriptsEtc\PushBullet_idens.ps1;

Loading & setting properties

$currentScriptName = $MyInvocation.MyCommand.Name.substring(-3);
[xml]$xmlProperties = Get-Content « $Env:ScriptsEtc\Scripts_properties.xml »;
#[xml]$xmlHackerCache = Get-Content $xmlProperties.$MyInvocation.MyCommand.Name.cacheFilename;

#----------------------------------------------------------------------------------------------------

Functions

#----------------------------------------------------------------------------------------------------

Function HassChangeSwitchStatus
{
Param([string]$relayNum, [string]$relayName, [string]$relayState, [string]$IPXNum )
Write-Output « $($MyInvocation.MyCommand.Name) => $(Get-Date -format « dd-MM-yyyy HH:mm:ss ») → Params: $relayNum - $relayName - $relayState - $IPXNum »

#remove "led" key word
$relayNum = $relayNum.substring(3) 

# add "ipx800_1_relay_" string at the relay number
$relayNum = "ipx800_" + $IPXNum + "_relay_" + $([int]$relayNum + 1)

# translate status code to hass codename 0=off 1=on
if($relayState -eq 1)     {$relayState = "on"} else {$relayState = "off"}

# build url to call hass
$hassURL = $xmlProperties.scriptsConfig.hass.ha_url + "/api/states/switch.$relayNum"

# buld body to send in the JSON request
$body = @{
   state = "$relayState"
   attributes = @{ friendly_name = "$relayName"
                     assumed_state = 'true' }
} | ConvertTo-Json

# setting headers
$headers = @{
    Authorization="Bearer $($xmlProperties.scriptsConfig.hass.ha_api_long_term_key)"
    ContentType = "application/json"
} 

# calling hass with Encoding to accept special char in the body
$resp = Invoke-WebRequest -Uri $hassURL -Method 'Post' -Headers $headers -body ([System.Text.Encoding]::UTF8.GetBytes($body))

Write-Output "$($MyInvocation.MyCommand.Name) <= $(Get-Date -format "dd-MM-yyyy HH:mm:ss")"

}

#----------------------------------------------------------------------------------------------------

MAIN

#----------------------------------------------------------------------------------------------------
try{
Write-Output « $($MyInvocation.MyCommand.Name) <=: $(Get-Date -format « dd-MM-yyyy HH:mm:ss ») »;

foreach ($ipx in $xmlProperties.scriptsConfig.SelectNodes("//ipx")){

    # retrieving IPX's creds
    $ipxUsrPass = $ipx.user + ":" + $ipx.pass

    # converting IPX's creds in BASE64
    $ipxCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($ipxUsrPass))
 
    # setting headers based on request seen in the Chrome console data
    $headers = @{
        "Authorization" = "Basic " + $ipxCreds
        "Accept" = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
        "Accept-Encoding" = "gzip, deflate"
        "Accept-Language" = "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7"
    }

    # retrieving relay statuses  
    [xml]$relayStatuses = Invoke-WebRequest -Method Get -Uri "$($ipx.url)/globalstatus.xml" -Headers $headers

    # retrieving relay names with Encoding to accept special char in the response
    [xml]$relayNames = [system.Text.Encoding]::UTF8.GetString((Invoke-WebRequest -Method Get -Uri "$($ipx.url)/ioname.xml" -Headers $headers).RawContentStream.ToArray())

    # initializing arrays
    $data = @()

    # Initiate relay status for each ones till max relay number param from script xml file
    for ($count = 0; $count -lt $ipx.maxRelay; $count++){
             HassChangeSwitchStatus $relayStatuses.response.SelectNodes("/response/led$($count)").LocalName $relayNames.SelectNodes("/response/output$($count+1)").InnerText $relayStatuses.response.SelectNodes("/response/led$($count)").InnerText $ipx.number
    }
    # temporary situation while the IPX 2 will migrate to version 3.47.0 or higher
    break;
}

}

catch{
Write-Output « $($MyInvocation.MyCommand.Name) => Error: $_ - $(Get-Date -format « dd-MM-yyyy HH:mm:ss ») »;
}

finally{
#logging elapstime …
Write-Output « $($MyInvocation.MyCommand.Name) =>: $(Get-Date -format « dd-MM-yyyy HH:mm:ss ») »;
}

Désolé pour le retard

1 « J'aime »

Bonjour, je lis avec attention tous les posts consacrés à HA mais n’ayant absolument aucune compétence en programmation mais néanmoins bien équipé en Domotique ( IPX800V4, module fil pilote, Yeelight, Aqara, Foscam, Robot Xiaomi) et très intéressé par Home assistant afin de regrouper dans une seule interface tout mon univers Domotique, ma question est simple : est-ce que ce sera possible de faire cohabiter tout ce monde avec HA et si oui faut-il un master en programmation pour paramétrer tout ça ? Et du coup, existe-il des tutos ?
D’avance merci pour vos avis éclairés.

Bonjour,
C’est en effet le but de HomeAssistant. Tout regrouper sous une même interface via des Intégrations (connecteur).

Tu peux déjà consulter les intégrations de HA avec ton écosystème sur le site web afin de voir si ces passerelles existent.

Ensuite pas besoin de connaissance en dev, l’application a bien progressé et tu peux faire pas ma de choses via l’interface web (scénario, actions…).

Je suis en train de creuser le sujet et je constate qu’en passant un peut de temps dessus je pourrais depuis une action sur l’ipx, commander, en plus de l’ipx, ma freebox ( couper le wifi avant d’aller me coucher), gérer l’éclairage via HA ou ipx, commander la sortie audio de ma barre de son, descendre mon vidéo projecteur et l’écran…(tout ça reste à faire :wink: pour ma part) avoir un historique des données de mes xthl

Mon installation est basé sur un raspberry pi sous docker avec un container HA.

Rien d’impossible et accessible.

Merci d’avoir pris le temps de répondre. Je vais me plonger dans les différents tutos dispos sur Youtube ou FB afin de voir si mes compétences me permettront de déployer la solution HA qui fait rêver :wink::smiley:

Moi j’utilise, ipx 3 et 4, des shellys, esp, 433 et zwave et tout cela est centralisé sur une box Eedomus. Ca fonctionne et c’est bien; j’aurais aimé plus de possibilité de scrips, et autre…
Du coup je teste Jeedom et now HA.
Pas facile, tres programmateur…j’ai vu beaucoup de tutos, ouf, quelle tete il faut…

MI

Bonjour j254y,

Je mets en place l’intégration Home Assistant avec l’ipx800 et je pars sur la solution Node-RED/MQTT.
Pourrais-tu m’exporter ton flow Node-RED avec ton serveur UPD stp car je bloque sur le paramétrage de certains nœuds. ? Merci d’avance.

Je ne sais pas si cela à deja été cité mais tu peux t’inscrire sur le forum HACF pour fouiner et poser tes questions si tu ne trouve pas déjà tes réponses.
La communauté est plutôt très sympa.
@+

Bonjour @j254y

Désolé de déterrer le post :cold_face:
Il est possible de partager ce flow avec la communauté ? C’est toujours bien de voir que l’on peut ajouter des fonctionnalités à l’existant ! :wink: