ELV Max! Heating control system

For heating/cooling related questions in Domoticz
michass
Posts: 23
Joined: Tuesday 27 March 2018 14:39
Target OS: NAS (Synology & others)
Domoticz version: 4.10064
Location: Gdynia
Contact:

Re: ELV Max! Heating control system

Post by michass » Wednesday 12 September 2018 13:15

Hi,
I have MAX! system and Synology based Domoticz.
Please help me with configure this in Synology enviroment.
Thanks in advance
Michał
Synology NAS
Heating: eq-3 MAX!
Vent: by Sonoff POW R2 & Espeasy
Cam: Foscam C1

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Thursday 20 September 2018 15:28

What am I doing wrong??
my script looks like this:

Code: Select all

-- Script which creates & synchronizes devices in Domoticz with values from MAX! cube
-- Change variables below to your own values
-- Start by adding new cronjob "*/5 * * * * /usr/bin/lua /home/pi/domoticz/scripts/lua/maxscript.lua" (using crontab -e) 

MaxIP='192.168.*.***' -- IP adress of your Cube, best to check via your router
MaxPort = 62910        -- Port used by your Cube, usually 62910
DomoticzPort = ****    -- Port used by Domoticz, 8080 is the default
useWMT = false          -- Set to true if there is a wall mounted thermostat in every room
interval = 5           -- Polling interval in minutes, fill in same value as in crontab
setpoint_DoorOpen = 1  -- Setpoint when door/window open

json   = (loadfile "/home/ubuntu/domoticz/scripts/lua/JSON.lua")()  -- uncomment if you're using Linux (comment next line)
--json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")()    -- uncomment if you're using Windows (comment previous line)

----------------------------------------
-- No changes required below this line -
----------------------------------------

package.loadlib("core.so", "*")
Socket = require "socket"
Basexx = require "basexx"
http   = require "socket.http"

Rooms   = {}
Devices = {}
Types   = {}
Room_nums = {}

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 get_MAX_ID()
  result, statuscode, content = http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=hardware')
  r,e = json:decode(result)
  if r.status == "OK" then
    for k,v in pairs(r.result) do
      if v.Name == "MAX!" then return v.idx end
    end
  end
end

function ReadThermostat(DID)
  result, statuscode, content = http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=devices')
  r,e = json:decode(result)
  if r.status == "OK" then
    for k,v in pairs(r.result) do
      if v.ID == DID then return v.SetPoint,v.LastUpdate end
    end
  end
  return 0, '2016-01-01 00:00:00'  -- value to return if device was not found
end

function UpdateValve(DID, value)
  http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&hid='..MAX_ID..'&did='..DID..'&dunit=1&dtype=243&dsubtype=6&nvalue=0&svalue='..value)
end

function UpdateTemperature(DID, value)
  http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&hid='..MAX_ID..'&did='..DID..'&dunit=1&dtype=80&dsubtype=5&nvalue=0&svalue='..value)
end

function UpdateSwitch(DID, status)
  if status == "On" then
    http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&hid='..MAX_ID..'&did='..DID..'&dunit=1&dtype=17&dsubtype=0&nvalue=1')
  elseif status == "Off" then
    http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&hid='..MAX_ID..'&did='..DID..'&dunit=1&dtype=17&dsubtype=0&nvalue=0')
  end
end

function SetpointSync(DID, devicename, setpoint_MAX)
  setpoint_Domoticz, LastUpdate = ReadThermostat(DID)
  if tonumber(setpoint_Domoticz) ~= setpoint_MAX then
    if age(LastUpdate) > interval * 60 then -- Domoticz thermostat value must be updated
      http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&hid='..MAX_ID..'&did='..DID..'&dunit=1&dtype=242&dsubtype=1&nvalue=0&svalue='..setpoint_MAX)
      print(os.date("%x %X ")..'Domoticz setpoint '..devicename..' set to '..setpoint..' degrees')
      http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=addlogmessage&message='..string.gsub('Domoticz setpoint '..devicename..' set to '..setpoint_MAX..' degrees',' ','%%20'))
    elseif setpoint_Domoticz ~= setpoint_DoorOpen then -- MAX! setpoint must be updated
      MaxCmdSend(adr, room_num, "MANUAL", setpoint_Domoticz)
      print(os.date("%x %X ")..'MAX! setpoint '..devicename..' set to '..setpoint_Domoticz..' degrees')
      http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=addlogmessage&message='..string.gsub('MAX! setpoint '..devicename..' set to '..setpoint_Domoticz..' degrees',' ','%%20'))
    end
  end
end

function maxCmd_H(data)
--   print('H='..data)
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)
  
  if num_rooms == 0 or num_rooms == nil then
    http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=addlogmessage&message=MAX!%20configuration%20error!')
  end
  
  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
    Types[adr] = dtype
  end
end

function maxCmd_C(data)
--   print('C='..data)
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]
    dtype = Types[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 dtype == 3 then	-- WallMountedThermostat
      s = hex:sub(17,18)
      setpoint = tonumber(s,16) / 2
      if setpoint > 50 then setpoint = setpoint - 64 end
      s = hex:sub(23,26)
      temp = tonumber(s,16) / 10
      if temp < 5 then temp = temp + 25.5 end  -- temporary solution for 2 digit hex temperature limitation
      UpdateTemperature(adr, temp)
      SetpointSync('0'..adr, name, setpoint)

    elseif dtype == 1 or dtype == 2 then -- Valve
      s = hex:sub(15,16)
      valve_pos = tonumber(s,16)
      s = hex:sub(17,18)
      setpoint = tonumber(s,16) / 2
      if setpoint > 50 then setpoint = setpoint - 64 end
      s = hex:sub(19,22)
      temp = tonumber(s,16) / 10
      if temp < 5 then temp = temp + 25.5 end  -- temporary solution for 2 digit hex temperature limitation
      UpdateValve(adr, valve_pos)
      if not useWMT then -- Use valve for temp & setpoint
        if temp ~= 0 then UpdateTemperature(adr, temp) end
        SetpointSync('0'..adr, name, setpoint)
      end

    elseif dtype == 4 then -- Door/window sensor
      if mode == 2 then UpdateSwitch(adr, "On") else UpdateSwitch(adr, "Off") end
    end

    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

-----------------------
-- Main script start --
-----------------------

  --Get ID of MAX hardware in Domoticz, create if it doesn't exist
  MAX_ID = get_MAX_ID()
  if MAX_ID == nil then  -- "MAX!" dummy hardware not yet created, create it
    http.request('http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=addhardware&htype=15&port=1&name=MAX!&enabled=true')
  end

  tcp = Socket.connect(MaxIP, MaxPort)
  if not tcp then
    print("Socket connect failed for "..MaxIP..':'..MaxPort)
    return
  end
  tcp:settimeout(2)

  while true do
    s, status, partial = tcp:receive()
    if (status) then
      print("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
      status = maxCmd_H(data)
      if status == 'Error' then break end
    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()
The first run of the script causes an error:

Code: Select all

lua: maxscript.lua:62: attempt to concatenate global 'MAX_ID' (a nil value)                                                                                                                                                                                                                                                
stack traceback:                                                                                                                                                                                                                                                                                                           
        maxscript.lua:62: in function 'UpdateValve'                                                                                                                                                                                                                                                                        
        maxscript.lua:189: in function 'maxCmd_L'                                                                                                                                                                                                                                                                          
        maxscript.lua:259: in main chunk                                                                                                                                                                                                                                                                                   
        [C]: in ?              
        
However, in the domotic in the hardware tab, a new item appears.
Hardware.JPG
Hardware.JPG (22.82 KiB) Viewed 564 times
The next launch of the script no longer contains errors.

Code: Select all

09/20/18 15:19:19 Domoticz setpoint Agatka-Rad set to 17 degrees                                                                                                                                                                                                                                                           
09/20/18 15:19:19 Domoticz setpoint Podłoga Łazienka-Rad set to 17 degrees                                                                                                                                                                                                                                                 
09/20/18 15:19:19 Domoticz setpoint Podłoga Kuchnia-Rad set to 17 degrees                                                                                                                                                                                                                                                  
09/20/18 15:19:19 Domoticz setpoint Sypialnia-Rad set to 17 degrees                                                                                                                                                                                                                                                        
09/20/18 15:19:19 Domoticz setpoint Podłoga Kuchnia-Stat set to 17 degrees                                                                                                                                                                                                                                                 
09/20/18 15:19:19 Domoticz setpoint Salon-Rad set to 17 degrees                                                                                                                                                                                                                                                            
09/20/18 15:19:19 Domoticz setpoint Podłoga Łazienka-Stat set to 17 degrees                                                                                                                                                                                                                                                
09/20/18 15:19:19 Domoticz setpoint Łazienka-Rad set to 17 degrees                                                                                                                                                                                                                                                         
09/20/18 15:19:19 Domoticz setpoint Łazienka-Stat set to 17 degrees    
But there are no new devices in the device tab.


Logs in domoticz indicate that the data is reaching correctly.

Code: Select all

2018-09-20 15:19:18.158 Status: Incoming connection from: 127.0.0.1
2018-09-20 15:19:19.010 Status: Domoticz setpoint Agatka-Rad set to 17 degrees
2018-09-20 15:19:19.067 Status: Domoticz setpoint Podłoga Łazienka-Rad set to 17 degrees
2018-09-20 15:19:19.123 Status: Domoticz setpoint Podłoga Kuchnia-Rad set to 17 degrees
2018-09-20 15:19:19.172 Status: Domoticz setpoint Sypialnia-Rad set to 17 degrees
2018-09-20 15:19:19.218 Status: Domoticz setpoint Podłoga Kuchnia-Stat set to 17 degrees
2018-09-20 15:19:19.268 Status: Domoticz setpoint Salon-Rad set to 17 degrees
2018-09-20 15:19:19.314 Status: Domoticz setpoint Podłoga Łazienka-Stat set to 17 degrees
2018-09-20 15:19:19.363 Status: Domoticz setpoint Łazienka-Rad set to 17 degrees
2018-09-20 15:19:19.409 Status: Domoticz setpoint Łazienka-Stat set to 17 degrees
The whole domoticz system operates in container station on qnap.

Please help.
Post written using the Google translator.

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

ELV Max! Heating control system

Post by mvzut » Thursday 20 September 2018 22:52

That the script gives an error the first time it is launched is normal, it needs to create the new (virtual) hardware on the first run. During the second run, it should automatically create the devices, but I have noticed it doesn't do this anymore. The JSON commands that the script uses for this are no longer functioning as they did before, many (beta) versions back. They still update existing devices, but they don't create new ones anymore if the given device doesn't exist yet. I have posted a question about this on the forum quite some time ago, but received no reaction from the Domoticz authors yet.
I am currently thinking about a solution for this. My ultimate wish is to make a Python plugin, but this requires me to learn Python and dive into the plugin architecture. That takes time that I currently don't have. Alternatively, you can follow the process as described on the Wiki (https://www.domoticz.com/wiki/EQ3_MAX!). This requires you to create the devices yourself, but once you have done that everything should work smoothly.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Friday 21 September 2018 9:29

Thank you for your answer. I created new devices manually and used the script_time_max.lua script described on the wiki. Only door sensors do not work for me. Is it possible for the door sensors to show their status?
door sensor.JPG
door sensor.JPG (30.15 KiB) Viewed 545 times

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

ELV Max! Heating control system

Post by mvzut » Saturday 22 September 2018 13:24

Can you try the script below? I haven't tested it myself, but it should work in theory. It requires you to create virtual on/off switches with the same name as defined for the window/door switches in the e-Q3/ELV MAX configuration software.

Code: Select all

 --./script_time_max.lua
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
package.loadlib("core.so", "*")
local Socket = require "socket"
local Basexx = require "basexx"

local MaxIP='192.168.178.46'
local MaxPort = 62910
local useWMT = true --Set to true if there is a wall mounted thermostat in every room
local interval = 5 --Polling interval in minutes, possible range 1-59. Cube doesn't seem to like too frequent communication, 5 minutes is a safe value
local DomoticzPort = 8080

local Rooms   = {}
local Devices = {}
local Types   = {}
local Room_nums = {}

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)
--   print('H='..data)
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
      Types[adr] = dtype
   end

end

function maxCmd_C(data)
--   print('C='..data)
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
      dtype = Types[adr]
      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 (dtype == 3) then
        valve_pos = -1
        s = hex:sub(17,18)
        setpoint = tonumber(s,16) / 2
        s = hex:sub(23,26)
        temp = tonumber(s,16) / 10
      elseif (dtype == 1 or dtype == 2) then
        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
      end

      
      --Following two lines correct temperatures over 25.5 degrees, since e.g. 26 degrees is reported as 0.5 degrees
      --This is due to the fact that temperatures seem to be stored as two Hex characters only (= max 255 in decimal)
      --Pending better solution
      if temp < 5 then temp = temp + 25.5 end
      if setpoint > 50 then setpoint = setpoint - 64 end

      -- Update virtual devices in Domoticz and update MAX! setpoints if necessary

      --print(dtype.."  "..name.."  Setpoint="..setpoint.."  Temp="..temp.."  Valve pos="..valve_pos)

      -- Commands for valve
      if (dtype == 1 or dtype == 2) and name:sub(-5,-1) ~= "-Sens" then
        table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[name]..'|0|'..valve_pos})   
        if not useWMT then --Use valve to update temperature and synchronize setpoints
          name = name:sub(1,-5) .. "-Stat"  -- set thermostat name to valve name with "-Stat" instead of "-Rad" suffix
          setpoint_Domoticz = tonumber(otherdevices_svalues[name])
          if setpoint_Domoticz ~= setpoint then
            if age(otherdevices_lastupdate[name]) > interval * 60 then --Domoticz thermostat value must be updated
              table.insert(commandArray, { ['OpenURL'] = 'http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&idx='..otherdevices_idx[name]..'&nvalue=0&svalue='..setpoint})
              print('Domoticz setpoint ' .. name .. ' updated')
            else --Max! setpoint must be updated
              MaxCmdSend(adr, room_num, "manual", setpoint_Domoticz)
              print('MAX! setpoint ' .. name .. ' updated')
            end
          end
        end

      -- Commands for thermostat
      elseif dtype == 3 then
        table.insert(commandArray, { ['UpdateDevice'] = otherdevices_idx[room]..'|0|'..temp})
        setpoint_Domoticz = tonumber(otherdevices_svalues[name])
        if setpoint_Domoticz ~= setpoint then
          if age(otherdevices_lastupdate[name]) > interval * 60 then --Domoticz thermostat value must be updated
            table.insert(commandArray, { ['OpenURL'] = 'http://127.0.0.1:'..DomoticzPort..'/json.htm?type=command&param=udevice&idx='..otherdevices_idx[name]..'&nvalue=0&svalue='..setpoint})
            print('Domoticz setpoint ' .. name .. ' updated')
          else --Max! setpoint must be updated
            MaxCmdSend(adr, room_num, "manual", setpoint_Domoticz)
            print('MAX! setpoint ' .. name .. ' updated')
          end
        end

      -- Commands for door/window sensor
      elseif dtype == 4 then
        if mode == 2 then
          commandArray[name] = "On"
        else
          commandArray[name] = "Off"
        end
      end

      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 = {}

local m = os.date('%M')
if (m % interval == 0) and (m ~= 0) then

  tcp = Socket.connect(MaxIP, MaxPort)
  if not tcp then
    print("Socket connect failed for "..MaxIP..':'..MaxPort)
    return
  end
  tcp:settimeout(2)

  while true do
    s, status, partial = tcp:receive()
    if (status) then
      print("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
      status = maxCmd_H(data)
      if status == 'Error' then break end
    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
Last edited by mvzut on Saturday 22 September 2018 13:24, edited 3 times in total.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Saturday 22 September 2018 15:28

After applying the script, it receives error.

Code: Select all

2018-09-22 15:20:00.987 Error: EventSystem: in /home/ubuntu/domoticz/scripts/lua/script_time_max.lua: /home/ubuntu/domoticz/scripts/lua/script_time_max.lua:72: attempt to index global 'Types' (a nil value)
I also came up with such a way to read window sensors, only that it works only with the head turned on, so it would have to work all year long.
event.JPG
event.JPG (25.44 KiB) Viewed 522 times

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: ELV Max! Heating control system

Post by mvzut » Saturday 22 September 2018 15:47

Oops, forgot to declare a new array in the beginning of the code. I have updated the code two posts back, can you check again?
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Saturday 22 September 2018 17:16

Now he gets the following error in domoticz log:

Code: Select all

2018-09-22 17:07:01.258 Error: EventSystem: in /home/ubuntu/domoticz/scripts/lua/script_time_max.lua: /home/ubuntu/domoticz/scripts/lua/script_time_max.lua:173: attempt to index global 'CommandArray' (a nil value)
If I run this script in the console then:

Code: Select all

lua: script_time_max.lua:139: attempt to index global 'otherdevices_idx' (a nil value)                                                                                                                                                                                                                                     
stack traceback:                                                                                                                                                                                                                                                                                                           
        script_time_max.lua:139: in function 'maxCmd_L'                                                                                                                                                                                                                                                                    
        script_time_max.lua:236: in main chunk                                                                                                                                                                                                                                                                             
        [C]: in ?

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: ELV Max! Heating control system

Post by mvzut » Saturday 22 September 2018 17:21

Found two typos, that's the disadvantage of writing code without testing (I have no access to my Pi currently). Can you check again? (Post above updated)
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Saturday 22 September 2018 17:53

Everything works now. I am very happy. I will try to add an additional switch - "auto manual eco boost".

Thank you very much for your help, which is invaluable.

I will add that running the script from the console causes an error, but everything works so it probably is not important.

Code: Select all

lua: script_time_max.lua:139: attempt to index global 'otherdevices_idx' (a nil value)                                                                                                                                                                                                                                     
stack traceback:                                                                                                                                                                                                                                                                                                           
        script_time_max.lua:139: in function 'maxCmd_L'                                                                                                                                                                                                                                                                    
        script_time_max.lua:236: in main chunk                                                                                                                                                                                                                                                                             
        [C]: in ?  

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

ELV Max! Heating control system

Post by mvzut » Saturday 22 September 2018 17:58

You're welcome!

Please share how you add the auto/manual/eco/boost button, so others can be inspired by it.

By the way, it is perfectly normal that LUA scripts give errors when run from the command line, because they are not able to communicate with Domoticz using commands like 'otherdevices[..]', 'commandArray[..]' etc. in this situation.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Saturday 22 September 2018 18:12

If only I can implement such a button, I will certainly share my knowledge. However, I do not have much experience with domotic, so I may not succeed.

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

ELV Max! Heating control system

Post by mvzut » Monday 24 September 2018 10:29

biomm wrote:Dear all,
After a few successful years my system (R Pi + eMAX! + Lua script) stopped to response. Lua script (with crontab) - fine, eMAX! devices are OK as well so... the only reason might be new router (!!)
Some minuter later it was obvious that new device is NOT able to set "static IP" and from time to time IP of eMAX! Cube was changing (why new devices are lacking such an important setting??)

As stated in Lua sript it should be possible to use IP or NAME of Cube device:
-- Enter your cube name or ip address and port here
--MaxIP='192.168.x.x'
MaxIP='LEQ1234567'
MaxPort=62910
/source - wiki - EQ3 MAX/

For some reason in my case IP is working fine while NAME is not working at all.
Script test results: Socket connect failed for 'LEQ1234567"

I would appreciate advice / help - checking each time for IP and paste it to max script is possible BUT very annoying - especially winter time while heating is ON.....
Strange, for me it works fine with the name instead of the ip address!
What you could try is the following code instead of MaxIP='LEQ1234567':

Code: Select all

 MaxIP = Socket.dns.toip('LEQ1234567')
If this also fails, you can type "arp" <enter> from the command line on your pi, to check under which exact name your Cube is known to the system.

P.S. I'm not exactly sure, but I believe you can configure the Cube (using the provided software) to get an automatic IP adress or not. If you enter the fixed address here that you have in your script, it will probably also work.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

nono212
Posts: 30
Joined: Sunday 18 December 2016 14:47
Target OS: Linux
Domoticz version: 3.6179
Contact:

Re: ELV Max! Heating control system

Post by nono212 » Monday 24 September 2018 14:11

Hi Guys
I have the same problem as michass I would like to use Max Heating with Domoticz (but it is runing the Jahdal 6.2 on synology )
So no Lua available
Can you help

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: ELV Max! Heating control system

Post by mvzut » Monday 24 September 2018 18:28

nono212 wrote:Hi Guys
I have the same problem as michass I would like to use Max Heating with Domoticz (but it is runing the Jahdal 6.2 on synology )
So no Lua available
Can you help
I have no experience with Domoticz on a Synology, is there no Lua package available for this system?
I assume it does run time- and event-based Lua scripts inside Domoticz? In that case, you can skip the test script part in the Wiki and set up the time-based Lua script as described there (after manually creating the devices). Use the version shown a few posts back if you also need support for door/window switches (I'll see if I can update the Wiki soon).
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

nono212
Posts: 30
Joined: Sunday 18 December 2016 14:47
Target OS: Linux
Domoticz version: 3.6179
Contact:

Re: ELV Max! Heating control system

Post by nono212 » Monday 24 September 2018 23:03

In fact I have a Domoticz on Pi ( an old one )
and I have my current Domoticz on Synology Is there a way to export the eq3 data to put it in the new Domoticz ?
Because I had a running eq-3 solution on the Pi but I migrate almost everything on the synology .
Can you help mvzut ?

Regards

and for info I type LUA on syno and nothing hapend:
nono212@syno:~$ lua
-sh: lua: command not found

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Tuesday 25 September 2018 20:24

I have domoticz installed on the qnap server and I also had a problem with the lua on the dedicated application. I solved this by installing the ubuntu xenial system in the docker.
Docker from ubuntu has its own IP address and logs in to it using the console. Then it's just like in a normal Linux.

nono212
Posts: 30
Joined: Sunday 18 December 2016 14:47
Target OS: Linux
Domoticz version: 3.6179
Contact:

Re: ELV Max! Heating control system

Post by nono212 » Wednesday 26 September 2018 18:54

but I am not using Docker I am using the image of JAhdal http://www.jadahl.com/

Regards

mvzut
Posts: 427
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

ELV Max! Heating control system

Post by mvzut » Thursday 27 September 2018 23:04

Hi all,

Finally I had some time to dive into the new Python plugin system. It was a steep learning curve, since I had no prior Python experience, but I think I succeeded, mostly... So here is my ELV/eQ-3 MAX! Python plugin for Domoticz!

https://github.com/mvzut/maxcube-Domoticz-plugin

I made use of a very well written Cube API by "hackercowbow", so many of the credits go to him.
Please note that the plugin has only been tested on a Raspberry Pi with the latest Beta (although it will probably work on the latest stable as well). You can install it by typing in a terminal:

Code: Select all

cd ~/domoticz/plugins
git clone https://github.com/mvzut/maxcube-Domoticz-plugin MaxCube
Then restart Domoticz, and find the newly added plugin under Setup > Hardware.
Activate the plugin by selecting it from the "Type" drop-down menu, fill in the parameters (on-screen explanation is given) and click "Add".
If all goes as intended, it should automatically create all MAX devices for you (using the names it receives from the Cube), update all devices with the given interval, and change thermostat setpoints on your Cube if you change them in Domoticz. Note that you can safely rename devices to anything you want, unlike previous solutions this plugin doesn't need specific names to function.

Who is willing to test it? I'm sure there are still bugs in it that I didn't encounter yet. For testing purposes, you can safely run it next to your existing MAX integration method. If at least a couple of people get it to work without problems, I'll probably create a dedicated topic on this plugin.

Hoping for your feedback!
MaxCube.jpeg
MaxCube.jpeg (205.3 KiB) Viewed 398 times
Last edited by mvzut on Friday 28 September 2018 8:25, edited 3 times in total.
Raspberry Pi 3 - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Xiaomi Gateway - Sonos - IP cameras - Wall mounted tablet + Imperihome - MANY switches/sensors

sakekl
Posts: 13
Joined: Thursday 20 September 2018 14:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: ELV Max! Heating control system

Post by sakekl » Friday 28 September 2018 0:15

I can not make it today, but I will start testing tomorrow. Nice job and respect for you.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests