[Fermé] Widget - Status des devices gérés par le plugin
Publié : 20 déc. 2023, 22:34
Salut à tous,
comme j'ai quelques soucis de stabilité en ce moment je me suis fait un petit widget alimenté par un script qui donne le nombre de devices Live / Lost / Undefined. Pour cela il interroge l'API du plugin.
J'ai créé un capteur virtuel de type "Alerte" afin d'avoir un visuel couleur.

Seul bémol l'objet "Alerte" n'est pas reconnu dans HomeHabit, si quelqu'un sait comment l'intégrer je suis preneur.
comme j'ai quelques soucis de stabilité en ce moment je me suis fait un petit widget alimenté par un script qui donne le nombre de devices Live / Lost / Undefined. Pour cela il interroge l'API du plugin.
J'ai créé un capteur virtuel de type "Alerte" afin d'avoir un visuel couleur.
Code : Tout sélectionner
local Alertidx = 126 -- Change to your idx for the Virtual Alert sensor you have created for this script
local devicesLive=0
local devicesLost=0
local devicesUndefined=0
local urlWebUI = "http://192.168.1.68" -- Change to your local ip (127.0.0.1 most of the time)
local portWebUI = "9440" -- Change WebUI port
local apiPath = '/rest-z4d/1/zdevice-name'
-- no changes needed below this section (except timer if you want to change frequency)
return {
logging = {
level = domoticz.LOG_ERROR,
marker = '(Zigate Status)'
},
on = {
timer = {'every 15 minutes'},
httpResponses = {'triggerSA'} -- must match with the callback passed to the openURL command
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.devices(Alertidx).updateAlertSensor(domoticz.ALERTLEVEL_GREY, "Requesting ...")
domoticz.openURL({
url = urlWebUI .. ':' .. portWebUI .. apiPath,
method = 'GET',
callback = 'triggerSA' -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.ok) then
if (item.isJSON) then
local result_table = item.json
local tc = #result_table
for i = 1, tc do
if result_table[i].Health == "Live" then
devicesLive=devicesLive+1
elseif result_table[i].Health == "Not Reachable" then
devicesLost=devicesLost+1
else
devicesUndefined=devicesUndefined+1
end
end
if devicesLost == 0 and devicesUndefined==0 then
level = domoticz.ALERTLEVEL_GREEN -- domoticz.ALERTLEVEL_GREY, ALERTLEVEL_GREEN, ALERTLEVEL_YELLOW, ALERTLEVEL_ORANGE, ALERTLEVEL_RED
AlertText = devicesLive
elseif devicesLost==0 then
level = domoticz.ALERTLEVEL_ORANGE
AlertText = devicesUndefined
else
level = domoticz.ALERTLEVEL_RED
AlertText = devicesLost
end
AlertText="Live: " .. devicesLive .. "\nUnknown: " .. devicesUndefined .. "\nLost: " ..devicesLost
-- update device in Domoticz
domoticz.devices(Alertidx).updateAlertSensor(level, AlertText)
end
else
domoticz.log('There was a problem handling the request' .. url, domoticz.LOG_ERROR)
end
end
end
}