This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Resident script pump circulation
#21
(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?
Reply
#22
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.
Done is better than perfect
Reply
#23
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.
Reply
#24
(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.
Done is better than perfect
Reply
#25
Thank you very much. It works!!
Great
Reply
#26
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.
Reply
#27
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)
Done is better than perfect
Reply
#28
(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
Reply
#29
Nice Smile
Done is better than perfect
Reply
#30
How long do you code Lua?
Reply
#31
(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
Done is better than perfect
Reply
#32
Wow cool. I am using LM for 2 years and I hope to improve my skills in coding.

You are very good. Thanks.
Reply
#33
For sure, be patient, try and askWink
Done is better than perfect
Reply
#34
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)
Reply
#35
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.
Reply
#36
Ok, log of which variable? Thanks
Reply
#37
Add this before os.sleep, this will give some info where the script is going:
Code:
log(stagione, opened, os.time(), firstTimestamp)
Reply
#38
Please:

Code:
log(valveStates)


Maybe you have some error in tags.
Done is better than perfect
Reply
#39
(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]
Reply
#40
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.
Reply


Forum Jump: