Page 1 of 1

help with script correction

Posted: Tuesday 02 April 2024 19:04
by ssk17051980
I need a script to turn on a solenoid valve to water some decorative plants, for 1 hour, 2 times/week, from April 1st to November 1st. I keep trying with AI but without success. can someone help me ?

Code: Select all

return {
    on = {
        timer = {
            'at 10:00 on Mon,Thu in April-September'
        }
    },
    execute = function(domoticz, device)
        -- Verificați dacă este între 1 aprilie și 20 septembrie
        local currentDate = domoticz.time
        if (currentDate.month == 4 and currentDate.day < 1) or
           (currentDate.month == 9 and currentDate.day > 20) or
           (currentDate.month < 4 or currentDate.month > 9) then
            return
        end

        -- Verificați dacă este luni sau joi
        if currentDate.dayOfWeek == domoticz.Sunday or currentDate.dayOfWeek == domoticz.Wednesday then
            -- Verificați dacă este ora 10:00 dimineața
            if currentDate.hour == 10 and currentDate.min == 0 then
                -- Porniți dispozitivul cu ID-ul 47
                domoticz.devices[47].switchOn()

                -- Oprește dispozitivul după 1 oră (3600 secunde)
                domoticz.devices[47].switchOff().afterSec(3600)
            end
        end
    end
}

Re: help with script correction

Posted: Tuesday 02 April 2024 19:14
by Kedi
Change this

Code: Select all

        timer = {
            'at 10:00 on Mon,Thu in April-September'
        }
in

Code: Select all

        timer = {
            'at 10:00 on mon,thu'
        }

Re: help with script correction

Posted: Tuesday 02 April 2024 19:27
by jvdz
ssk17051980 wrote: Tuesday 02 April 2024 19:04 I keep trying with AI but without success. can someone help me ?
I am sure the documentation is way more useful than trusting AI! :)
This is untested, but I assume it should be as simple as something like this:

Code: Select all

return {
    on = {
        timer = {
            'at 10:00 on Mon,Thu on 3/1-10/31'
        }
    },
    execute = function(domoticz, device)
        -- Start the device with ID 47 for 3600 seconds
        domoticz.devices[47].switchOn().forSec(3600)
    end
}

Re: help with script correction

Posted: Tuesday 02 April 2024 19:55
by Kedi
Should that not be?

Code: Select all

'at 10:00 on Mon,Thu on 1/3-31/10'

Re: help with script correction

Posted: Tuesday 02 April 2024 20:05
by ssk17051980
i gone try all the variant from here .

thx

Re: help with script correction

Posted: Tuesday 02 April 2024 21:53
by HvdW
From the wiki:

Code: Select all

  'every 10 minutes between 20 minutes before sunset and 30 minutes after sunrise on mon,fri,tue on 20/5-18/8'
Don't know if Mon or mon makes a difference.

Re: help with script correction

Posted: Thursday 04 April 2024 19:42
by ssk17051980
in this form is not working
something to change ?

Code: Select all

return {
    on = {
        timer = {
            'at 10:00 on Wed,Thu on 1/3-31/10'
        }
    },
    execute = function(domoticz, device)
        -- Porniți dispozitivul cu ID-ul 47 pentru 3600 de secunde (o oră)
        domoticz.devices[47].switchOn().forSec(3600)
    end
}

Re: help with script correction

Posted: Thursday 04 April 2024 19:56
by waltervl
It should work, perhaps add a log statement to be sure.
Also make sure you have some time left (min 2 minutes) to have Domoticz setup the triggers. So save the script latest at 9:58 to have th trigger action on 10:00.

See also wiki https://www.domoticz.com/wiki/DzVents:_ ... gger_rules

Re: help with script correction

Posted: Saturday 06 April 2024 21:23
by ssk17051980
I also modified the date format as follows: 'at 10:00 on Mon,Thu on 1/3-31/10' but without success :(

Re: help with script correction

Posted: Saturday 06 April 2024 21:58
by jvdz
What exactly isn't working, as I've just tested with a similar dzvent script, and it triggers fine and shows the Test2 in the domoticz log?

Code: Select all

return {
    on = {
        timer = {
            'at 21:58 on Sat,Thu on 1/4-31/10'
        } 
    },
    execute = function(domoticz, device)
        -- Start the device with ID 47 for 3600 seconds
        print("test 2")
    end
}

Re: help with script correction

Posted: Tuesday 09 April 2024 10:05
by ssk17051980
Out of ideea.

I have no idea :(
I simply want to be able to turn on a switch twice a week between April 1st and October 1st.
only the starting part interests me, the time does not matter, etc

Re: help with script correction

Posted: Tuesday 09 April 2024 10:15
by Kedi
Change the script from @jvdz in

Code: Select all

return {
    on = {
        timer = {
            'every minute on Tue,Sat,Thu on 1/4-31/10'
        } 
    },
    execute = function(domoticz, device)
        -- Start the device with ID 47 for 3600 seconds
        print("test 2")
    end
}
Every minute now the text "test 2' should be printed in the log.
Is that working? If not are other scripts working?

Re: help with script correction

Posted: Tuesday 09 April 2024 10:22
by jvdz
ssk17051980 wrote: Tuesday 09 April 2024 10:05 Out of ideea.

I have no idea :(
I simply want to be able to turn on a switch twice a week between April 1st and October 1st.
only the starting part interests me, the time does not matter, etc
You still are not explaining "What" is not working ! Just telling us that it isn't working doesn't tell us much! ;)
Help us to help you. The simple example I gave should show a message in the domoticz log when the condition is met. Did you try that and what was the result!

Re: help with script correction

Posted: Sunday 14 April 2024 11:30
by ssk17051980
the swith that i want to control is not starting in the program. from april to november, 2 day/wek.
i try a lot of version whit chat gpt whit no luck.
this is the last try whit dzvents from chat gpt.


return {
on = {
timer = { 'daily' }
},
execute = function(dz)
local currentDate = os.date('*t')
local switchIdxToControl = 305

-- Verificăm dacă suntem în aprilie - octombrie și este una din zilele de miercuri sau vineri
if (currentDate.month >= 4 and currentDate.month <= 10) and (currentDate.wday == 3 or currentDate.wday == 5) then
dz.devices(switchIdxToControl).switchOn() -- Pornim switch-ul cu idx-ul 305
else
dz.devices(switchIdxToControl).switchOff() -- Oprim switch-ul cu idx-ul 305
end
end
}


important it's to start in that interval. the stop part it's easy whit blockly.

Re: help with script correction

Posted: Sunday 14 April 2024 18:48
by Kedi
Did you test this script? And what is the result? https://www.domoticz.com/forum/viewtopi ... 96#p315996
Do other scripts work?

Re: help with script correction

Posted: Monday 15 April 2024 9:02
by ssk17051980
yes, it's working that part whit : test 2 script
the device whit idx 47 is not starting, only the text : test 2 it's apear in the log.




2024-04-15 10:00:00.210 Status: dzVents: test 2
2024-04-15 10:01:00.236 Status: dzVents: test 2

Re: help with script correction

Posted: Monday 15 April 2024 9:49
by ssk17051980
return {
on = {
timer = {
'every minute on Mon,Sat,Thu on 1/4-31/10'
}
},
execute = function(domoticz, device)
-- Start the device with ID 47 for 3600 seconds
domoticz.devices(47).switchOn().forSec(3600)
print("Device with idx 47 started for 3600 seconds")
end
}
this it's working!!


thx for the HELP !!!

Re: help with script correction

Posted: Monday 15 April 2024 14:52
by Kedi
I think you should change the timer part, because now the device is switched on for 1 hour every minut.

Re: help with script correction

Posted: Monday 15 April 2024 20:43
by ssk17051980
Kedi wrote: Monday 15 April 2024 14:52 I think you should change the timer part, because now the device is switched on for 1 hour every minut.
yes, you right =))
i see that after i start to test.
i did not find a solution until now.
AI is not so smart on dzvents =))). we are at the same level .