Aller au contenu

Messages recommandés

Posté(e)
Le 10/03/2017 à 09:40, Steven a dit :

Je te propose et conseil de modifier les toutes dernières lignes du VD ainsi : 

 


pcall(function() 
	Zibase.putSensorsInMemory()
	local time = os.date("le %d.%m.%Y à  %H:%M:%S")
	if (Zibase.errors > 0) then time = "Erreur : " .. Zibase.errors end
	fibaro:call(fibaro:getSelfId(),"setProperty","ui.Label1.value",time)
end)
fibaro:sleep(maj*1000)

Le fait d'entourer le code par "pcall" évite le module de planter. Si une erreur survient, il sera relancé les prochaines 30 secondes.

 

 

Pour le fake device, le seul module z-wave qui vaut vraiment la peine serait l'oeil de sauron (FGMS)

C'est copié, je test sur le temps et vous dit ça ;)

 

ok pour le fake je vais faire l'achat du capteur du coup et après ? 

Posté(e)

Trouvé ! 

 ADN182 :  Création d'une Fake Device

J'utilise ici la procédure de @Lazer (Voir Post ici)

En voici les grandes lignes : 

  • on inclue un module (du type qu'on souhaite (consommation, température, détecteur, etc))
  • on le reset (via appui long sur le bouton, selon la méthode décrite dans la doc) sans l'exclure de la HC2
  • il passe en noeud mort
  • en décoche la case 'marquer comme mort' => le module ne sera plus jamais mort, même si il n'existe plus
  • en peut l'utiliser à  vie pour updater ses propriétés via l'API
  • Puis on recommande la procédure décrite ci-dessus autant de fois qu'on souhaite, afin d'avoir une infinité de modules, qui remplacent parfaitement les plugins.

 

Je n'ai aucun mérite juste fait un copier coller de ton post Merci a Lui !

 

 

Pour la Zibase 

Mise à jour

Erreur : 1

 

-- This script will request sensors.xml file from a Zibase
-- and use it to change global variables.

-- Version = "1.0.0"

-- Author = "Domotique-Info.fr (Steven Piccand)"

-- Info = "Memory is preserved: Object are only load once in memory"-- This program is free software: you can redistribute it and/or modify

-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
-- You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

local maj = 30 -- Durée en secondes de la mise à jour

-- --------------------------------------------------------------------------------------------------------------
-- Check that one and only one instance is in memory
-- --------------------------------------------------------------------------------------------------------------
if ((not Zibase) or (Zibase.errors >= 5)) then

	Zibase = {
  		errors = 0
    }
	
	-- --------------------------------------------------------------------------------------------------------------
	-- Miscellaneous
	-- --------------------------------------------------------------------------------------------------------------
  	Zibase.url = fibaro:get(fibaro:getSelfId(), 'IPAddress')
	Zibase.port = fibaro:get(fibaro:getSelfId(), 'TCPPort')

	-- --------------------------------------------------------------------------------------------------------------
	-- Get the XML from the zibase and return it as a LUA table
	-- --------------------------------------------------------------------------------------------------------------
	Zibase.getXml = function() 
		--local zibaseURL = Net.FHttp("zibase.net");
		--response, status, errorCode = zibaseURL:GET("/m/get_xml_sensors.php?device="..Zibase.id.."&token="..Zibase.token);
		local zibaseURL = Net.FHttp(Zibase.url)
		response, status, errorCode = zibaseURL:GET("/sensors.xml")
		return Zibase.iif(response ~= nil, Zibase.newParser().ParseXmlText(response), "")
	end

	-- --------------------------------------------------------------------------------------------------------------
	-- Put all Sensors values in global variables
	-- --------------------------------------------------------------------------------------------------------------
	Zibase.putSensorsInMemory = function(id)
		local xmlTable = Zibase.getXml()
		if (xmlTable) then 
      		if (not xmlTable.doc) then 
        		Zibase.errors = Zibase.errors+1 
        		return nil
      		end
			local evs = xmlTable.doc.evs
			for i in pairs(evs:children()) do
				local idtmp = evs.ev[i]["@id"]
				if (evs.ev[i]["@pro"]) then 
					idtmp = evs.ev[i]["@pro"] .. idtmp
				else
					if (evs.ev[i]["@type"] == "2") then idtmp = "VS" .. idtmp
					elseif (evs.ev[i]["@type"] == "6") then idtmp = "CS" .. idtmp
					elseif (evs.ev[i]["@type"] == "7") then idtmp = "OS" .. idtmp
					elseif (evs.ev[i]["@type"] == "8") then idtmp = "VR" .. idtmp
					elseif (evs.ev[i]["@type"] == "10") then idtmp = "WS" .. idtmp
					end
				end
				if (not id) then
					fibaro:setGlobal(idtmp.."_V1", evs.ev[i]["@v1"])
					fibaro:setGlobal(idtmp.."_V2", evs.ev[i]["@v2"])
				elseif ((id ~= nil) and (idtmp == id)) then
					values = {}
					values[1] = evs.ev[i]["@v1"]
					values[2] = evs.ev[i]["@v2"]
					return values
				end
			end
		end
		return nil
	end
	
	-- --------------------------------------------------------------------------------------------------------------
	-- Get the values (v1 and v2) of a sensor from the zibase
	-- --------------------------------------------------------------------------------------------------------------
	Zibase.getSensorValues = function(id)
		if (id ~= nil) then
			return Zibase.putSensorsInMemory(id)
		else
			return nil
		end
	end

	-- --------------------------------------------------------------------------------------------------------------
	-- Get the value from a variable from the zibase
	-- --------------------------------------------------------------------------------------------------------------
	Zibase.getVariable = function(num)
		local xmlTable = Zibase.getXml()
		if (xmlTable) then
      		if (not xmlTable.doc) then 
        		Zibase.errors = Zibase.errors+1 
        		return ""
     		end
			local vars = xmlTable.doc.vars
			for i in pairs(vars:children()) do
				if (vars.var[i]["@num"] == num) then
					return vars.var[i]["@val"] 
				end
			end
		end
		return ""
	end

	-- -------------------------------------------------------------------------------------------------------------
	-- Test the condition and return true or false param depending of the result
	-- param : condition (condition to test)
	--            iftrue (result to return of condition if true)
	--            iftfalse (result to return of condition if false)
	-- -------------------------------------------------------------------------------------------------------------
	Zibase.iif = function(condition, iftrue, iffalse)
		if (condition) then
			return iftrue
		end
		return iffalse
	end

	-- -------------------------------------------------------------------------------------------------------------
	-- Return a random number from 1 to 100
	-- -------------------------------------------------------------------------------------------------------------
	Zibase.random = function()
		return math.random(100)
	end

	-- -------------------------------------------------------------------------------------------------------------
	-- This is a modified version of Corona-XML-Module by Jonathan Beebe which in turn 
	-- is based on Alexander Makeev's Lua-only XML parser .
	-- see https://github.com/Cluain/Lua-Simple-XML-Parser
	-- -------------------------------------------------------------------------------------------------------------
	Zibase.newParser = function()

		parseXml = {}

		parseXml.FromXmlString = function(value)
			value = string.gsub(value, "&#x([%x]+)%;",
			    function(h)
				return string.char(tonumber(h, 16))
			    end);
			value = string.gsub(value, "&#([0-9]+)%;",
			    function(h)
				return string.char(tonumber(h, 10))
			    end);
			value = string.gsub(value, "\"", "\"");
			value = string.gsub(value, "'", "'");
			value = string.gsub(value, ">", ">");
			value = string.gsub(value, "<", "<");
			value = string.gsub(value, "&", "&");
			return value;
		end

		parseXml.ParseArgs = function(node, s)
			string.gsub(s, "(%w+)=([\"'])(.-)%2", function(w, _, a)
			    node:addProperty(w,  parseXml.FromXmlString(a))
			end)
		end

		parseXml.ParseXmlText = function(xmlText)
			local stack = {}
			local top = parseXml.newNode()
			table.insert(stack, top)
			local ni, c, label, xarg, empty
			local i, j = 1, 1
			while true do
			    ni, j, c, label, xarg, empty = string.find(xmlText, "<(%/?)([%w_:]+)(.-)(%/?)>", i)
			    if not ni then break end
			    local text = string.sub(xmlText, i, ni - 1);
			    if not string.find(text, "^%s*$") then
				local lVal = (top:value() or "") .. parseXml.FromXmlString(text)
				stack[#stack]:setValue(lVal)
			    end
			    if empty == "/" then -- empty element tag
				local lNode = parseXml.newNode(label)
				parseXml.ParseArgs(lNode, xarg)
				top:addChild(lNode)
			    elseif c == "" then -- start tag
				local lNode = parseXml.newNode(label)
				parseXml.ParseArgs(lNode, xarg)
				table.insert(stack, lNode)
				top = lNode
			    else -- end tag
				local toclose = table.remove(stack) -- remove top

				top = stack[#stack]
				if #stack < 1 then
				    error("XmlParser: nothing to close with " .. label)
				end
				if toclose:name() ~= label then
				    error("XmlParser: trying to close " .. toclose.name .. " with " .. label)
				end
				top:addChild(toclose)
			    end
			    i = j + 1
			end
			local text = string.sub(xmlText, i);
			if #stack > 1 then
			    error("XmlParser: unclosed " .. stack[#stack]:name())
			end
			return top
		end

		parseXml.newNode = function(name)
		    local node = {}
		    node.___value = nil
		    node.___name = name
		    node.___children = {}
		    node.___props = {}
		    function node:value() return self.___value end
		    function node:setValue(val) self.___value = val end
		    function node:name() return self.___name end
		    function node:setName(name) self.___name = name end
		    function node:children() return self.___children end
		    function node:numChildren() return #self.___children end
		    function node:addChild(child)
			if self[child:name()] ~= nil then
			    if type(self[child:name()].name) == "function" then
				local tempTable = {}
				table.insert(tempTable, self[child:name()])
				self[child:name()] = tempTable
			    end
			    table.insert(self[child:name()], child)
			else
			    self[child:name()] = child
			end
			table.insert(self.___children, child)
		    end
		    function node:properties() return self.___props end
		    function node:numProperties() return #self.___props end
		    function node:addProperty(name, value)
			local lName = "@" .. name
			if self[lName] ~= nil then
			    if type(self[lName]) == "string" then
				local tempTable = {}
				table.insert(tempTable, self[lName])
				self[lName] = tempTable
			    end
			    table.insert(self[lName], value)
			else
			    self[lName] = value
			end
			table.insert(self.___props, { name = name, value = self[name] })
		    end
		    return node
		end

		return parseXml;
	end

end

-- -------------------------------------------------------------------------------------------------------------
-- Send a message in the default chat frame if debug mode is activated
-- param : sMessage (message to display)
-- return : <none>
-- -------------------------------------------------------------------------------------------------------------

pcall(function() 
	Zibase.putSensorsInMemory()
	local time = os.date("le %d.%m.%Y à  %H:%M:%S")
	if (Zibase.errors > 0) then time = "Erreur : " .. Zibase.errors end
	fibaro:call(fibaro:getSelfId(),"setProperty","ui.Label1.value",time)
end)
fibaro:sleep(maj*1000)

 

×
×
  • Créer...