Page 1 of 1
Reading XML from TME - Ethernet Thermometer
Posted: Monday 02 September 2019 15:55
by laco
I need to create a script for temperature and humidity from the TME sensor.
https://github.com/MultiTricker/TMEP
Code: Select all
<root xmlns="http://www.papouch.com/xml/th2e/act">
<sns id="1" type="1" status="0" unit="0" val="18.3" w-min="" w-max="" e-min-val=" -21.1" e-max-val=" 36.8" e-min-dte="03/01/2018 04:53:57" e-max-dte="07/01/2019 15:17:17"/>
<sns id="2" type="2" status="0" unit="3" val="80.8" w-min="" w-max="" e-min-val=" 15.4" e-max-val=" 100.0" e-min-dte="04/20/2019 15:26:28" e-max-dte="06/29/2018 01:13:00"/>
<sns id="3" type="3" status="0" unit="0" val="14.9" w-min="" w-max="" e-min-val=" -24.2" e-max-val=" 20.8" e-min-dte="03/01/2018 04:53:57" e-max-dte="08/01/2018 14:06:55"/>
<status frm="1" location="Jezersko 43" time="09/02/2019 15:21:07" typesens="3"/>
</root>
id1 val="18.3" is the temperature
id2 val="80.8" is the humidity
Can someone help me? well thank you
Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 02 September 2019 16:36
by Toulon7559
This thread may have some applicable examples.
Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 02 September 2019 18:12
by waaren
Can you try this dzVents script ?
When not yet familiar with dzVents please start with reading
Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Code: Select all
local scriptVersion = '0.201909021700'
local scriptVar = 'thermometerIP_' .. scriptVersion
--[[
this dzVents script is used to collect data from ether thermometer Because there is no known API / JSON interface at the time this script was created, it uses a call to the Web Gui and interprets the returned XML code.
Before activating the script:
please read the GETTING STARTED section of the dzVents wiki.
change xxx.xxx.xxx.xxx in this script to the IP of your IP thermometer
define a dummy hardware in domoticz if not already done
define virtual sensor temp/humidity for this dummy hardware
and change the name in the device declarations
]]--
return
{
on =
{
timer = { 'every 5 minutes' },
httpResponses = { scriptVar },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
-- ********** local settings below this line *************
-- change to IP of your thermometer
local thermometerIP = 'xxx.xxx.xxx.xxx'
-- Change devicename below to reflect your device name.
-- You can also use idx but if you do don't use the surrounding quotes.
local temperatureHumidity = dz.devices('xmlTempHum')
-- ********** No changes necessary below this line *************
-- this function will call the webpage
local function getThermometerXML()
local url = 'http://' .. thermometerIP .. '9050/fresh.xml'
dz.openURL ({ url = url, callback = scriptVar })
end
local function processXML(xmlData)
local extractedData = {}
for word in string.gmatch(xmlData,"(\" val=\"%d+.%d*)") do -- loop over all 'words' in the data and extract " val="##.##
extractedData[#extractedData + 1] = word:gsub('\" val=\"','') -- put value (after removing " val=" from the found 'word')
end
return extractedData
end
local function updateDevice(values)
local function humidityStatus(temperature, humidity) -- as used in domoticz source
humidity = tonumber(humidity)
temperature = tonumber(temperature)
if humidity <= 30 then return dz.HUM_DRY
elseif humidity >= 70 then return dz.HUM_WET
elseif humidity >= 35 and humidity <= 65 and temperature >= 22 and temperature <= 26 then return dz.HUM_COMFORTABLE end
return dz.HUM_NORMAL
end
temperatureHumidity.updateTempHum(values[1], values[2], humidityStatus(values[1],values[2]))
end
-- main
if item.isTimer then
getThermometerXML()
elseif item.ok then -- statusCode == 2xx
updateDevice(processXML(item.data))
else
dz.log('Could not get (good) data from ' .. thermometerIP,dz.LOG_ERROR)
dz.log(item.data,dz.LOG_DEBUG)
end
end
}
Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 02 September 2019 22:16
by jursat
I have configured the dzVents script according to you, but if I want to load data from the Eternet thermometer, I need to log in with the username and password in the script. Could you add that, please. thx
Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 02 September 2019 23:06
by waaren
jursat wrote: Monday 02 September 2019 22:16
I have configured the dzVents script according to you, but if I want to load data from the Eternet thermometer, I need to log in with the username and password in the script.
This script can only do that if it is possible to include the username / password in the http call. Because I don't own the device myself I need your help on how the http call including these should look like, if at all possible with this type of script.
Re: Reading XML from TME - Ethernet Thermometer
Posted: Tuesday 03 September 2019 17:58
by jursat
Thank you for your help, solved.
I wrote down my name and password in the line local url = 'http://user:password@' .. thermometerIP .. ':9050/fresh.xml'
Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 07 October 2019 10:47
by jursat
Do you know why the graph does not show values below zero?

Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 07 October 2019 12:17
by waaren
jursat wrote: Monday 07 October 2019 10:47
Do you know why the graph does not show values below zero?
Yes. It's because of a bug in the procesXML function
To fix; replace the function with
Code: Select all
local function processXML(xmlData)
local extractedData = {}
for word in string.gmatch(xmlData,"(\" val=\"%-*%+*%d+.%d*)") do -- loop over all 'words' in the data and extract " val="##.## or " val = "-##.##"
extractedData[#extractedData + 1] = word:gsub('\" val=\"','') -- put value (after removing " val=" from the found 'word')
end
return extractedData
end
Re: Reading XML from TME - Ethernet Thermometer
Posted: Monday 07 October 2019 15:40
by jursat
Thank you very much, I'll fix it
Re: Reading XML from TME - Ethernet Thermometer
Posted: Saturday 26 December 2020 14:52
by laco
I have 2 databases on my server
MariaDB 5 port: 3306 and MariaDB 10 port: 3307
writes this setting to localhost 3306 by default
how can I change the entry to localhost 3307?
Thanks