This script monitors openhab log for messages like Terminating homekit connection
and New homekit connection
and saving connection state to specified MQTT. I'm running it with following parameters:
python3 homekiter.py --mqtt_host wb.286.su --mqtt_topic_prefix /custom/homekit_connected --logfile /usr/src/logs/openhab.log
In the openhab I have created following things and items:
Thing exec:command:openhab_refresh_homekit [ command="ssh -i /openhab/conf/id_rsa openhab@localhost -p 8101 bundle:refresh org.openhab.io.homekit", interval=0, autorun=false ]
Switch refresh_homekit {channel="exec:command:openhab_refresh_homekit:run", autoupdate="false"}
Switch homekit_connected_atv (gHomekitConnected) {mqtt="<[wirenboard:/custom/homekit_connected/192.168.88.67:state:MAP(mqtt_on_off.map)]", autoupdate="false"}
Switch homekit_connected_andrey_iphone (gHomekitConnected) {mqtt="<[wirenboard:/custom/homekit_connected/192.168.88.67:state:MAP(mqtt_on_off.map)]", autoupdate="false"}
Switch homekit_connected_alina_iphone (gHomekitConnected) {mqtt="<[wirenboard:/custom/homekit_connected/192.168.88.68:state:MAP(mqtt_on_off.map)]", autoupdate="false"}
Switch homekit_connected_ipad (gHomekitConnected) {mqtt="<[wirenboard:/custom/homekit_connected/192.168.88.66:state:MAP(mqtt_on_off.map)]", autoupdate="false"}
Group:Switch:OR(ON,OFF) gHomekitConnected
And at last following rule refreshes homekit when there is no active homekit connections for few seconds:
rule "Reload homekit when no connections"
when
Item gHomekitConnected changed to OFF
then
createTimer(now.plusSeconds(5), [|
if (gHomekitConnected.state == OFF) {
refresh_homekit.sendCommand(ON)
sendTelegram("wb286prv", "Перезапускаю HomeKit")
}
])
end