[DzVents] LiveBox 3 et 4

Vous avez créé un script LUA dont vous êtes fier, un .sh génial, un programme Python hors du commun, un Tuto, c'est ici que vous pouvez les partager.
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: [DzVents] LiveBox 3 et 4

Message par Neutrino »

Grâce à l'aide et la patience de hawk, voici une version compatible avec la dernière version de la liveBox 3 SG30_sip-fr-6.52.12.1
Pour les possesseur de cette LB3, pensez à mettre :

Code : Tout sélectionner

local liveBox3 = true
A tester :)

Code : Tout sélectionner

--[[
	Prérequis : 
	Domoticz v3.8837 or later (dzVents version 2.4 or later)
	
	Sources : 	https://www.alex-braga.fr/ressources_externe/xdslbox_3.4.10.sh
				https://github.com/rene-d/sysbus
				https://github.com/NextDom/plugin-livebox/

	Livebox 3/4 stats
	
				https://easydomoticz.com/forum/viewtopic.php?f=17&t=7247
				https://github.com/papo-o/domoticz_scripts/new/master/dzVents/scripts/livebox.lua
				https://pon.fr/dzvents-toutes-les-infos-de-la-livebox-en-un-seul-script/
	
-- Authors  ----------------------------------------------------------------
	V1.0 - Neutrino - 	Domoticz
	V1.1 - Neutrino - 	Activation/désactivation du WiFi
	V1.2 - papoo - 		Liste des n derniers appels manqués, sans réponse, réussis et surveillance périphériques des connectés/déconnectés
	V1.3 - Neutrino - 	Possibilité de purger le journal d'appels
	V1.4 - papoo - 		Possibilité de rebooter la Livebox
	V1.5 - papoo - 		Correction non mise à jour des devices après RAZ de la liste des appels
	V1.6 - papoo - 		Correction horodatage heures d'appel à GMT+2
	V1.7 - papoo - 		Affichage des noms connus via fichiers de contacts
	V1.8 - Neutrino - 	Support de la Livebox 3 Play, gestion heures d'été/heure d'hiver
	V1.9 - Neutrino - 	Prise en charge du Wifi 5 GHz de la Livebox 3
	V1.10 - Neutrino - 	gestion fichier contacts inexistant, gestion périphériques différentes, version du firmware, correction de bugs,
						Optimisation du nombre de requêtes
]]--
-- Variables à modifier ------------------------------------------------

local fetchIntervalMins = 1 --  intervalle de mise à jour. 
local adresseLB = '192.168.1.1' --Adresse IP de votre Livebox 4
local password = "motDePasse"
local tmpDir = "/var/tmp" --répertoire temporaire, dans l'idéal en RAM
local myOutput=tmpDir.."/Output.txt"
local myCookies=tmpDir.."/Cookies.txt"
local fichier_contacts = "/home/pi/domoticz/scripts/dzVents/scripts/contacts.json"
local liveBox3 = false --true si vous avez une liveBox3/play

-- Domoticz devices
local SyncATM = "Sync ATM" -- Nom du capteur custom Synchro ATM down, nil si non utilisé
local SyncATMup = "Sync ATM up" -- Nom du capteur custom Synchro ATM up, nil si non utilisé
local Attn = "Attn" -- Nom du capteur custom Attenuation de la ligne, nil si non utilisé
local MargedAttn = "Marge d'Attn" -- Nom du capteur custom Marge d'atténuation, nil si non utilisé
local IPWAN = "IP WAN" -- Nom du capteur Text IP WAN, nil si non utilisé
local IPv6WAN = "IPv6 WAN" -- Nom du capteur Text IPv6 WAN, nil si non utilisé
local UptimeLB = "Uptime Livebox"  -- Nom du capteur Text Uptime Livebox, nil si non utilisé
local TransmitBlocks = "TransmitBlocks"  -- Nom du capteur Incremental Counter TransmitBlocks, nil si non utilisé
local ReceiveBlocks = "ReceiveBlocks"  -- Nom du capteur Incremental Counter ReceiveBlocks, nil si non utilisé
local internet = "Internet"  -- Nom du capteur Interrupteur Internet, nil si non utilisé
local VoIP = "VoIP"  -- Nom du capteur Interrupteur VoIP, nil si non utilisé
local ServiceTV = "Service TV"  -- Nom du capteur Interrupteur Service TV, nil si non utilisé
local wifi24 = "WiFi 2.4"  -- Nom du capteur Interrupteur wifi 2.4Ghz, nil si non utilisé
local wifi5 = "WiFi 5"  -- Nom du capteur Interrupteur wifi 5Ghz, nil si non utilisé
local firmware = "Firmware LB" -- Nom du capteur Text Firmware LB, nil si non utilisé
local DernierAppel = "Dernier Appel" -- Nom du capteur Text Dernier Appel, nil si non utilisé
local missedCall = nil --"Appels manqués" -- Nom du capteur Text appels manqués, nil si non utilisé
local nbMissedCall = 4 -- Nombre d'appels manqués à afficher
local failedCall = nil -- "Appels sans réponse" -- Nom du capteur Text appels sans réponse, nil si non utilisé
local nbFailedCall = 4 -- Nombre d'appels sans réponse à afficher
local succeededCall = nil -- "Appels Réussis" -- Nom du capteur Text appels réussis, nil si non utilisé
local nbSucceededCall = 4 -- Nombre d'appels réussis à afficher
local clearCallList = "Effacer liste appels" -- Nom du capteur Interrupteur PushOn clearCallList
local reboot = "Reboot Livebox" -- Nom du capteur Interrupteur PushOn reboot
local devices_livebox_mac_adress = { -- MAC ADDRESS des périphériques à surveiller
										"AA:AA:AA:AA:AA:AA",
										"AA:AA:AA:AA:AA:AA",
									}
-- SVP, ne rien changer sous cette ligne (sauf pour modifier le logging level)

function os.capture(cmd, raw)
	local f = assert(io.popen(cmd, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	if raw then return s end
	s = string.gsub(s, '^%s+', '')
	s = string.gsub(s, '%s+$', '')
	s = string.gsub(s, '[\n\r]+', ' ')
	return s
end

function disp_time(time)
	local days = math.floor(time/86400)
	local remaining = time % 86400
	local hours = math.floor(remaining/3600)
	remaining = remaining % 3600
	local minutes = math.floor(remaining/60)
	remaining = remaining % 60
	local seconds = remaining
	return string.format("%d:%02d:%02d:%02d",days,hours,minutes,seconds)
end

function traduction(str) -- supprime les accents de la chaîne str
	if (str) then
	str = string.gsub (str,"missed", "manqué")
	str = string.gsub (str,"failed", "échoué")
	str = string.gsub (str,"succeeded", "réussi")	
	end
	return (str)
end
local function get_timezone()
  local now = os.time()
  return os.difftime(now, os.time(os.date("!*t", now)))
end


function format_date(str) -- supprime les caractères T et Z de la chaîne str  et corrige l'heure suivant le fuseau horaire
	if (str) then
		_, _, A, M, j, h, m, s = string.find(str, "^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)Z$")
		h = h + get_timezone()/3600
		str= A.."-"..M.."-"..j.." - "..h..":"..m..":"..s
	end
	return (str)
end

function ReverseTable(t)
	local reversedTable = {}
	local itemCount = #t
	for k, v in ipairs(t) do
		reversedTable[itemCount + 1 - k] = v
	end
	return reversedTable
end

function searchName(contacts, phoneNumber)
	name = phoneNumber
	for index, variable in pairs(contacts) do
		if variable.Phone == phoneNumber then
			name = variable.Name
			break
		end
	end
	return name
end

function searchKey(children, mac)
	key = -1
	if children then
		for index, variable in pairs(children) do
			if variable.Key == mac then
				key = index
				break
			end
		end
	end
	return key
end

local scriptName = 'Livebox'
local scriptVersion = '1.10'

return {
	active = true,
	logging = {
					-- level	 =   domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
					-- level	=   domoticz.LOG_INFO, -- Seulement un niveau peut être actif; commenter les autres
					-- level	=   domoticz.LOG_ERROR,											
					-- level	=   domoticz.LOG_DEBUG,
					-- level	=   domoticz.LOG_MODULE_EXEC_INFO,
		marker = scriptName..' '..scriptVersion
	},
	on = {
		timer = {
			'every '..tostring(fetchIntervalMins)..' minutes',
		},
	devices = {wifi5,wifi24,clearCallList,reboot}
	},

	execute = function(domoticz, item)
		local function readLuaFromJsonFile(fileName)
			local file = io.open(fileName, 'r')
			if file then
				local contents = file:read('*a')
				local lua_value = domoticz.utils.fromJSON(contents)
				io.close(file)
				return lua_value
			end
			return nil
		end
		--Connexion et récupération du cookies
		os.execute("curl -s -o \""..myOutput.."\" -X POST -c \""..myCookies.."\" -H 'Content-Type: application/x-sah-ws-4-call+json' -H 'Authorization: X-Sah-Login' -d \"{\\\"service\\\":\\\"sah.Device.Information\\\",\\\"method\\\":\\\"createContext\\\",\\\"parameters\\\":{\\\"applicationName\\\":\\\"so_sdkut\\\",\\\"username\\\":\\\"admin\\\",\\\"password\\\":\\\""..password.."\\\"}}\" http://"..adresseLB.."/ws > /dev/null")

		--Lecture du cookies pour utilisation ultérieure
		myContextID = os.capture("tail -n1 \""..myOutput.."\" | sed 's/{\"status\":0,\"data\":{\"contextID\":\"//1'| sed 's/\",//1' | sed 's/\"groups\":\"http,admin//1' | sed 's/\"}}//1'")
		domoticz.log('Context : '..myContextID, domoticz.LOG_DEBUG)
		
		if (item.isTimer)then
			
			--Données de connexion
			if SyncATM or SyncATMup or Attn or MargedAttn or UptimeLB then
				MIBs=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.data\\\",\\\"method\\\":\\\"getMIBs\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
				domoticz.log('MIBs : '..MIBs, domoticz.LOG_DEBUG)
				local lbAPIData = domoticz.utils.fromJSON(MIBs)
				if lbAPIData.status == nil or lbAPIData == nil then
					domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
				else
					if SyncATM then domoticz.log('ATM Down: '..lbAPIData.status.dsl.dsl0.DownstreamCurrRate, domoticz.LOG_INFO)
					domoticz.devices(SyncATM).updateCustomSensor(lbAPIData.status.dsl.dsl0.DownstreamCurrRate) end
					
					if SyncATMup then domoticz.log('ATM Up: '..lbAPIData.status.dsl.dsl0.UpstreamCurrRate, domoticz.LOG_INFO)
					domoticz.devices(SyncATMup).updateCustomSensor(lbAPIData.status.dsl.dsl0.UpstreamCurrRate) end
					
					if Attn then domoticz.log('Attn : '..tostring(lbAPIData.status.dsl.dsl0.DownstreamLineAttenuation/10)..' dB', domoticz.LOG_INFO)
					domoticz.devices(Attn).updateCustomSensor(tostring(lbAPIData.status.dsl.dsl0.DownstreamLineAttenuation/10)) end
					
					if MargedAttn then domoticz.log('Marge d\'Attn : '..tostring(lbAPIData.status.dsl.dsl0.DownstreamNoiseMargin/10)..' dB', domoticz.LOG_INFO)
					domoticz.devices(MargedAttn).updateCustomSensor(tostring(lbAPIData.status.dsl.dsl0.DownstreamNoiseMargin/10)) end
					
					if UptimeLB then Uptime = disp_time(lbAPIData.status.dsl.dsl0.LastChange)
					domoticz.log('Uptime : '..Uptime, domoticz.LOG_INFO)
					domoticz.devices(UptimeLB).updateText(Uptime) end
		   
				end
			end
			
			-- Volume de données échangées
			if TransmitBlocks or ReceiveBlocks then
				DSLstats=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.dsl0\\\",\\\"method\\\":\\\"getDSLStats\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
				domoticz.log('DSLstats : '..DSLstats, domoticz.LOG_DEBUG)
				local lbAPIDataDSL = domoticz.utils.fromJSON(DSLstats)
				if lbAPIDataDSL.status == nil then
					domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
				else
					if TransmitBlocks then domoticz.devices(TransmitBlocks).update(0,lbAPIDataDSL.status.TransmitBlocks) end
					if ReceiveBlocks then domoticz.devices(ReceiveBlocks).update(0,lbAPIDataDSL.status.ReceiveBlocks) end
				end
			end
			
			--État WiFi
			if wifi24 or wifi5 then
				wifi=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.lan\\\",\\\"method\\\":\\\"getMIBs\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
				domoticz.log('wifi : '..wifi, domoticz.LOG_DEBUG)
				local lbAPIDataWifi = domoticz.utils.fromJSON(wifi)
				if lbAPIDataWifi.status == nil then
					domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
				else
					if wifi24 then 
						domoticz.log('Wifi 2.4 Ghz : '..lbAPIDataWifi.status.wlanvap.wl0.VAPStatus, domoticz.LOG_INFO)
						if (lbAPIDataWifi.status.wlanvap.wl0.VAPStatus == 'Up' and domoticz.devices(wifi24).active == false)then
							domoticz.devices(wifi24).switchOn().silent()
						elseif (lbAPIDataWifi.status.wlanvap.wl0.VAPStatus ~= 'Up' and domoticz.devices(wifi24).active)then
							domoticz.devices(wifi24).switchOff().silent()
						end
					end	
					
					if wifi5 then
						if (lbAPIDataWifi.status.wlanvap.eth6)then
							domoticz.log('Wifi 5 Ghz : '..lbAPIDataWifi.status.wlanvap.eth6.VAPStatus, domoticz.LOG_INFO)
							if (lbAPIDataWifi.status.wlanvap.eth6.VAPStatus == 'Up' and domoticz.devices(wifi5).active == false)then
								domoticz.devices(wifi5).switchOn().silent()
							elseif (lbAPIDataWifi.status.wlanvap.eth6.VAPStatus ~= 'Up' and domoticz.devices(wifi5).active)then
								domoticz.devices(wifi5).switchOff().silent()
							end
						else
							--support de la livebox3
							domoticz.log('Wifi 5 Ghz : '..lbAPIDataWifi.status.wlanvap.wl1.VAPStatus, domoticz.LOG_INFO)
							if (lbAPIDataWifi.status.wlanvap.wl1.VAPStatus == 'Up' and domoticz.devices(wifi5).active == false)then
								domoticz.devices(wifi5).switchOn().silent()
							elseif (lbAPIDataWifi.status.wlanvap.wl1.VAPStatus ~= 'Up' and domoticz.devices(wifi5).active)then
								domoticz.devices(wifi5).switchOff().silent()
							end
						end
					end	
				end
			end 
			
			--Dernier Appel reçu ou émis
			local missedCallList = ""
			local failedCallList = ""
			local succeededCallList = ""
			if DernierAppel or missedCall or failedCall or succeededCall then
				callList=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"VoiceService.VoiceApplication\\\",\\\"method\\\":\\\"getCallList\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
				domoticz.log('callList : '..callList, domoticz.LOG_DEBUG)
				local lbAPIDataCallList = domoticz.utils.fromJSON(callList)
				if lbAPIDataCallList.status == nil then
					domoticz.log('Lecture de la MIBs impossible', domoticz.LOG_ERROR)
				else
					domoticz.log('CallList : '..#lbAPIDataCallList.status, domoticz.LOG_INFO)
					if (#lbAPIDataCallList.status>0) then
						contacts = readLuaFromJsonFile(fichier_contacts)
						if contacts == nil then contacts = {} end 
						domoticz.log('Dernier Appel : '..lbAPIDataCallList.status[#lbAPIDataCallList.status].remoteNumber, domoticz.LOG_INFO)
						domoticz.log('Dernier Appel : '..traduction(lbAPIDataCallList.status[#lbAPIDataCallList.status].callType), domoticz.LOG_INFO)
						NumeroEtat = searchName(contacts, lbAPIDataCallList.status[#lbAPIDataCallList.status].remoteNumber) .. " - "..lbAPIDataCallList.status[#lbAPIDataCallList.status].callType
						if DernierAppel and domoticz.devices(DernierAppel).text ~= traduction(NumeroEtat) then
								domoticz.devices(DernierAppel).updateText(traduction(NumeroEtat))
						end
						-- x Appels manqués, sans réponse, réussis
						for i, call in ipairs(ReverseTable(lbAPIDataCallList.status)) do
							if call.callType == "missed" and nbMissedCall > 0 then
								--domoticz.log(call.remoteNumber .. " " .. traduction(call.callType) .. " " .. format_date(call.startTime), domoticz.LOG_INFO)
								missedCallList = missedCallList .. searchName(contacts, call.remoteNumber) .. " - " .. format_date(call.startTime) .. "\n"
								nbMissedCall = nbMissedCall - 1
							end
							if call.callType == "failed" and nbFailedCall > 0 then
								--domoticz.log(call.remoteNumber .. " " .. traduction(call.callType) .." ".. format_date(call.startTime), domoticz.LOG_INFO)
								failedCallList = failedCallList .. call.remoteNumber .." - ".. format_date(call.startTime) .. "\n"
								nbFailedCall = nbFailedCall - 1
							end
							if call.callType == "succeeded" and nbSucceededCall > 0 then
								--domoticz.log(call.remoteNumber .. " " .. traduction(call.callType) .. " " .. format_date(call.startTime), domoticz.LOG_INFO)
								succeededCallList = succeededCallList .. searchName(contacts, call.remoteNumber) .. " - " .. format_date(call.startTime) .. "\n"
								nbSucceededCall = nbSucceededCall - 1
							end
						end					
						if missedCallList == "" then missedCallList = "Aucun appel à afficher" end						
						domoticz.log('Appels manqués : \n'..missedCallList, domoticz.LOG_INFO)
						if missedCall and domoticz.devices(missedCall).text ~= traduction(missedCallList) then 
							domoticz.devices(missedCall).updateText(traduction(missedCallList))
						end 
						if failedCallList == "" then failedCallList = "Aucun appel à afficher" end						
						domoticz.log('Appels sans réponse : \n'..failedCallList, domoticz.LOG_INFO)
						if failedCall and domoticz.devices(failedCall).text ~= traduction(failedCallList) then 
							domoticz.devices(failedCall).updateText(traduction(failedCallList))
						end 
						if succeededCallList == "" then succeededCallList = "Aucun appel à afficher" end
						domoticz.log('Appels réussis : \n'..succeededCallList, domoticz.LOG_INFO)
						if succeededCall and domoticz.devices(succeededCall).text ~= traduction(succeededCallList) then 
							domoticz.devices(succeededCall).updateText(traduction(succeededCallList))
						end					 
					else
						NumeroEtat = "Aucun appel à afficher"
						domoticz.log('Dernier Appel : '..NumeroEtat, domoticz.LOG_INFO)
						if DernierAppel and domoticz.devices(DernierAppel).text ~= NumeroEtat then
							domoticz.devices(DernierAppel).updateText(NumeroEtat)
						end 
						if missedCallList == "" then missedCallList = "Aucun appel à afficher" end						
						domoticz.log('Appels manqués : \n'..missedCallList, domoticz.LOG_INFO)
						if missedCall and domoticz.devices(missedCall).text ~= traduction(missedCallList) then 
							domoticz.devices(missedCall).updateText(traduction(missedCallList))
						end 
						if failedCallList == "" then failedCallList = "Aucun appel à afficher" end						
						domoticz.log('Appels sans réponse : \n'..failedCallList, domoticz.LOG_INFO)
						if failedCall and domoticz.devices(failedCall).text ~= traduction(failedCallList) then 
							domoticz.devices(failedCall).updateText(traduction(failedCallList))
						end 
						if succeededCallList == "" then succeededCallList = "Aucun appel à afficher" end
						domoticz.log('Appels réussis : \n'..succeededCallList, domoticz.LOG_INFO)
						if succeededCall and domoticz.devices(succeededCall).text ~= traduction(succeededCallList) then 
							domoticz.devices(succeededCall).updateText(traduction(succeededCallList))
						end					
					end
				end
			end
			
			if firmware or devices_livebox_mac_adress or ServiceTV or VoIP then
				LAN=os.capture("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..myContextID.."\" -d \"{\\\"service\\\":\\\"Devices.Device.HGW\\\",\\\"method\\\":\\\"topology\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws")
				LAN=LAN:gsub('"SerialNumber ... ','"SerialNumber" : "'):gsub(" ... ",'     ')
				domoticz.log('LAN : '..LAN, domoticz.LOG_DEBUG)
				LAN = domoticz.utils.fromJSON(LAN)
			--Version du firmware
				if LAN.status[1].SoftwareVersion and firmware then
					domoticz.log("Version Firmware : "..LAN.status[1].SoftwareVersion,domoticz.LOG_INFO)
					if domoticz.devices(firmware).text ~= LAN.status[1].SoftwareVersion then
						domoticz.devices(firmware).updateText(LAN.status[1].SoftwareVersion)
					end
				end
				
			--Etat du Service TV
				if LAN.status[1].IPTV and ServiceTV then
					domoticz.log("IPTV : "..tostring(LAN.status[1].IPTV),domoticz.LOG_INFO)
					if (LAN.status[1].IPTV)then
						domoticz.devices(ServiceTV).switchOn().checkFirst()
					else
						domoticz.devices(ServiceTV).switchOff().checkFirst()
					end
				end
				
			--Etat du Service VoIP
				if LAN.status[1].Telephony and VoIP then
					domoticz.log("Telephony : "..tostring(LAN.status[1].Telephony),domoticz.LOG_INFO)
					if (LAN.status[1].Telephony)then
						domoticz.devices(VoIP).switchOn().checkFirst()
					else
						domoticz.devices(VoIP).switchOff().checkFirst()
					end
				end
				
			--Etat du Service Internet
				if LAN.status[1].Internet and internet then
					domoticz.log("Internet : "..tostring(LAN.status[1].Internet),domoticz.LOG_INFO)
					if (LAN.status[1].Internet)then
						domoticz.devices(internet).switchOn().checkFirst()
					else
						domoticz.devices(internet).switchOff().checkFirst()
					end
				end
				
			-- IP WAN
				if LAN.status[1].ConnectionIPv4Address and IPWAN then
					domoticz.log("IP WAN : "..LAN.status[1].ConnectionIPv4Address,domoticz.LOG_INFO)
					if  domoticz.devices(IPWAN).text ~= LAN.status[1].ConnectionIPv4Address then
						domoticz.devices(IPWAN).updateText(LAN.status[1].ConnectionIPv4Address)
					end
				end

			-- IPv6WAN
				if LAN.status[1].ConnectionIPv6Address and IPv6WAN then
					domoticz.log("IPv6 WAN : "..LAN.status[1].ConnectionIPv6Address,domoticz.LOG_INFO)
					if  domoticz.devices(IPv6WAN).text ~= LAN.status[1].ConnectionIPv6Address then
						domoticz.devices(IPv6WAN).updateText(LAN.status[1].ConnectionIPv6Address)
					end
				end
			

			--Présence de périphériques
				LAN = LAN.status[1]['Children']
				for l=1,#LAN do -- récupération de l'arbre des périphériques LAN
					if LAN[l]["Key"]== "lan" then
						LAN = LAN[l]['Children']
						break
					end
				end
				local k=-1
				for i=1,#devices_livebox_mac_adress do -- recherche de l'adresse MAC et son statut
					for j=1,#LAN do
						if(LAN[j]['DiscoverySource'] == "selflan")then
							k=searchKey(LAN[j]['Children'],devices_livebox_mac_adress[i])
							if (k~=-1 and LAN[j]['Children'][k]['Active'])then
								domoticz.log('switch : '..LAN[j]['Children'][k]['Name'].." On", domoticz.LOG_INFO)
								if (domoticz.devices(LAN[j]['Children'][k]['Name']))then
									domoticz.devices(LAN[j]['Children'][k]['Name']).switchOn().checkFirst()
								end	
								break
							elseif (k~=-1 and LAN[j]['Children'][k]['Active']==false)then
								domoticz.log('switch : '..LAN[j]['Children'][k]['Name'].." Off", domoticz.LOG_INFO)
								if (domoticz.devices(LAN[j]['Children'][k]['Name']))then
									domoticz.devices(LAN[j]['Children'][k]['Name']).switchOff().checkFirst()
								end
								break
							end
						end
					end
					if (k==-1) then
						domoticz.log('mac : '..devices_livebox_mac_adress[i].." introuvable", domoticz.LOG_INFO)
					end
				end
			end
			
		else
			if(item.name == wifi5)then
				if liveBox3 then chip='wifi1_ath' else chip='wifi0_quan' end
				os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
					myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.lan\\\",\\\"method\\\":\\\"setWLANConfig\\\",\\\"parameters\\\":{\\\"mibs\\\":{\\\"penable\\\":{\\\""..chip.."\\\":{\\\"PersistentEnable\\\":"..
					tostring(item.active)..", \\\"Enable\\\":true}}}}}\" http://"..adresseLB.."/ws &")
				domoticz.log("wifi5 "..tostring(item.active),domoticz.LOG_INFO)
			elseif(item.name == wifi24)then
				if liveBox3 then chip='wifi0_ath' else chip='wifi0_bcm' end
				os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
					myContextID.."\" -d \"{\\\"service\\\":\\\"NeMo.Intf.lan\\\",\\\"method\\\":\\\"setWLANConfig\\\",\\\"parameters\\\":{\\\"mibs\\\":{\\\"penable\\\":{\\\""..chip.."\\\":{\\\"PersistentEnable\\\":"..
					tostring(item.active)..", \\\"Enable\\\":true}}}}}\" http://"..adresseLB.."/ws &")
				domoticz.log("wifi24 "..tostring(item.active),domoticz.LOG_INFO)
			elseif(item.name == clearCallList)then
				os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
					myContextID.."\" -d \"{\\\"service\\\":\\\"VoiceService.VoiceApplication\\\",\\\"method\\\":\\\"clearCallList\\\",\\\"parameters\\\":{}}\" http://"..adresseLB.."/ws &")
				domoticz.log("clearCallList "..tostring(item.active),domoticz.LOG_INFO)			

			elseif(item.name == reboot)then
			os.execute("curl -s -b \""..myCookies.."\" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H \"X-Context: "..
					myContextID.."\" -d \"{\\\"parameters\\\":{}}\" http://"..adresseLB.."/sysbus/NMC:reboot &")
				domoticz.log("reboot "..tostring(item.active),domoticz.LOG_INFO)			
			end		
		end
		--Déconnexion et suppression des fichiers temporaires
		os.execute("curl -s -b "..myCookies.." -X POST http://"..adresseLB.."/logout &")
		os.execute('rm "'..myCookies..'" "'..myOutput..'" &')
	end
}
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: [DzVents] LiveBox 3 et 4

Message par papoo »

yannig a écrit : 13 déc. 2018, 22:39
Je ne comprends pas ce qu'il faut faire. J'ai mis l'adresse mac de ma TV et d'une camera IP mais que dois-je créer comme composant dans domoticz pour les voir actifs ou non ? un virtual switch ?
Oui avec exactement le même nom que celui déclaré dans la Livebox (via l’interface admin, dans réseau, mes périphériques connectés
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
pat054
Messages : 70
Inscription : 29 juil. 2018, 18:14

Re: [DzVents] LiveBox 3 et 4

Message par pat054 »

bonjour Neutrino,

j'ai mis à jour le script dans Domoticz mais j'ai 3 nouvelles erreurs :

Code : Tout sélectionner

2018-12-14 14:56:00.247 Status: dzVents: Info: Livebox 1.10: ------ Start external script: livebox_play.lua:, trigger: every 1 minutes
2018-12-14 14:56:00.536 Status: dzVents: Info: Livebox 1.10: ATM Down: 9110
2018-12-14 14:56:00.561 Status: dzVents: Info: Livebox 1.10: ATM Up: 1020
2018-12-14 14:56:00.562 Status: dzVents: Info: Livebox 1.10: Attn : 38.2 dB
2018-12-14 14:56:00.563 Status: dzVents: Info: Livebox 1.10: Marge d'Attn : 8.3 dB
2018-12-14 14:56:00.564 Status: dzVents: Info: Livebox 1.10: Uptime : 1:04:50:34
2018-12-14 14:56:03.403 Status: dzVents: Info: Livebox 1.10: Wifi 2.4 Ghz : Up
2018-12-14 14:56:03.404 Status: dzVents: Info: Livebox 1.10: Wifi 5 Ghz : Up
2018-12-14 14:56:03.502 Status: dzVents: Info: Livebox 1.10: CallList : 3
2018-12-14 14:56:03.502 Status: dzVents: Info: Livebox 1.10: Dernier Appel :
2018-12-14 14:56:03.502 Status: dzVents: Info: Livebox 1.10: Dernier Appel : manqué
2018-12-14 14:56:03.505 Status: dzVents: Info: Livebox 1.10: Appels manqués :
2018-12-14 14:56:03.505 xxxxxxxxxxx - 2018-12-12 - 17:36:24
2018-12-14 14:56:03.505 xxxxxxxxxxx- 2018-12-12 - 11:15:48
2018-12-14 14:56:03.505 xxxxxxxxxxx - 2018-12-11 - 17:03:25
2018-12-14 14:56:03.505
2018-12-14 14:56:03.505 Status: dzVents: Info: Livebox 1.10: Appels sans réponse :
2018-12-14 14:56:03.505 Aucun appel à afficher
2018-12-14 14:56:03.505 Status: dzVents: Info: Livebox 1.10: Appels réussis :
2018-12-14 14:56:03.505 Aucun appel à afficher
2018-12-14 14:56:04.006 Status: dzVents: Info: Livebox 1.10: Version Firmware : SG30_sip-fr-6.52.12.1
2018-12-14 14:56:04.006 Status: dzVents: Error (2.4.9): Livebox 1.10: There is no device with that name or id: Firmware LB
2018-12-14 14:56:04.006 Status: dzVents: Error (2.4.9): Livebox 1.10: An error occured when calling event handler livebox_play
2018-12-14 14:56:04.006 Status: dzVents: Error (2.4.9): Livebox 1.10: /home/pi/domoticz/scripts/dzVents/scripts/livebox_play.lua:354: attempt to index a nil value
2018-12-14 14:56:04.006 Status: dzVents: Info: Livebox 1.10: ------ Finished livebox_play.lua
Dans l'attente, bon courage. Cordialement.

Pat
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: [DzVents] LiveBox 3 et 4

Message par Neutrino »

Code : Tout sélectionner

2018-12-14 14:56:04.006 Status: dzVents: Error (2.4.9): Livebox 1.10: There is no device with that name or id: Firmware LB
La solution est simple, il suffit de traduire :? Il n'y a pas de dispositif du nom de Firmware LB
DzVents ne peut pas mettre à jour un dispositif qui n'existe pas...

Code : Tout sélectionner

2018-12-14 14:56:04.006 Status: dzVents: Error (2.4.9): Livebox 1.10: An error occured when calling event handler livebox_play
2018-12-14 14:56:04.006 Status: dzVents: Error (2.4.9): Livebox 1.10: /home/pi/domoticz/scripts/dzVents/scripts/livebox_play.lua:354: attempt to index a nil value
Erreur à la ligne 354, il y a quoi à la ligne 354 de ton script ?
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
pat054
Messages : 70
Inscription : 29 juil. 2018, 18:14

Re: [DzVents] LiveBox 3 et 4

Message par pat054 »

Autant pour moi, effectivement, je viens de rajouter le dispositif "Firmware LB" et maintenant je n'ai plus d'erreurs.
Pour info, la ligne 354 était :

Code : Tout sélectionner

					if domoticz.devices(firmware).text ~= LAN.status[1].SoftwareVersion then
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: [DzVents] LiveBox 3 et 4

Message par Neutrino »

Ok, c'est lié à la première erreur.
Sois tu crées un dispositif text nommé Firmware LB, soit tu remplaces la ligne

Code : Tout sélectionner

local firmware = "Firmware LB" -- Nom du capteur Text Firmware LB, nil si non utilisé
par

Code : Tout sélectionner

local firmware = nil -- Nom du capteur Text Firmware LB, nil si non utilisé
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
yannig
Messages : 55
Inscription : 04 oct. 2018, 14:34

Re: [DzVents] LiveBox 3 et 4

Message par yannig »

Hello ça fonctionne sur ma Livebox play fibre. Merci pour la réactivité et les infos !
Un truc étrange je n’ai pas d’uptime alors que ça semble fonctionner dans les post au dessus.
Objets connectés :
- 7 interfaces Sauter cozytouch fil pilote
- 2 radiateurs Sauter Malao
- Bridge Cozytouch
- caméra Heden Cloud v5.6
- tondeuse Landroid Worx
- Netatmo Home Coach
Semi connecté :
- Ballon d'eau chaude Sauter Prodigio
georges54
Messages : 105
Inscription : 01 févr. 2018, 18:10

Re: [DzVents] LiveBox 3 et 4

Message par georges54 »

chez moi aussi c'est ok. Merci pour le travail réalisé.
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: [DzVents] LiveBox 3 et 4

Message par Neutrino »

yannig a écrit : 14 déc. 2018, 21:14 Un truc étrange je n’ai pas d’uptime alors que ça semble fonctionner dans les post au dessus.
Effectivement, je récupère l'uptime de la connexion DSL.
J'ai fait ce choix pendant ma campagne de réduction du nombre de requêtes...
Je n'avais pas pensé à la fibre :lol:
Désolé pour cette régression, ça reviendra à la prochaine version.
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
hawk
Messages : 5
Inscription : 09 déc. 2018, 22:09

Re: [DzVents] LiveBox 3 et 4

Message par hawk »

Installé sur LvBx 3 et fonctionne direct !!!
Gros boulot !
Merci
Répondre