LogicMachine Forum
Resident script pump circulation - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Resident script pump circulation (/showthread.php?tid=1279)

Pages: 1 2 3 4


RE: Resident script pump circulation - Domoticatorino - 10.03.2018

(10.03.2018, 17:16)buuuudzik Wrote:
(10.03.2018, 17:14)Domoticatorino Wrote: It is a Schneider HL 2.0.1

I mean updated version of above scriptWink I've adjusted it to be more universal, added new variables:
Code:
valveStatesTag = 'circulation_pump' pumpGA = '1/1/10' openingValveTime = 300 -- time for fully open the valve (maximum time for next calculation) minInterval = 30 -- minimum offset for next calculation opened, firstTimestamp = false, 0 valveStates = grp.tag(valveStatesTag) for v = 1, #valveStates, 1 do  valveState = valveStates[v]  if valveState.value then    opened = true    if firstTimestamp > 0 then        if firstTimestamp > valveState.updatetime then firstTimestamp = valveState.updatetime end    else        firstTimestamp = valveState.updatetime    end  end end if opened then    fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime    if fullyOpened then        grp.checkwrite(pumpGA, true)        nextCalculationAfter = minInterval    else        grp.checkwrite(pumpGA, false)        nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)    nextCalculationAfter = openingValveTime + 1 end log('Next calculation after: ' .. nextCalculationAfter .. 's.') os.sleep(nextCalculationAfter)

No, it does not work.
there is not any mistake and any error log. Is there the opportunity to have a debug for lua?


RE: Resident script pump circulation - buuuudzik - 10.03.2018

What are your settings? It is resident script 0s? Did you tried disable and enable script? Did you add the tag to valves? Do you changed the GA for pump?

When script start it should log such message in the Logs:

Code:
Circulation pump calculation 10.03.2018 18:33:49 * string: Next calculation after: 293s.



RE: Resident script pump circulation - Domoticatorino - 10.03.2018

It is a resident script set at 60 seconds.
Obviously I add tag and change address of pump. In the log I read "next calculation after" but pumps does not start.


RE: Resident script pump circulation - buuuudzik - 10.03.2018

(10.03.2018, 18:36)Domoticatorino Wrote: It is a resident script set at 60 seconds.
Obviously I add tag and change address of pump. In the log I read "next calculation after" but pumps does not start.

Please change the time to 0, update script to the newest version, disable and enable it and it must work.

I've checked it and all works perfect. You can also comment this line with log.


RE: Resident script pump circulation - Domoticatorino - 18.03.2018

Thank you very much. It works!!
Great


RE: Resident script pump circulation - Domoticatorino - 24.04.2018

Code:
valveStatesTagEstate = 'pompa_circolazione_giorno_estate' valveStatesTagInverno = 'pompa_circolazione_giorno_inverno' pumpGA = '2/0/1' openingValveTime = 60 -- time for fully open the valve (maximum time for next calculation) minInterval = 30 -- minimum offset for next calculation opened, firstTimestamp = false, 0 if stagione == false then     valveStatesEstate = grp.tag(valveStatesTagEstate)     for v = 1, #valveStatesEstate, 1 do      valveStateEstate = valveStatesEstate[v]      if valveStateEstate.value then        opened = true        if firstTimestamp > 0 then          if firstTimestamp > valveStateEstate.updatetime then firstTimestamp = valveStateEstate.updatetime end        else          firstTimestamp = valveStateEstate.updatetime        end      end  end else    valveStatesInverno = grp.tag(valveStatesTagInverno)    for v = 1, #valveStatesInverno, 1 do      valveStateInverno = valveStatesInverno[v]      if valveStateInverno.value then        opened = true        if firstTimestamp > 0 then          if firstTimestamp > valveStateInverno.updatetime then firstTimestamp = valveStateInverno.updatetime end        else          firstTimestamp = valveStateInverno.updatetime        end      end end end if opened then    fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime    if fullyOpened then        grp.checkwrite(pumpGA, true)        nextCalculationAfter = minInterval    else        grp.checkwrite(pumpGA, false)        nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)    nextCalculationAfter = openingValveTime + 1 end -- log('Next calculation after: ' .. nextCalculationAfter .. 's.') log(valveStatesEstate) os.sleep(nextCalculationAfter)
Hi,
In your opinion what is wrong in this script above. I add a condition to separate winter condition from summer condition.

I log variable log(valveStatesEstate) but the result is nil. Objects tags are correct and in other 2 scripts (the same) everything works fine.

I cannot understand the reason why it does not working. I expect to read TRUE in log (valveStateEstate).

Thank you for your help.


RE: Resident script pump circulation - buuuudzik - 24.04.2018

You are trying to log value 'ValveStatesEstate' but you hasn't defined stagione so stagione equals nil so else condition is executed.

But generally when you extend this script maybe better would be create some function and do script more elastic also for the futureWink

See below (but still you must define stagione!):

Code:
valveStatesTagEstate = 'pompa_circolazione_giorno_estate' valveStatesTagInverno = 'pompa_circolazione_giorno_inverno' pumpGA = '2/0/1' openingValveTime = 60 -- time for fully open the valve (maximum time for next calculation) minInterval = 30 -- minimum offset for next calculation opened, firstTimestamp = false, 0 function getParamsFromValveStates(valvesTag)     local valveStates = grp.tag(valveStatesTag)     for v = 1, #valveStates, 1 do       valveState = valveStates[v]       if valveState.value then         opened = true         if firstTimestamp > 0 then             if firstTimestamp > valveState.updatetime then firstTimestamp = valveState.updatetime end         else             firstTimestamp = valveState.updatetime         end       end     end return opened, firstTimestamp end if not stagione then opened, firstTimestamp = getParamsFromValveStates(valveStatesTagEstate) else opened, firstTimestamp = getParamsFromValveStates(valveStatesTagInverno) end if opened then    fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime    if fullyOpened then        grp.checkwrite(pumpGA, true)        nextCalculationAfter = minInterval    else        grp.checkwrite(pumpGA, false)        nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)    nextCalculationAfter = openingValveTime + 1 end -- log('Next calculation after: ' .. nextCalculationAfter .. 's.') os.sleep(nextCalculationAfter)



RE: Resident script pump circulation - Domoticatorino - 24.04.2018

(24.04.2018, 17:03)buuuudzik Wrote: You are trying to log value 'ValveStatesEstate' but you hasn't defined stagione so stagione equals nil so else condition is executed.

But generally when you extend this script maybe better would be create some function and do script more elastic also for the futureWink

See below (but still you must define stagione!):

Code:
valveStatesTagEstate = 'pompa_circolazione_giorno_estate' valveStatesTagInverno = 'pompa_circolazione_giorno_inverno' pumpGA = '2/0/1' openingValveTime = 60 -- time for fully open the valve (maximum time for next calculation) minInterval = 30 -- minimum offset for next calculation opened, firstTimestamp = false, 0 function getParamsFromValveStates(valvesTag)     local valveStates = grp.tag(valveStatesTag)     for v = 1, #valveStates, 1 do       valveState = valveStates[v]       if valveState.value then         opened = true         if firstTimestamp > 0 then             if firstTimestamp > valveState.updatetime then firstTimestamp = valveState.updatetime end         else             firstTimestamp = valveState.updatetime         end       end     end return opened, firstTimestamp end if not stagione then opened, firstTimestamp = getParamsFromValveStates(valveStatesTagEstate) else opened, firstTimestamp = getParamsFromValveStates(valveStatesTagInverno) end if opened then    fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime    if fullyOpened then        grp.checkwrite(pumpGA, true)        nextCalculationAfter = minInterval    else        grp.checkwrite(pumpGA, false)        nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)    nextCalculationAfter = openingValveTime + 1 end -- log('Next calculation after: ' .. nextCalculationAfter .. 's.') os.sleep(nextCalculationAfter)

Thank you very much...stupid mistake!! I have to hire you  Wink


RE: Resident script pump circulation - buuuudzik - 24.04.2018

Nice Smile


RE: Resident script pump circulation - Domoticatorino - 24.04.2018

How long do you code Lua?


RE: Resident script pump circulation - buuuudzik - 25.04.2018

(24.04.2018, 23:24)ODomoticatorino Wrote: How long do you code  Lua?

3-4 years with Logic Machine. Sometimes less sometimes more. But I’ve asked a lot of questions also on this forumSmile Now I like more Javascript than Lua and LM would be for me perfect with modern JS instead the LuaWink


RE: Resident script pump circulation - Domoticatorino - 25.04.2018

Wow cool. I am using LM for 2 years and I hope to improve my skills in coding.

You are very good. Thanks.


RE: Resident script pump circulation - buuuudzik - 25.04.2018

For sure, be patient, try and askWink


RE: Resident script pump circulation - Domoticatorino - 24.10.2018

Hi there,
I have a big problem with the script below. Please consider that I have 3 same script (obviosly with different varables) and everyting works fine. The one below does not work anymore.

I have seen in the obkect list that last update of group address 2/0/2 was dated 16th of September. The other correctly dated today. I cannot understand the reason why it does not work anymore. And nothing changed.

I tried to delate scritp and redo it without success. I tried to do again object 2/0/2 without success. Nothing group address 2/0/2 never update. Could you help me please?

Thanks.

Code:
valveStatesTagEstate = 'pompa_circolazione_mansarda_estate' valveStatesTagInverno = 'pompa_circolazione_mansarda_inverno' stagione = grp.getvalue('2/0/100') pumpGA = '2/0/2' openingValveTime = 60 -- time for fully open the valve (maximum time for next calculation) minInterval = 30 -- minimum offset for next calculation opened, firstTimestamp = false, 0 if stagione == false then     valveStatesEstate = grp.tag(valveStatesTagEstate)     for v = 1, #valveStatesEstate, 1 do      valveStateEstate = valveStatesEstate[v]      if valveStateEstate.value then        opened = true        if firstTimestamp > 0 then          if firstTimestamp > valveStateEstate.updatetime then firstTimestamp = valveStateEstate.updatetime end        else          firstTimestamp = valveStateEstate.updatetime        end      end  end else    valveStatesInverno = grp.tag(valveStatesTagInverno)    for v = 1, #valveStatesInverno, 1 do      valveStateInverno = valveStatesInverno[v]      if valveStateInverno.value then        opened = true        if firstTimestamp > 0 then          if firstTimestamp > valveStateInverno.updatetime then firstTimestamp = valveStateInverno.updatetime end        else          firstTimestamp = valveStateInverno.updatetime        end      end end end if opened then    fullyOpened = (os.microtime() - firstTimestamp) >= openingValveTime    if fullyOpened then        grp.checkwrite(pumpGA, true)        nextCalculationAfter = minInterval    else        grp.checkwrite(pumpGA, false)        nextCalculationAfter = openingValveTime + 1 - (os.microtime() - firstTimestamp) -- run a little after possible change    end else    grp.checkwrite(pumpGA, false)    nextCalculationAfter = openingValveTime + 1 end -- log('Next calculation after: ' .. nextCalculationAfter .. 's.') os.sleep(nextCalculationAfter)



RE: Resident script pump circulation - admin - 24.10.2018

Add some logging to your script before any grp.checkwrite call. Since it uses grp.checkwrite there won't be any value sent unless it changes.


RE: Resident script pump circulation - Domoticatorino - 24.10.2018

Ok, log of which variable? Thanks


RE: Resident script pump circulation - admin - 24.10.2018

Add this before os.sleep, this will give some info where the script is going:
Code:
log(stagione, opened, os.time(), firstTimestamp)



RE: Resident script pump circulation - buuuudzik - 24.10.2018

Please:

Code:
log(valveStates)


Maybe you have some error in tags.


RE: Resident script pump circulation - Domoticatorino - 24.10.2018

(24.10.2018, 12:20)buuuudzik Wrote: Please:

Code:
log(valveStates)


Maybe you have some error in tags.

Here below the log:

Tesy_pompa_circolazione_mansarda 24.10.2018 14:36:47
* table:
[1]
 * table:
  [export]
   * number: 0
  [disablelog]
   * number: 1
  [tagcache]
   * string: clima, pompa_circolazione_mansarda_inverno, pompa_circolazione_mansarda_estate
  [datahex]
   * string: 00
  [units]
   * string:
  [value]
   * bool: false
  [comment]
   * string:
  [updatetime]
   * number: 1540384570
  [datatype]
   * number: 1009
  [address]
   * string: 2/0/107
  [id]
   * number: 4203
  [data]
   * bool: false
  [highpriolog]
   * number: 0
  [pollinterval]
   * string:
  [readoninit]
   * number: 0
  [name]
   * string: T7 FB Elettrovalvola pavimento mansarda
  [decoded]
   * bool: true



[size=undefined]
Tesy_pompa_circolazione_mansarda 24.10.2018 14:36:47
* arg: 1
 * bool: true
* arg: 2
 * bool: false
* arg: 3
 * number: 1540384607
* arg: 4
 * number: 0[/size]



RE: Resident script pump circulation - admin - 24.10.2018

The last script you've posted does not have valveStates variable anywhere, please post the latest version that you are using. Also, try turning 2/0/107 on.