<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.domoticz.com/index.php?action=history&amp;feed=atom&amp;title=Inserting_raw_lua_parsers</id>
	<title>Inserting raw lua parsers - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.domoticz.com/index.php?action=history&amp;feed=atom&amp;title=Inserting_raw_lua_parsers"/>
	<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Inserting_raw_lua_parsers&amp;action=history"/>
	<updated>2026-09-18T20:43:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.domoticz.com/index.php?title=Inserting_raw_lua_parsers&amp;diff=4840&amp;oldid=prev</id>
		<title>Leplan73 at 21:08, 6 November 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.domoticz.com/index.php?title=Inserting_raw_lua_parsers&amp;diff=4840&amp;oldid=prev"/>
		<updated>2015-11-06T21:08:05Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Let&amp;#039;s describe a new way to insert data using lua scripts&lt;br /&gt;
&lt;br /&gt;
[[Example]]: You have a nice hardware like the Yocto-Meteo [http://www.yoctopuce.com/EN/products/usb-environmental-sensors/yocto-meteo] from Yoctopuce [http://www.yoctopuce.com] and you want to insert the sensors data into Domoticz&lt;br /&gt;
&lt;br /&gt;
The idea is to use Yoctopuce&amp;#039;s &amp;#039;&amp;#039;&amp;#039;VirtualHub&amp;#039;&amp;#039;&amp;#039; (a process exposing the sensors) to push the data to an external HTTP server, that&amp;#039;s call the &amp;#039;&amp;#039;&amp;#039;Outgoing callbacks&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
The overall architecture is quiet simple: Yoctopuce&amp;#039;s VirtualHub is pushing the data with HTTP to a new Domoticz&amp;#039;s entry point, once received the data is parsed by a lua script and the parsed data can to inserted into any devices&lt;br /&gt;
&lt;br /&gt;
== Step 1 : Configuring VirtualHub ==&lt;br /&gt;
&lt;br /&gt;
Connect to port 4444 and configure the Outgoing callbacks as followed :&lt;br /&gt;
&lt;br /&gt;
[[File:inserting_raw_lua_parsers.png]]&lt;br /&gt;
&lt;br /&gt;
* HTTP Method : GET&lt;br /&gt;
* Callback : &amp;#039;&amp;#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;domoticz ip&amp;gt;:&amp;lt;domoticz port&amp;gt;/json.htm?type=command&amp;amp;param=&amp;#039;&amp;#039;&amp;#039;udevices&amp;#039;&amp;#039;&amp;#039;&amp;amp;script=&amp;#039;&amp;#039;&amp;#039;yoctopuce_meteo.lua&amp;#039;&amp;#039;&amp;#039;&amp;amp;&amp;lt;/nowiki&amp;gt;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Some explanations :&lt;br /&gt;
* Notice the ending &amp;#039;&amp;amp;&amp;#039;, it is mandatory because VirtualHub will append its data to the url&lt;br /&gt;
* &amp;quot;udevices&amp;quot; is the new command&lt;br /&gt;
* yoctopuce_meteo.lua is the name of the lua script to be used to parse incoming data&lt;br /&gt;
* The HTTP method is &amp;#039;GET&amp;#039; and the HTTP query made to Domoticz will look like : &amp;#039;&amp;#039;&amp;lt;nowiki&amp;gt;http://&amp;lt;domoticz ip&amp;gt;:&amp;lt;domoticz port&amp;gt;/json.htm?type=command&amp;amp;param=udevices&amp;amp;script=yoctopuce_meteo.lua&amp;amp;timestamp=1446371516&amp;amp;network=&amp;amp;meteo%23dataLogger=OFF&amp;amp;meteo%23temperature=5.72&amp;amp;meteo%23pressure=889&amp;amp;meteo%23humidity=81.1&amp;lt;/nowiki&amp;gt;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Step 2 : Create a dummy device ==&lt;br /&gt;
&lt;br /&gt;
Create a dummy device and note the device index, it will be useful just below&lt;br /&gt;
&lt;br /&gt;
== Step 3 : Parse the data ==&lt;br /&gt;
&lt;br /&gt;
Domoticz is designed to execute the lua script defined in the url (defined in Step 1) and parse the HTTP data (query + &amp;#039;POST&amp;#039; data if defined). The script has to be added to &amp;lt;domoticz path&amp;gt;/scripts/lua_parsers&lt;br /&gt;
Here is the script use to parse the VirtualHub&amp;#039;s data:&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
local temperature = uri[&amp;#039;meteo#temperature&amp;#039;];&amp;lt;BR&amp;gt;&lt;br /&gt;
local humidity = uri[&amp;#039;meteo#humidity&amp;#039;];&lt;br /&gt;
local pressure = uri[&amp;#039;meteo#pressure&amp;#039;];&lt;br /&gt;
&lt;br /&gt;
domoticz_updateDevice(15,0,temperature .. &amp;quot;;&amp;quot; .. humidity .. &amp;quot;;&amp;quot; .. &amp;quot;0&amp;quot; .. &amp;quot;;&amp;quot; .. pressure .. &amp;quot;;&amp;quot; .. &amp;quot;0&amp;quot;);&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some explanations:&lt;br /&gt;
&lt;br /&gt;
* 2 internals global lua variables are defined :&lt;br /&gt;
** request[&amp;quot;content&amp;quot;] : Contains the query data (when using &amp;#039;POST&amp;#039; HTTP method)&lt;br /&gt;
** uri : It&amp;#039;s an associative array with all HTTP query parameters. From the above query, the array will contain several entries like uri[&amp;#039;timestamp&amp;#039;], uri[&amp;#039;meteo#temperature&amp;#039;], uri[&amp;#039;meteo#humidity&amp;#039;], uri[&amp;#039;meteo#pressure&amp;#039;] etc...&lt;br /&gt;
* a lua function called &amp;#039;&amp;#039;&amp;#039;domoticz_updateDevice&amp;#039;&amp;#039;&amp;#039; can be used to assign a (or several) values to a device: The parameters are &amp;lt;device id&amp;gt;, &amp;lt;nvalue&amp;gt;, &amp;lt;svalue&amp;gt;. See [https://www.domoticz.com/wiki/Domoticz_API/JSON_URL&amp;#039;s#Update_devices] for more details&lt;/div&gt;</summary>
		<author><name>Leplan73</name></author>
	</entry>
</feed>