update states scritp and add refresh status every 5 mins
This commit is contained in:
@@ -51,6 +51,20 @@ fi
|
|||||||
# Give services time to start
|
# Give services time to start
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
|
# Lancement du synchro en arrière-plan toutes les X secondes
|
||||||
|
# Cela garantit que même si un équipement est sur un "autre canal",
|
||||||
|
# il sera interrogé et mis à jour car on boucle sur la liste globale.
|
||||||
|
php -r "while(true) { include 'sync_hass_states.php'; sleep(10); }" & SYNC_PID=$!
|
||||||
|
|
||||||
|
# Surveillance du processus de synchronisation
|
||||||
|
while true; do
|
||||||
|
sleep 60
|
||||||
|
if [[ -n "$SYNC_PID" && "$SYNC_PID" =~ ^[0-9]+$ ]] && ! kill -0 $SYNC_PID 2>/dev/null; then
|
||||||
|
echo "ERROR: Sync Service died..." >&2
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Monitor services
|
# Monitor services
|
||||||
ASW_PID=$(cat AirSendWebService.lock)
|
ASW_PID=$(cat AirSendWebService.lock)
|
||||||
while true; do
|
while true; do
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
|
|
||||||
payload=`echo $2 | base64 -d`
|
payload=`echo $2 | base64 -d`
|
||||||
echo -en $payload | curl -s --data-binary @- -X POST -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -H "Content-Type: application/json" http://supervisor/core/api/states/$1
|
echo -en $payload | curl -s --data-binary @- -X POST -H "Authorization: Bearer ${HASS_TOKEN}" -H "Content-Type: application/json" http://${HASS_HOST}/api/states/$1
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/usr/bin/with-contenv bashio
|
#!/usr/bin/with-contenv bashio
|
||||||
|
|
||||||
curl -o states.json -s -X GET -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -H "Content-Type: application/json" http://supervisor/core/api/states
|
curl -o states.json -s -X GET -H "Authorization: Bearer ${HASS_TOKEN}" -H "Content-Type: application/json" http://${HASS_HOST}/api/states/$1
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
require_once dirname(__FILE__) . "/hassapi.class.php";
|
||||||
|
|
||||||
|
// --- Configuration (Identique à votre setup actuel) ---
|
||||||
|
$SUPERVISOR_TOKEN = @getenv("SUPERVISOR_TOKEN");
|
||||||
|
$HASS_HOST = @getenv("HASS_HOST");
|
||||||
|
$HASS_TOKEN = @getenv("HASS_TOKEN");
|
||||||
|
|
||||||
|
// ... [Logique de construction de $api identique à celle de votre script principal] ...
|
||||||
|
|
||||||
|
if ($api->isAuthorized()) {
|
||||||
|
// On récupère la liste des entités que Home Assistant connaît
|
||||||
|
// Cela nous sert de "liste de courses" pour savoir ce qu'on doit mettre à jour.
|
||||||
|
$all_entities = $api->loadStates();
|
||||||
|
|
||||||
|
foreach ($all_entities as $entity_data) {
|
||||||
|
$id = $entity_data['entity_id'];
|
||||||
|
$details = $api->getState($id); // Récupère le type (temp, humidity, etc.) et l'état actuel.
|
||||||
|
|
||||||
|
if ($details) {
|
||||||
|
/**
|
||||||
|
* ÉTAPE CRUCIALE : Ici, au lieu d'attendre un événement AirSend,
|
||||||
|
* vous devez appeler une fonction qui interroge directement
|
||||||
|
* votre service AirSendWebService pour obtenir la valeur physique.
|
||||||
|
*
|
||||||
|
* Si vous avez une méthode ou un endpoint dans AirSend pour "récupérer tout",
|
||||||
|
* utilisez-le ici pour remplir $current_physical_value.
|
||||||
|
*/
|
||||||
|
$current_physical_value = $details['state']; // Par défaut, on garde l'ancienne si pas de changement
|
||||||
|
|
||||||
|
// Exemple logique si vous interrogez le service AirSend directement :
|
||||||
|
// $raw_airsend = \AirSendService::fetchStatus($entity_data['some_id']);
|
||||||
|
// if ($raw_airsend) { $current_physical_value = $raw_airsend; }
|
||||||
|
|
||||||
|
// On force la mise à jour vers Home Assistant
|
||||||
|
$api->setState(
|
||||||
|
$id,
|
||||||
|
$details['type'] ?? 'state',
|
||||||
|
$current_physical_value,
|
||||||
|
time() * 1000, // Timestamp actuel pour forcer le "last_updated" dans HA
|
||||||
|
$entity_data['attributes']['channel'] ?? null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user