Hello,
i have tested. When i change the lines (your sencond pos 2.) then i become only 25.5 as Temp in my sensors.
2016-10-15 10:06:00.885 LUA: Valve TH-WZ-rechts Setpoint=8 Temp=25.5 Valve pos=0
2016-10-15 10:06:00.885 LUA: Valve TH-WZ-mitte Setpoint=8 Temp=25.5 Valve pos=0
2016-10-15 10:06:00.885 LUA: Valve TH-WZ-couch Setpoint=8 Temp=25.5 Valve pos=0
2016-10-15 10:06:00.885 LUA: Valve TH-WZ-links Setpoint=8 Temp=25.5 Valve pos=0
this is my acutal code:
Code: Select all
--./script_time_max.lua
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
package.loadlib("core.so", "*")
local Socket = require "socket"
local Basexx = require "basexx"
local Rooms = {}
local Devices = {}
local Room_nums = {}
local MaxIP = "192.168.66.30"
local MaxPort = 62910
local useWMT = false --# Set to true if there is a wall mounted thermostat in every room, then this one will be used for setpoint getting/setting
Debug = "YES" --# Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Script functions
----------------------------------------------------------------------------------------------------------
function age(timestring)
t = {}
t.year = string.sub(timestring,1,4)
t.month = string.sub(timestring,6,7)
t.day = string.sub(timestring,9,10)
t.hour = string.sub(timestring,12,13)
t.min = string.sub(timestring,15,16)
t.sec = string.sub(timestring,18,19)
return os.difftime(os.time(),os.time(t))
end
function maxCmd_H(data)
--if Debug=="YES" then print('H='..data) end
end
function maxCmd_M(data)
i = 0
j = 0
while true do --find next comma
i = string.find(data, ",", i+1)
if not i then break end
j = i
end
s = data:sub(j+1)
dec = Basexx.from_base64(s)
num_rooms = string.byte(dec,3)
pos=4
for i=1, num_rooms do
room_num = string.byte(dec, pos)
name_len = string.byte(dec, pos+1)
pos = pos+2
name = dec:sub(pos, pos+name_len-1)
pos = pos+name_len
adr = Basexx.to_hex(dec:sub(pos, pos+2))
Rooms[room_num] = name
pos = pos+3
end
num_devs = string.byte(dec, pos)
for i=1, num_devs do
dtype = string.byte(dec, pos+1)
adr = Basexx.to_hex(dec:sub(pos+2, pos+4))
snum = dec:sub(pos+5, pos+14)
name_len = string.byte(dec, pos+15)
pos = pos+16
name = dec:sub(pos, pos+name_len-1)
pos = pos+name_len
room_num = string.byte(dec, pos)
Room_nums[adr] = room_num
Devices[adr] = name
end
end
function maxCmd_C(data)
--if Debug=="YES" then print('C='..data) end
end
function maxCmd_L(data)
pos = 1
dec = Basexx.from_base64(data)
L_hex = Basexx.to_hex(dec)
L_len = string.len(L_hex)
while (pos < L_len) do
s = L_hex:sub(pos,(pos+1))
data_len = tonumber(s,16) + 1
hex = L_hex:sub(pos,pos+(data_len*2))
adr = hex:sub(3,8)
room_num = string.format("%02X", Room_nums[adr])
room = Rooms[Room_nums[adr]]
name = Devices[adr]
if not name then name=adr end
valve_info = tonumber(hex:sub(13,14),16)
batt = bit32.extract(valve_info,7,1)
bst = bit32.extract(valve_info,3,1)
mode = bit32.extract(valve_info,0,2)
if (batt==0) then sbat="OK" else sbat="Low" end
if (mode==0) then
smode="Auto"
elseif (mode==1) then
smode="Manual"
elseif (mode==2) then
smode="Holiday"
elseif (mode==3) then
smode="Boost"
end
if (data_len == 13) then -- WallMountedThermostat (dev_type 3)
valve_pos = -1
s = hex:sub(17,18)
setpoint = tonumber(s,16) / 2
s = hex:sub(23,26)
temp = tonumber(s,16) / 10
dtype = "Thermostat"
elseif (data_len == 12) then -- HeatingThermostat (dev_type 1 or 2)
s = hex:sub(15,16)
valve_pos = tonumber(s,16)
s = hex:sub(17,18)
setpoint = tonumber(s,16) / 2
if (mode ~= 2) then
s = hex:sub(19,22)
temp = tonumber(s,16) / 10
else
temp = 0
end
dtype = "Valve"
end
--Temperaturdevices den Status aktualisieren
if temp ~= 0 and dtype == "Valve" then
table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[name.." (Valve)"]..'|0|'..temp..';'..valve_pos..';0'})
elseif temp ~= 0 and dtype == "Thermostat" then
table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[room]..'|0|'..temp})
end
if smode=="Manual" then
--Update virtual devices in Domoticz and update MAX! setpoints if necessary
if Debug=="YES" then print(dtype.." "..name.." Setpoint="..setpoint.." Temp="..temp.." Valve pos="..valve_pos) end
if dtype == "Valve" then
--table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[name.." (Valve)"]..'|0|'..temp..';'..valve_pos..';0'})
if not useWMT and tonumber(otherdevices_svalues[name])~=nil then --Use valve to check setpoint mismatch
setpoint_Domoticz = tonumber(otherdevices_svalues[name])
---if name ~= "EcoTaster" and name ~= "Switch-SZ" and name ~= "Switch-WZ" then
if setpoint_Domoticz ~= setpoint then
print(otherdevices_lastupdate[name])
print(age(otherdevices_lastupdate[name]))
if otherdevices_lastupdate[name]~=nil and age(otherdevices_lastupdate[name]) > 120 then --Domoticz thermostat value must be updated
table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[name]..'|0|'..setpoint})
if Debug=="YES" then print("Domoticz setpoint updated") end
else --Max! setpoint must be updated
MaxCmdSend(adr, room_num, "manual", setpoint_Domoticz)
if Debug=="YES" then print("MAX!Valve setpoint updated") end
end
end
---end
end
elseif dtype == "Thermostat" then
--table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[room]..'|0|'..temp})
setpoint_Domoticz = tonumber(otherdevices_svalues[name])
if setpoint_Domoticz ~= setpoint then
print(otherdevices_lastupdate[name])
print(age(otherdevices_lastupdate[name]))
if otherdevices_lastupdate[name]~=nil and age(otherdevices_lastupdate[name]) > 120 then --Domoticz thermostat value must be updated
table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[name]..'|0|'..setpoint})
if Debug=="YES" then print("Domoticz setpoint updated") end
else --Max! setpoint must be updated
MaxCmdSend(adr, room_num, "manual", setpoint_Domoticz)
if Debug=="YES" then print("MAX!WMT setpoint updated") end
end
end
end
end
dtype=""
name=""
setpoint=""
temp=""
valve_pos=""
pos = pos + (data_len*2)
end
end
function MaxCmdSend(id, room, mode, setpoint)
bits = setpoint * 2
smode = string.upper(mode)
if smode == 'MANUAL' then
bits = 64 + bits
elseif smode == 'BOOST' then
bits = 192 + bits
elseif smode == 'VACATION' then
bits = 128 + bits
end
hex = "000440000000"..id..room..string.format("%x",bits)
sendStr = Basexx.to_base64(Basexx.from_hex(hex))
i, status = tcp:send("s:"..sendStr.."\r\n")
if not i then
print("MAX! TCP send failed - "..status)
return
end
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
local m = os.date('%M')
if (m % 2 == 0) then
--print("The 3 minute script interval reached")
tcp = Socket.connect(MaxIP, MaxPort)
if not tcp then
print("MAX! Socket connect failed for "..MaxIP..':'..MaxPort)
return
end
tcp:settimeout(2)
local time = os.date("*t")
while (time.min ~= 0) do
s, status, partial = tcp:receive()
if (status) then
print("MAX! TCP receive - "..status)
break
end
local line = (s or partial)
local cmd = line:sub(1,1)
local data = line:sub(3)
if (cmd == 'H') then
maxCmd_H(data)
elseif (cmd == 'M') then
maxCmd_M(data)
elseif (cmd == 'C') then
maxCmd_C(data)
elseif (cmd == 'L') then
maxCmd_L(data)
break
end
end
tcp:close()
end
return commandArray
i have also another litte Problem. i don't Understand why this is so. i Do the following:
Set Point WandTH-WZ to an Number of "10.5" all woring fine except the Valve "TH-GuestWC"
after 4 Minutes (my Script runs only all 2 Minutes) the Valce even has become the new "10.5"
but when i Cange the TH-GuestWC then only this ist Updated.
i Think that the WandTH-WZ is the Problem, bt why. When i set an new Setpoint why become the
TH-GuestWc this Value.
The WandTH-WZ is an Thermostat (WMT) and the TH-GuestWC is an Valve.
Here ist the LOG:
2016-10-15 11:34:00.624 LUA: Valve TH-Kueche Setpoint=16.5 Temp=17.7 Valve pos=0
2016-10-15 11:34:00.625 LUA: Valve TH-Flur Setpoint=8 Temp=18.8 Valve pos=0
2016-10-15 11:34:00.625 LUA: Valve TH-GuestWC Setpoint=10 Temp=15.6 Valve pos=0
2016-10-15 11:34:00.625 LUA: Thermostat WandTH-WZ Setpoint=10 Temp=18.3 Valve pos=-1
2016-10-15 11:34:00.625 LUA: Valve TH-WZ-rechts Setpoint=10 Temp=18.3 Valve pos=0
2016-10-15 11:34:00.625 LUA: Valve TH-WZ-mitte Setpoint=10 Temp=18.3 Valve pos=0
2016-10-15 11:34:00.625 LUA: Valve TH-WZ-couch Setpoint=10 Temp=0 Valve pos=0
2016-10-15 11:34:00.626 LUA: Valve TH-WZ-links Setpoint=10 Temp=0 Valve pos=0
2016-10-15 11:34:00.630 EventSystem: Script event triggered: script_time_max
2016-10-15 11:34:00.644 EventSystem: Script event triggered: script_time_variable
2016-10-15 11:35:00.220 EventSystem: Script event triggered: script_time_variable
2016-10-15 11:36:00.820 LUA: Valve TH-Kueche Setpoint=16.5 Temp=17.7 Valve pos=0
2016-10-15 11:36:00.821 LUA: Valve TH-Flur Setpoint=8 Temp=18.8 Valve pos=0
2016-10-15 11:36:00.821 LUA: Valve TH-GuestWC Setpoint=10 Temp=15.6 Valve pos=0
2016-10-15 11:36:00.821 LUA: Thermostat WandTH-WZ Setpoint=10 Temp=18.3 Valve pos=-1
2016-10-15 11:36:00.821 LUA: 2016-10-15 11:35:49
2016-10-15 11:36:00.821 LUA: 11
2016-10-15 11:36:00.822 LUA: MAX!WMT setpoint updated
2016-10-15 11:36:00.822 LUA: Valve TH-WZ-rechts Setpoint=10 Temp=18.3 Valve pos=0
2016-10-15 11:36:00.822 LUA: Valve TH-WZ-mitte Setpoint=10 Temp=18.3 Valve pos=0
2016-10-15 11:36:00.822 LUA: Valve TH-WZ-couch Setpoint=10 Temp=0 Valve pos=0
2016-10-15 11:36:00.822 LUA: Valve TH-WZ-links Setpoint=10 Temp=0 Valve pos=0
2016-10-15 11:36:00.824 EventSystem: Script event triggered: script_time_max
2016-10-15 11:36:00.831 EventSystem: Script event triggered: script_time_variable
2016-10-15 11:37:00.393 EventSystem: Script event triggered: script_time_variable
2016-10-15 11:38:01.026 LUA: Valve TH-Kueche Setpoint=16.5 Temp=17.7 Valve pos=0
2016-10-15 11:38:01.027 LUA: Valve TH-Flur Setpoint=8 Temp=18.8 Valve pos=0
2016-10-15 11:38:01.027 LUA: Valve TH-GuestWC Setpoint=10.5 Temp=15.9 Valve pos=0
2016-10-15 11:38:01.027 LUA: 2016-10-15 11:26:42
2016-10-15 11:38:01.027 LUA: 679
2016-10-15 11:38:01.027 LUA: Domoticz setpoint updated
2016-10-15 11:38:01.027 LUA: Thermostat WandTH-WZ Setpoint=10.5 Temp=18.5 Valve pos=-1
2016-10-15 11:38:01.027 LUA: Valve TH-WZ-rechts Setpoint=10.5 Temp=0 Valve pos=0
2016-10-15 11:38:01.027 LUA: Valve TH-WZ-mitte Setpoint=10.5 Temp=18.3 Valve pos=0
2016-10-15 11:38:01.028 LUA: Valve TH-WZ-couch Setpoint=10.5 Temp=18.3 Valve pos=0
2016-10-15 11:38:01.028 LUA: Valve TH-WZ-links Setpoint=10.5 Temp=18.3 Valve pos=0
2016-10-15 11:38:10.458 EventSystem: Script event triggered: script_time_variable
2016-10-15 11:38:10.500 EventSystem: Script event triggered: script_time_max
2016-10-15 11:39:00.534 EventSystem: Script event triggered: script_time_variable
Do you have an Idea ?