I want to connect my Waterkotte Ecotouch heatpump to LM/W4k. I have a working .php script what is running on my Raspberry. This script I want to transfer to LM.
To start with: My goal is to read "TEMPERATURE_OUTSIDE" and write it to a group address and write "ENABLE_HEATING" from a group address.
Is this possible? Has anybody an idea how to start?
Try running this code and post what you get in Logs. Change ip, user and pwd variables as needed.
Code:
http = require('socket.http')
ip = '192.168.178.100' -- ip address of Waterkotte heat pump
user = 'XXX' -- username of web interface
pwd = 'XXX' -- password of web interface
url = 'http://' .. ip .. '/cgi/login?username=' .. user .. '&password=' .. pwd
res, code = http.request(url)
log('login request', res, code)
if res and code == 200 then
token = res:match('%x+')
log('token', token)
if type(token) == 'string' and #token == 32 then
storage.set('ecotouch-token', token)
end
end
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A1'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
end
@admin: Many thanks again for your big help! Highly appreciated!
I made two script sets out of it.
The first one is to read the actual values I'm interested in:
Code:
http = require('socket.http')
ip = 'xxx' -- ip address of Waterkotte heat pump
user = 'xxx' -- username of web interface
pwd = 'xxx' -- password of web interface
url = 'http://' .. ip .. '/cgi/login?username=' .. user .. '&password=' .. pwd
res, code = http.request(url)
log('login request', res, code)
if res and code == 200 then
token = res:match('IDALToken=(%x+)')
log('token', token)
if type(token) == 'string' and #token == 32 then
storage.set('ecotouch-token', token)
end
end
-- Read actual hot water temperature ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A19'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/1', value/10)
end
end
os.sleep(1)
-- Read actual source in temperature ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A4'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/2', value/10)
end
end
os.sleep(1)
-- Read actual source out temperature ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A5'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/3', value/10)
end
end
os.sleep(1)
-- ************************************************************
-- Read actual return temperature ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A11'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/4', value/10)
end
end
os.sleep(1)
-- Read actual flow temperature ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A12'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/5', value/10)
end
end
os.sleep(1)
-- ************************************************************
-- Read actual power compressor ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A25'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/6', value/10)
end
end
os.sleep(1)
-- Read actual power heating****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A26'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/7', value/10)
end
end
os.sleep(1)
-- Read actual COP***************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A28'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/1/8', value/10)
end
end
-- Read desrired hot water temperature ****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=A37'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
grp.checkupdate('46/3/1', value/10)
end
end
os.sleep(1)
-- Read status heeting mode****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=I30'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
if value == 1
then
value = true
elseif
value == 0
then
value = false
end
grp.checkupdate('46/3/2', value)
end
end
os.sleep(1)
-- Read status cooling mode****************************
if token then
url = 'http://' .. ip .. '/cgi/readTags?n=1&t1=I31'
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
value = res:match('S_OK%s+%d+%s+(%d+)')
if value then
value = tonumber(value)
-- log(value)
if value == 1
then
value = true
elseif
value == 0
then
value = false
end
grp.checkupdate('46/3/3', value)
end
end
os.sleep(1)
And the second one to write the desired values:
Code:
http = require('socket.http')
ip = 'xxx' -- ip address of Waterkotte heat pump
user = 'xxx' -- username of web interface
pwd = 'xxx' -- password of web interface
url = 'http://' .. ip .. '/cgi/login?username=' .. user .. '&password=' .. pwd
res, code = http.request(url)
log('login request', res, code)
if res and code == 200 then
token = res:match('IDALToken=(%x+)')
log('token', token)
if type(token) == 'string' and #token == 32 then
storage.set('ecotouch-token', token)
end
end
os.sleep(1)
-- Write enable heating mode ****************************
setvalue = grp.getvalue('46/2/2')
if setvalue == true
then setvalue = 1
else setvalue = 0
end
if token then
url = 'http://' .. ip .. '/cgi/writeTags?returnValue=true&n=1&t1=I30&v1='..setvalue
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
end
os.sleep(1)
-- Write enable cooling mode ****************************
setvalue = grp.getvalue('46/2/3')
if setvalue == true
then setvalue = 1
else setvalue = 0
end
if token then
url = 'http://' .. ip .. '/cgi/writeTags?returnValue=true&n=1&t1=I31&v1='..setvalue
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
end
os.sleep(1)
-- Write water temperature****************************
setvalue = grp.getvalue('46/2/1')
setvalue = setvalue *10
if token then
url = 'http://' .. ip .. '/cgi/writeTags?returnValue=true&n=1&t1=A38&v1='..setvalue
res, code = http.request({
url = url,
headers = {
['Cookie'] = 'IDALToken=' .. token
}
})
log('read request', res, code)
end
Generally it works fine EXCEPT when the time between two request is to short I getting the following return in the log and the values are not written to the heatpump:
@admin: Do you have an idea how to control the situation? Do I need to detect: "#E_TOO_MANY_USERS" and then wait some second and resend? How would this look like? Many thanks for your help!
The login procedure should not be performed for each request. The token is already saved into storage so it should be used in read/write requests. If the request fails with an error then the token should be refreshed.