Heatmiser PRT wifi thermostat successfully read with lua

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
benp
Posts: 52
Joined: Saturday 21 May 2016 20:12
Target OS: NAS (Synology & others)
Domoticz version: V4.10717
Location: France
Contact:

Heatmiser PRT wifi thermostat successfully read with lua

Post by benp »

I use this method with the reference: PRTHW-TS WIFI
It should work with DT-TS WIFI, PRT-TS WIFI and PRT-E WIFI
It sould not work on Neo (I don't know the protocol)
The data can be readen with a LUA script only.
The only difficult part is to install the socket library because it is not integrted in the domoticz+lua images (is it possible to include it in the future).
The steps are described for domoticz on rabberry2 + fillezilla(windows)+android phone

Here are the steps:
Step 1:Install the socket library
Download usrlocalsharelua5p2.tar.gz and usrlocalliblua5p2.tar.gz to /home/pi/temp with filezilla on the raspberry.
On the raspberry terminal (putty for me)
Copy usrlocalsharelua5p2.tar.gz in directory /usr/local/share/lua/5.2/ and extracting the file with sudo tar -xvf usrlocalsharelua5p2.tar.gz
Copy usrlocalliblua5p2.tar.gz in /usr/local/lib/lua/5.2/ and extract all the files with sudo tar -xvf usrlocalliblua5p2.tar.gz
linux command:
cd /usr/local/share/lua/5.2/
sudo cp /home/pi/temp/usrlocalsharelua5p2.tar.gz .
sudo tar -xvf usrlocalsharelua5p2.tar.gz
cd /usr/local/lib/lua/5.2/
sudo cp /home/pi/temp/usrlocalliblua5p2
sudo tar -xvf usrlocalliblua5p2.tar.gz

Step 2: Find the TCP binary command with your android phone
Install and configure Heatmiser on your android device
Install Packet capture on your android device
Start packet capture
Start and connect to heatmiser
Stop packet capture
Look at the heatmiser capture packet capture + preference Hex. You should have number starting with 93

Step 3: Copy the TCP binary into this lua script time - line 12(local nb=)
Only AA BB (pin code) and CC DD (CRC) sould change for you.

Code: Select all

commandArray = {}

local host, port = "192.168.0.9", 8068
local socket = require("socket")
local tcp = assert(socket.tcp())

local status=tcp:connect(host, port);
print("TCP status:" .. status)
tcp:settimeout(1000)

--see protocol p22 in Heatmiser V3 protocol pdf
local nb=tcp:send(string.char( 0x93, 0x0b, 0x00, 0xAA, 0xBB, 0x00, 0x00, 0xff, 0xff, 0xCC, 0xDD))
print("TCP send lenth:" .. nb)
local data = tcp:receive(50) --receive 50 bytes
tcp:close()


print("TCP receive length:" .. string.len(data)) -- longueur de chaine
--print("TCP raw data 37+38:" .. string.byte(data,45) .. " " .. string.byte(data,46)) --raw temp data 45=37+8 46=38+8
local airTemp=(string.byte(data,45)+string.byte(data,46)*256)/10
print("raw temp45:" .. string.byte(data,45) .. "|raw temp46:" .. string.byte(data,46))
local setTemp=string.byte(data,26)
local heatStatus
if (string.byte(data,48)>0) then heatStatus='On' else heatStatus='Off' end
print("TCP air temp:" .. airTemp .. " setTemp:" .. setTemp .. " Heat:" .. heatStatus)

commandArray['Th. chauffe']=heatStatus --set dummy switch Th. Chauffe
commandArray[2]={['UpdateDevice']='24|1|' .. airTemp} --set temperature of dummy 24/1
commandArray[1]={['UpdateDevice']='25|1|' .. setTemp} --set temperature of dummy 25/1

return commandArray
Before activate this script, you must create 2 dummy temperature device and 1 dummy switch
You must change:
switch name line 27
temperature device number line 28+29
ip port of the heatmiser wifi thermostat

You should be able to get any other data with this script and the protocol

Reference:
heatmiser_v3_protocol_3.9.pdf (I don't know how to upload it ;2024Ko). I will try to put it on another server if not possible (not avaiable on heatmiser website since 2014)
edit: here on the waybackmachine:
https://web.archive.org/web/20130304022 ... l-document
The protocol is page 22
Reading (starts with 0x93)
Reply (starts with 0x94)
http://www.domoticz.com/forum/viewtopic ... 638#p22638 for lua socket

Possible improvement:
Remove the luacolor from the socket lbray of the attached files
I can give you the right code for pin 1234 if somebody want it.
Automatic CRC calculation (if somebody can do the code)
Send data to the thermostat (easy once CRC done)
Attachments
usrlocalliblua5p2.tar.gz
(119.53 KiB) Downloaded 85 times
usrlocalsharelua5p2.tar.gz
(117.12 KiB) Downloaded 78 times
Last edited by benp on Sunday 08 July 2018 21:17, edited 2 times in total.
Domoticz V2024.7
benp
Posts: 52
Joined: Saturday 21 May 2016 20:12
Target OS: NAS (Synology & others)
Domoticz version: V4.10717
Location: France
Contact:

Heatmiser PRT wifi thermostat

Post by benp »

-
Last edited by benp on Sunday 08 July 2018 21:16, edited 2 times in total.
Domoticz V2024.7
benp
Posts: 52
Joined: Saturday 21 May 2016 20:12
Target OS: NAS (Synology & others)
Domoticz version: V4.10717
Location: France
Contact:

Re: Heatmiser PRT wifi thermostat successfully read with lua

Post by benp »

New lua code with hour reading and alarm if hour difference between heatmiser thermostat and domoticz is more than 10 minutes:

Code: Select all

commandArray = {}

local host, port = "192.168.0.9", 8068
local socket = require("socket")
local tcp = assert(socket.tcp())

local status=tcp:connect(host, port);
--print("TCP status:" .. status)
tcp:settimeout(1000)

--see protocol p22 in Heatmiser V3 protocol pdf
local nb=tcp:send(string.char( 0x93, 0x0b, 0x00, 0x52, 0x04, 0x00, 0x00, 0xff, 0xff, 0x08, 0x60))
--print("TCP send lenth:" .. nb)
local data = tcp:receive(60) --receive 50 bytes
tcp:close()

local yy="2000"+string.byte(data,52)
local mm=string.byte(data,53)
local dd=string.byte(data,54)
local hh=string.byte(data,56)
local mi=string.byte(data,57)
local ss=string.byte(data,58)

local   t1 = os.time()
local   t2 = os.time{year=yy, month=mm, day=dd, hour=hh, min=mi, sec=ss}
local   dif = os.difftime (t2, t1)
--print("yy=" .. yy .. " mm=" ..mm.. " dd=" ..dd.. " hh=" ..hh.. " mi=" .. mi .. " ss=".. ss)
--print(t1)
--print(t2)
print ("Erreur horloge heatmiser:" .. dif .. "s")
if ( math.abs(dif)>600) then --si plus de 10 min d erreur envoyer un sms
    if (otherdevices['Alarme Heatmiser']=='Off') then 
       commandArray['Alarme Heatmiser']='On'
    end
end

if ( math.abs(dif)<600) then --si moins de 10 min d erreur RAZ alarme
    if (otherdevices['Alarme Heatmiser']=='On') then 
       commandArray['Alarme Heatmiser']='Off'
    end
end

--print("blabla")

--print("TCP receive length:" .. string.len(data)) -- longueur de chaine
--print("TCP raw data 37+38:" .. string.byte(data,45) .. " " .. string.byte(data,46)) --raw temp data 45=37+8 46=38+8
local airTemp=(string.byte(data,45)+string.byte(data,46)*256)/10
--print("raw temp45:" .. string.byte(data,45) .. "|raw temp46:" .. string.byte(data,46))
local setTemp=string.byte(data,26)
local heatStatus
if (string.byte(data,48)>0) then heatStatus='On' else heatStatus='Off' end
print("TCP air temp:" .. airTemp .. " setTemp:" .. setTemp .. " Heat:" .. heatStatus)
--print(otherdevices['Th. chauffe'])
if (not(otherdevices['Th. chauffe']==heatStatus)) then 
    commandArray['Th. chauffe']=heatStatus --set dummy switch Th. Chauffe
    print('Nouveau status' .. heatStatus)
end
commandArray[2]={['UpdateDevice']='24|1|' .. airTemp} --set temperature of dummy 24/1
commandArray[1]={['UpdateDevice']='25|1|' .. setTemp} --set temperature of dummy 25/1

return commandArray
Domoticz V2024.7
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest