Reading XML from TME - Ethernet Thermometer Topic is solved

Moderator: leecollings

Post Reply
User avatar
laco
Posts: 86
Joined: Tuesday 30 October 2018 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: Slovensko
Contact:

Reading XML from TME - Ethernet Thermometer

Post 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
Last edited by laco on Friday 14 October 2022 9:21, edited 1 time in total.
Toulon7559
Posts: 858
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post by Toulon7559 »

This thread may have some applicable examples.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post by waaren »

laco wrote: Monday 02 September 2019 15:55 I need to create a script for temperature and humidity from the TME sensor. https://www.papouch.com/en/shop/product ... ermometer/
Can someone help me? well thank you
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jursat
Posts: 26
Joined: Monday 14 January 2019 20:58
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Slowakia
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jursat
Posts: 26
Joined: Monday 14 January 2019 20:58
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Slowakia
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post 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'
User avatar
jursat
Posts: 26
Joined: Monday 14 January 2019 20:58
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Slowakia
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post by jursat »

Do you know why the graph does not show values below zero?

Image
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post 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 :oops:
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jursat
Posts: 26
Joined: Monday 14 January 2019 20:58
Target OS: NAS (Synology & others)
Domoticz version: 2023.2
Location: Slowakia
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post by jursat »

Thank you very much, I'll fix it
User avatar
laco
Posts: 86
Joined: Tuesday 30 October 2018 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: Slovensko
Contact:

Re: Reading XML from TME - Ethernet Thermometer

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest