LogicMachine Forum
write on modbus - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: write on modbus (/showthread.php?tid=4353)



write on modbus - CristianAgata - 06.11.2022

Hi,
I realized this script (resident 10 sec) to read data from Daikin Altherma. It seems works fine in reading mode. 
Now I need to add a cmd that writes on the 0 register 'on' when the thermostat it is 'on' and 'off' in the other case.
Best regards Cristian  
Code:
require('luamodbus') --funzioni function convert(data)   --log(data)   if data == 1 then     value = "auto"     else if data == 2 then       value = "Cooling"       else if data == 3 then         value = "Heating"         end       end     end   return(value) end function convert_2(data)   --log(data)   if data > 200 then     value = 0     else     voltage = grp.getvalue('Tensione_FTV')       return(((data / 10) * voltage)/1000)     end   return(value) end --Programma mb = luamodbus.rtu() mb:open('/dev/ttyUSB0', 19200, 'E', 8, 1, 'H') mb:connect() mb:setslave(1) local powerFull = grp.getvalue('Altherma - Powerfull') local cmd_riscaldamento = grp.getvalue('Altherma - cmd_risc') --log(cmd_riscaldamento) local value_1 = mb:readregisters(0)     if value_1 then                 grp.update('Altherma - ON-OFF', value_1)   end local value_2 = mb:readregisters(1)     if value_2 then         grp.checkupdate('Altherma - Setpoint', value_2 / 10,0.5)   end --local value_3 = mb:readregisters(3) --    if value_3 then --        grp.update('Altherma - Modi', convert(value_3)) --  end local value_4 = mb:readregisters(48)     if value_4 then       grp.checkupdate('Altherma - Temp Serbatoio', value_4 / 10, 0.5)   end local value_5 = mb:readregisters(45)     if value_5 then       grp.checkupdate('Altherma - Assorbimento', convert_2(value_5),0.01)   end local value_6 = mb:readregisters(9)     if value_6 then       grp.update('Altherma - Unit status ACS', value_6)   end local value_7 = mb:readregisters(10)     if value_7 then     grp.update('Altherma - Status Power ACS', value_7)   end local value_8 = mb:readregisters(11)     if value_8 then       grp.checkupdate('Altherma - Setpoint Water', value_8 / 10,1)   end local value_9 = mb:readregisters(12)     if value_9 then       grp.checkupdate('Altherma - Setpoint ACS', value_9 / 10,1)   end local value_10 = mb:readregisters(35)     if value_10 then       grp.checkupdate('Altherma - Temperatura Esterna', value_10 / 10, 1)   end --local value_11 = mb:readregisters(49)     --if value_11 then       --grp.checkupdate('Altherma - Temp Acqua Uscita ICP', value_11 / 10,0.5)   --end local value_12 = mb:readregisters(50)     if value_12 then       grp.checkupdate('Altherma - Temp Refrigerante', value_12 / 10,0.5)   end local value_13 = mb:readregisters(51)     if value_13 then       grp.checkupdate('Altherma - Flusso Acqua', value_13 / 10, 1)   end local value_14 = mb:readregisters(52)     if value_14 then       grp.checkupdate('Altherma - Pressione Acqua', value_14 / 10, 0.1)   end local value_15 = mb:readregisters(46)     if value_15 then       grp.checkupdate('Altherma - Temp Acqua Uscita', value_15 / 10, 0.5)   end local value_16 = mb:readregisters(47)     if value_16 then       grp.checkupdate('Altherma - Temp Acqua Ingresso', value_16 / 10, 0.5)   end local value_17 = mb:readregisters(36)     if value_17 then       grp.checkupdate('Altherma - Temperatura Ritorno', value_17 / 10,0.5)   end mb:close()



RE: write on modbus - admin - 07.11.2022

If you don't want to use a profile then simply add a write before reading the new values. But using a profile is a better approach as there won't be a delay between the object change and write. Also be careful with USB adapters as some of them are not very reliable.


RE: write on modbus - CristianAgata - 07.11.2022

(07.11.2022, 09:04)admin Wrote: If you don't want to use a profile then simply add a write before reading the new values. But using a profile is a better approach as there won't be a delay between the object change and write. Also be careful with USB adapters as some of them are not very reliable.

Thanks admin,
But this time it was a must......
BR Cristian