Aller au contenu

Watchdog Pour Scènes Et Modules Virtuels


Lazer

Messages recommandés

salut, j'ai testé le formidable watchdog en appuyant sur stop pour GEA, j ai donc bien eu le push demandé et le watchdog a bien redémarré la scène.

 

Cependant, quand je recois le push, voila ce que je reçois:

 

Watchdog: Scene\\\\\\\"GEA 5.30\\\\\\\" (43) a été redémarré

 

 

Ci dessous le debug du watchdog:

[DEBUG] 16:45:02: Scene(43) 0 running instance
[DEBUG] 16:45:02Restart Scene(43)
[DEBUG] 16:45:02Scene(43) successfully restarted
[DEBUG] 16:45:02Notification : Watchdog : Scene "GEA 5.30" (43) a été redémarré
[DEBUG] 16:46:02: Check

 
 
Comment faire pour ne pas recevoir lors d'un push les \\\\\\\\\\\   , merci d'avance :)
Lien vers le commentaire
Partager sur d’autres sites

C'est un problème de protection de l'apostrophe.... comme ça passe par les serveurs de Fibaro, je pense qu'on ne peut rien faire, j'ai le souci pour toutes les notifications par email depuis toujours

Lien vers le commentaire
Partager sur d’autres sites

oui en effet, si tu ne met aucun apostrophe, le problème n'apparait pas.

Mais là, comme j'en ai mis autour du nom du VD/Scène redémarré, le bug réapparait. J'espère que Fibaro corrigera ce problème un jour

Lien vers le commentaire
Partager sur d’autres sites

Je ne vais pas sortir une nouvelle version juste pour ça, tu peux donc modifier directement les lignes concernées, àpriori il n'y en a que 4.

Tu cherches simplement les lignes où il y a "n'a pas pu être redémarré"

Lien vers le commentaire
Partager sur d’autres sites

  • 2 mois après...

la 4.082b semble nous avoir réservé encore d'autres surprises :

Mon GEA s'est arrêté à5:08 ce matin, et le watchdog n'aurait rien vu. Mais peut-être est-ce la scène qui était dans les choux.

Mais de toute façon, je n'arrive pas àssauver manuellement le GEA => ça sent le reboot ...

Lien vers le commentaire
Partager sur d’autres sites

  • 3 mois après...

avec la nouvelle version du VD sonos, que faut-il mettre dans le watchdog ?

Je suis en version1.0.1 de sonos

J'ai mis ceci, mais c'est pas bon :

  {type = "VD",    id = 309, match = {text="Start main process", interval=31*60},                        no_match = {text="", type="ERROR"}, restart=false,  notification = {       "email" }}, -- SONOS_CUISINE (Tk.isTraceEnabled = true)

Voici le debug :

[DEBUG] 13:19:23: Check : type=VD id=309
[DEBUG] 13:19:23: http://127.0.0.1:11111/api/virtualDevices/309/debugMessages/0
[DEBUG] 13:19:23: Check : type=VD id=343
[DEBUG] 13:19:23: http://127.0.0.1:11111/api/virtualDevices/343/debugMessages/0
[DEBUG] 13:19:23: Check : type=VD id=307
[DEBUG] 13:19:23: http://127.0.0.1:11111/api/virtualDevices/307/debugMessages/0
[DEBUG] 13:19:24: VD(343) String "Start main process" not found
[DEBUG] 13:19:24: Restart VD(343)
[DEBUG] 13:19:24: VD(309) String "Start main process" not found
[DEBUG] 13:19:24: Restart VD(309)
[DEBUG] 13:19:24: VD(307) String "Start main process" not found
[DEBUG] 13:19:24: Restart VD(307)
Lien vers le commentaire
Partager sur d’autres sites

merci, donc j'ai mis ceci

  {type = "VD",    id = 309, match = {text="Get ", interval=60},                        no_match = {text="", type="ERROR"}, restart=false,  notification = {       "email" }}, -- SONOS_CUISINE (Tk.isTraceEnabled = true)

et j'ai toujours la même erreur dans le debug

[DEBUG] 13:57:03: Check : type=VD id=309
[DEBUG] 13:57:03: http://127.0.0.1:11111/api/virtualDevices/309/debugMessages/0
[DEBUG] 13:57:03: VD(309) String "Get " not found
[DEBUG] 13:57:03: Restart VD(309)

as-tu du activé qqch du genre "(Tk.isTraceEnabled = true) " dans le VD sonos ?

Lien vers le commentaire
Partager sur d’autres sites

  • 2 semaines après...

@Lazer

 

i have added Telegram as an option in your great Watchdog script.

--[[
%% autostart
%% properties
%% globals
--]]
--------------------------------------------------
-- Scene   : Watchdog
-- Author  : Lazer
-- Version : 1.1
-- Date    : November 2015
--------------------------------------------------
 
-- User variables
local intervalle = 60
local delay = 15*60
local watchdog = {
  	{type = "Scene", id = 186, match = {text="(month)", interval=5*60}, no_match = {text=""}, count=1,      restart=true, notification = {"push", "email", "sms"}}, -- Netatmo
	{type = "Scene", id = 4, match = {text="Duration", interval=11*60}, no_match = {text=""}, count=1, restart=true, notification = {"push", "email", "sms"}}, -- GEA
	{type = "Scene", id = 12, match = {text="Nà¤sta", interval=16*60}, no_match = {text=""}, count=1, restart=true, notification = {"telegram"}}, -- WUWeather
	{type = "VD",    id = 159, match = {text="", interval=0}, no_match = {text="", type="ERROR"}, restart=true, notification = {"push", "email", "sms"}}, -- Clock Sync
	{type = "VD",    id = 160, match = {text="", interval=0}, no_match = {text="", type="ERROR"}, restart=true, notification = {"push", "email", "sms"}}, -- My Batteries
	{type = "VD",    id = 146, match = {text="", interval=0}, no_match = {text="", type="ERROR"}, restart=true, notification = {"push", "email", "sms"}}, -- Evénements
	{type = "VD",    id = 317, match = {text="", interval=0}, no_match = {text="", type="ERROR"}, restart=true, notification = {"push", "email", "sms"}}, -- GEA Alarm Jonny
	{type = "VD",    id = 318, match = {text="", interval=0}, no_match = {text="", type="ERROR"}, restart=true, notification = {"push", "email", "sms"}}, -- GEA Alarm Mona
	{type = "VD",    id = 298, match = {text="", interval=30}, no_match = {text="", type="ERROR"}, restart=true, notification = {"telegram"}}, -- Sonos Player (Tk.isTraceEnabled = true)
  
}
local userID = {}               	-- Email
local smartphoneID = {284}         	-- Push
local telegram = {	
  	["VG_Name"]   = "Telegram"  
}      								-- Global Variable Name
local sms = {
	["VD_ID"]     = 0,             	-- Virtual Device ID
	["VD_Button"] = "1",          	-- Virtual Device Button
	["VG_Name"]   = "SMS"         	-- Global Variable Name
}
local debug = true
 
 
--
-- Message function
--
function Message(color, message)
	if color and color ~= "" then
		fibaro:debug('<span style="color:'..color..';">'..message..'</span>')
	else
		fibaro:debug(message)
	end
end
 
 
--
-- Notification function
--
function Notification(message, param)
	local message = message or "<vide>"
	Message("yellow", "Notification : "..message)
	if param then
		for _, notif in ipairs(param) do
			if debug then
				Message("grey", notif)
			end
			-- Envoi Push
			if notif == "push" and smartphoneID then
				for _, id in ipairs(smartphoneID) do
					if debug then
						Message("grey", "Send Push smartphone ID : "..id)
					end
					fibaro:call(id, "sendPush", message)
				end
			-- Envoi Email
			elseif notif == "email" and userID then
				for _, id in ipairs(userID) do
					if debug then
						Message("grey", "Send Email user ID : "..id)
					end
					fibaro:call(id, "sendEmail", "HC2 Watchdog", message)
				end
        	-- Telegram
        	elseif notif == "telegram" and telegram then
				if debug then
					Message("grey", "Send Telegram : VG_Name="..(telegram["VG_Name"] or ""))
				end
				fibaro:setGlobal(telegram["VG_Name"], message)
			-- Envoi SMS
			elseif notif == "sms" and sms then
				if debug then
					Message("grey", "Send SMS : VD_ID="..(sms["VD_ID"] or 0).." VD_Button="..(sms["VD_Button"] or "0").." VG_Name="..(sms["VG_Name"] or ""))
				end
				fibaro:setGlobal(sms["VG_Name"], message)
				if sms["VD_ID"] and tonumber(sms["VD_ID"])>0 and sms["VD_Button"] and tonumber(sms["VD_Button"])>0 then
					fibaro:call(sms["VD_ID"], "pressButton", sms["VD_Button"])
				end
			end
		end
	else
		Message("orange", "Warning : no notification options given")
	end
end
 
 
--
-- Restart function
--
function Restart(type, id, restart, notification)
 
	Message("blue", 'Restart '..type..'('..id..')')
 
	-- Prepare API URL
	local getURL = ""
	local putURL = ""
	if type:lower() == "scene" then
		getURL = 'http://127.0.0.1:11111/api/scenes/'..id
		putURL = 'http://127.0.0.1:11111/api/scenes/'..id
	elseif type:lower() == "vd" then
		getURL = 'http://127.0.0.1:11111/api/virtualDevices/'..id
		putURL = 'http://127.0.0.1:11111/api/virtualDevices/'..id
	end
 
	-- Load VD/Scene
	local httpClient = net.HTTPClient()
	httpClient:request(getURL, {
		success = function(response)
			if response.status == 200 then
				local jsonTable = json.decode(response.data)
				local name = jsonTable.name or ""
				if restart and restart == true then
					-- Save VD/Scene
					httpClient:request(putURL, {
						success = function(response)
							if response.status == 200 then
								Message("green", type.."("..id..") successfully restarted")
								Notification('Watchdog : '..type..' "'..(name or "")..'" ('..id..") was restarted", notification)
							else
								Message("red", type.."("..id..") Error : status="..tostring(response.status))
								Notification('Watchdog : '..type..' "'..(name or "")..'" ('..id..") could not be restarted", notification)
							end
						end,
						error = function(err)
							Message("red", type.."("..id..") Error : "..err)
							Notification('Watchdog : '..type..' "'..(name or "")..'" ('..id..") could not be restarted", notification)
						end,
						options = {
							method = 'PUT',
							-- headers = {
								-- ["content-type"] = 'application/x-www-form-urlencoded;'
							-- },
							data = response.data
						}
					})
				else
					Notification('Watchdog : '..type..' "'..(name or "")..'" ('..id..") must be manually restarted", notification)
				end
			else
				Message("red", type.."("..id..") Error : status="..tostring(response.status))
				Notification('Watchdog : '..type..' ('..id..") could not be restarted", notification)
			end
		end,
		error = function(err)
			Message("red", type.."("..id..") Error : "..err)
			Notification('Watchdog : '..type..' ('..id..") could not be restarted", notification)
		end,
		options = {
			method = 'GET'
		}
	})
 
end -- function
 
 
--
-- Check function
--
function Check(interval)
 
	Message(nil, "Check")
 
	-- Browse VD/Scene list
	local httpClient = net.HTTPClient()
	local elements = #watchdog
	for i = 1, elements do
 
		-- Initialization
		local countscene_found = false
		if debug then
			Message(nil, "Check : type="..watchdog[i].type.." id="..watchdog[i].id)
		end
 
		-- Check number of running scene instances
		if watchdog[i].type:lower() == "scene" and watchdog[i].count and watchdog[i].count > 0 then
			local countScenes = fibaro:countScenes(watchdog[i].id)
			if countScenes < watchdog[i].count then
				Message("orange", watchdog[i].type..'('..watchdog[i].id..') '..countScenes..' running instance')
				countscene_found = true
				Restart(watchdog[i].type, watchdog[i].id, watchdog[i].restart, watchdog[i].notification)
			elseif debug then
				Message("green", watchdog[i].type..'('..watchdog[i].id..') '..countScenes.." running instance")
			end
		end
 
		if countscene_found == false then  -- Do not enter this loop if scene has already been restarted
			-- Prepare API URL
			local getURL = ""
			if watchdog[i].type:lower() == "scene" then
				getURL = "http://127.0.0.1:11111/api/scenes/"..watchdog[i].id.."/debugMessages"
			elseif watchdog[i].type:lower() == "vd" then
				getURL = "http://127.0.0.1:11111/api/virtualDevices/"..watchdog[i].id.."/debugMessages/0"
			else
				Message("red", "Error : unknown type value")
			end
			if getURL ~= "" then
				if debug then
					Message("grey", getURL)
				end
				-- Load VD/Scene debug messages
				httpClient:request(getURL, {
					success = function(response)
						if response.status == 200 then
							if response.data and response.data ~= "" then
								local jsonTable = json.decode(response.data)
								local current_timestamp = os.time()
								local oldest_timestamp = current_timestamp
								local match_found = false
								local no_match_found = false
								-- Reverse browsing of debug messages
								for j = #jsonTable, 1, -1 do
									oldest_timestamp = jsonTable[j].timestamp
									-- Check if debug message match lookup string within allowed interval
									if watchdog[i].match.text and watchdog[i].match.text ~= "" and watchdog[i].match.interval > 0 and jsonTable[j].txt:match(watchdog[i].match.text) then
										if jsonTable[j].timestamp > current_timestamp - watchdog[i].match.interval then
											if debug then
												Message("green", watchdog[i].type..'('..watchdog[i].id..') Found string "'..watchdog[i].match.text..'"')
											end
											match_found = true
										end
									end
									-- Check if debug message match forbidden string
									if watchdog[i].no_match.text and watchdog[i].no_match.text ~= "" and jsonTable[j].txt:match(watchdog[i].no_match.text) then
										Message("orange", watchdog[i].type..'('..watchdog[i].id..') Found string "'..watchdog[i].no_match.text..'"')
										no_match_found = true
										break
									end
									if watchdog[i].no_match.type and watchdog[i].no_match.type ~= "" and jsonTable[j].type == watchdog[i].no_match.type then
										Message("orange", watchdog[i].type..'('..watchdog[i].id..') Found type "'..watchdog[i].no_match.type..'"')
										no_match_found = true
										break
									end
								end -- for
								if debug and oldest_timestamp > current_timestamp - watchdog[i].match.interval then
									Message("grey", watchdog[i].type..'('..watchdog[i].id..') oldest debug timestamp more recent than interval')
								end
 
								-- Restart VD/Scene
								if watchdog[i].match.text and watchdog[i].match.text ~= "" and watchdog[i].match.interval > 0 and match_found == false and oldest_timestamp < current_timestamp - watchdog[i].match.interval then
									Message("orange", watchdog[i].type..'('..watchdog[i].id..') String "'..watchdog[i].match.text..'" not found')
									Restart(watchdog[i].type, watchdog[i].id, watchdog[i].restart, watchdog[i].notification)
								--if watchdog[i].no_match.text and watchdog[i].no_match.text ~= "" and no_match_found == true then
								elseif no_match_found == true then
									Restart(watchdog[i].type, watchdog[i].id, watchdog[i].restart, watchdog[i].notification)
								end
							else
								Message("red", "Error : empty response")
							end
						else
							Message("red", "Error : status=" .. tostring(response.status))
						end
					end,
					error = function(err)
						Message("red", 'Error : ' .. err)
					end,
					options = {
						method = 'GET'
					}
				})
			end
		end
 
	end -- for
 
	-- Wait
	if interval and interval > 0 then
		setTimeout(function() Check(interval) end, interval*1000)
	end
 
end -- function
 
 
--
-- Main loop
--
local trigger = fibaro:getSourceTrigger()
if trigger["type"] == "autostart" then
	Message(nil, "Watchdog instance autostart")
	-- Check function call delayed to prevent killing all other scenes not already started right after HC2 boot
	setTimeout(function() Check(intervalle) end, delay*1000)
else
	Message(nil, "Watchdog instance manual launch")
	-- Call Check function
	Check(nil)
end
 
 
  • Upvote 1
Lien vers le commentaire
Partager sur d’autres sites

Vu que pour moi le redémarrage ne marchait plus non plus pour les scènes à  partir de la 4.091, j'ai juste adapté le code avec un stop et start.

 

httpClient:request("http://127.0.0.1:11111/api/sceneControl?id="..id.."&action=stop")
fibaro:sleep(1000)
httpClient:request("http://127.0.0.1:11111/api/sceneControl?id="..id.."&action=start")
Encore merci pour cette scène qui m'a sauvé la mise plusieurs fois. Il ne me sert plus que pour la scène Netamo Welcome qui plante de temps en temps.
Lien vers le commentaire
Partager sur d’autres sites

×
×
  • Créer...