Page 1 of 1
Fish pond pump script
Posted: Saturday 23 September 2017 22:30
by D3LTA
Anyone here knows if there is a Fish pond pump script that deals with time and weather data?
i searched everywhere and also tried making my own from some heating scripts but without any luck and working script....
what i'm looking for is a script that sets on the pond pump x time (for example 2 hours and then off) at a x interval (example 2 hours on and 1 hours off and repeats that )
and if the temperature is below a x variable (like 0 degrees) it will not turn in on at all of turns is on continuously
i truly hope some of you could help me out or can give me some examples to work with.
(made serveral bash and python scripts, but i can't seem too figure out this one)
thanks alot
Re: Fish pond pump script
Posted: Sunday 24 September 2017 11:57
by zicht
In Lua, just give youre some idea;s to get you started with the timing :
put the time/date table in variable time
Code: Select all
if (time.hour==7 or time.hour==19) and time.min==0 then ....pump on or off ..... end
time.hour contains the hours of time.
time.min contains the minite of time
Code: Select all
if ((time.min% 2)==0) then ..... end
would run every 2 minutes, this can also be done with time.hour.
Dont forget to load the table in time (first sentence)
Re: Fish pond pump script
Posted: Sunday 24 September 2017 18:25
by D3LTA
thanks for the push in right direction.. will give it a shot tonight.. is it okay if i post my progress here.. so you can maybe help me out a little?
Re: Fish pond pump script
Posted: Sunday 24 September 2017 21:51
by zicht
D3LTA wrote: ↑Sunday 24 September 2017 18:25
thanks for the push in right direction.. will give it a shot tonight.. is it okay if i post my progress here.. so you can maybe help me out a little?
See PM and yes you can post it here if you made something, that way others can benefit or think together with you
Re: Fish pond pump script
Posted: Monday 25 September 2017 6:13
by Egregius
With pass2php times are quite easy:
Code: Select all
<?php
$temp=status('temperature');
$pump=status('pump');
if($temp>25){
//To hot, let's pump continuosly
if($pump!='On')sw('pump','On');
}elseif($temp>0){
//Normal temp
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}else{
//It's freezing cold, don't pump at all
if($pump!='Off')sw('pump','Off');
}
Re: Fish pond pump script
Posted: Monday 25 September 2017 11:25
by D3LTA
Egregius wrote: ↑Monday 25 September 2017 6:13
With pass2php times are quite easy:
Code: Select all
<?php
$temp=status('temperature');
$pump=status('pump');
if($temp>25){
//To hot, let's pump continuosly
if($pump!='On')sw('pump','On');
}elseif($temp>0){
//Normal temp
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}else{
//It's freezing cold, don't pump at all
if($pump!='Off')sw('pump','Off');
}
that looks very good indeed, but how does it get the var temp and pump? are those the names in domoticz ?
i can read the script and understand it.. but can you explain the "timestamp".. is that a persistant value? or does it read the time variables from domoticz? ("last seen")
How do i implement it?
Re: Fish pond pump script
Posted: Monday 25 September 2017 12:47
by Egregius
Yes, the names of Domoticz.
You'll need to get pass2php running. All the magic happens there.
Re: Fish pond pump script
Posted: Monday 25 September 2017 13:27
by D3LTA
thats no problem, please help me understand the script (timestamps) as i have no php knowledge.
is it also possible to store values? because for example if it freezes for 2 days, and temp gets above 0 again.. it takes for example 5 days before the pump can start again because the ice needs to melddown.
Re: Fish pond pump script
Posted: Monday 25 September 2017 17:26
by D3LTA
realy hope you or someone willing to make this a working script... i just don't have the knowledge..yet..

Re: Fish pond pump script
Posted: Monday 25 September 2017 17:37
by Egregius
you can store custom variables with the setstatus() function and read them with the status() function of pass2php.
You could (for example) set a variable 'hasfrozen' to the lowest frost temperature. pass2php automatically remembers the last set time of a var.
Didn't test this, but something like this could be a good direction:
Code: Select all
<?php
$temp=status('temperature');
$pump=status('pump');
if($temp>25){
//To hot, let's pump continuosly
if($pump!='On')sw('pump','On');
}elseif($temp>8){
//Normal temp, let's cycle 2 hours on, 1 hour off
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}elseif($temp>0){
//It's cold, did it freeze lately?
$hasfrozen=status('hasfrozen');
$hasfrozentime=timestamp('hasfrozen');
if($hasfrozen<-20){
//damned that was cold, lets wait 10 days
if($hasfrozentime<time-(86400*10)){
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}
}elseif($hasfrozen<-10){
//damned that was cold, lets wait 5 days
if($hasfrozentime<time-(86400*5)){
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}
}elseif($hasfrozen<-5){
//damned that was cold, lets wait 2 days
if($hasfrozentime<time-(86400*2)){
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}
}elseif($hasfrozen<0){
//Just a litle frost, one day will do
if($hasfrozentime<time-86400){
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}
}else{
//It didn't freeze, lets cycle
if($pump=='On'&×tamp('pump')<time-7200)sw('pump','Off');
elseif($pump=='Off'&×tamp('pump')<time-3600)sw('pump','On');
}
}else{
//It's freezing cold, don't pump at all
if($pump!='Off')sw('pump','Off');
$hasfrozen=status('hasfrozen');
if($temp<$hasfrozen)setstatus('hasfrozen',$temp);
}
A lot of information of pass2php can be found at
http://www.domoticz.com/forum/viewtopic ... 64&t=12343
Re: Fish pond pump script
Posted: Tuesday 26 September 2017 21:41
by D3LTA
Thank you very much Egregius.. will give it a try
what will happen if it's -11 2 days in a row? it will just stay 5 days with every extra day its still freezing -11 ?
Re: Fish pond pump script
Posted: Sunday 01 October 2017 17:52
by D3LTA
Anyone willing to help debug and improve this script?
thanks in advance
Code: Select all
-- start lua commandarray = schakel tabel waarin we opdrachten gaan geven
commandArray = {}
------------------------------------------------------------
-- functie timedifference = functie di we verderop aanroepen om te zien hoe lang pomp aan is of uit is.
------------------------------------------------------------
function timedifference (s) --- tijdverschil bepalen sinds laatste schakeling in sec
yearx=string.sub(s, 1, 4) monthx=string.sub(s, 6, 7) dayx=string.sub(s, 9, 10)
hourx=string.sub(s, 12, 13) minutesx=string.sub(s, 15, 16) secondsx=string.sub(s, 18, 19)
t1=os.time()
t2=os.time{year=yearx, month=monthx, day=dayx, hour=hourx, min=minutesx, sec=secondsx}
difference=os.difftime (t1, t2)
--print(s.." "..tostring(t).." "..tostring(difference))
return difference
end
------------------------------------------------------------
-- zet de temperatuur in variable zodat we deze later als vooraarde kunnen laten dienen-- bepaal wat er moet gebeuren
------------------------------------------------------------
local temp = otherdevices_temperature['Temp Ground / Humidity (Twente)'] -- zet temp in waarde, en maak er n getal van ipv string
local laag= 0 -- min temp
local hoog= 25 -- max temp
local timediff=timedifference(otherdevices_lastupdate['vijver-pomp'])
local pompstatus=otherdevices['vijver-pomp']
local pompbeveiliging=false
------------------------------------------------------------
-- bepaal wat er moet gebeuren
------------------------------------------------------------
-- normaal
if temp>laag and temp<hoog then
max_uit = 3600 -- 3600 sec (1 uur)
max_aan = 7200 -- 7200 sec (2uur)
end
-- warm
if temp>laag and temp>hoog then
max_uit = 1800 -- 1800 sec (30 min)
max_aan = 10800 -- 10800 sec (3uur)
end
-- koud
if temp<laag and temp<hoog then
pompbeveiliging=true
else
pompbeveiliging=false
end
------------------------------------------------------------
-- Doe wat er moet gebeuren normaal en warm
------------------------------------------------------------
if pompbeveiliging==false then -- alleen schakelen als de pompbeveiliging niet actief is
if otherdevices['pompstatus'] == 'Off' and timediff>max_uit then -- aanzetten als uit en te lang uit
commandarray['pompstatus']='On'
end
if otherdevices['pompstatus']== 'On' and timediff>max_aan then -- uitzetten als aan en te lang aan.
commandarray['pompstatus']='Off'
end
end
------------------------------------------------------------
-- Doe wat er moet gebeuren bij vorst
------------------------------------------------------------
if pompbeveiliging==true and otherdevices['pompstatus']=='On' then -- als pompbeveiliging actief is en pomp aan dan pomp uitzetten
commandarray['pompstatus']='Off'
end
return commandArray -- nu gaat domoticz wat we in commandarray hebben geplaatst ook werkelijk uitvoeren