help with script correction

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

help with script correction

Post 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
}
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: help with script correction

Post 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'
        }
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help with script correction

Post 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
}
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: help with script correction

Post by Kedi »

Should that not be?

Code: Select all

'at 10:00 on Mon,Thu on 1/3-31/10'
Logic will get you from A to B. Imagination will take you everywhere.
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post by ssk17051980 »

i gone try all the variant from here .

thx
HvdW
Posts: 504
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: help with script correction

Post 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.
Bugs bug me.
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post 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
}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: help with script correction

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post by ssk17051980 »

I also modified the date format as follows: 'at 10:00 on Mon,Thu on 1/3-31/10' but without success :(
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help with script correction

Post 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
}
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post 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
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: help with script correction

Post 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?
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help with script correction

Post 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!
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post 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.
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: help with script correction

Post by Kedi »

Did you test this script? And what is the result? https://www.domoticz.com/forum/viewtopi ... 96#p315996
Do other scripts work?
Logic will get you from A to B. Imagination will take you everywhere.
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post 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
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post 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 !!!
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: help with script correction

Post by Kedi »

I think you should change the timer part, because now the device is switched on for 1 hour every minut.
Logic will get you from A to B. Imagination will take you everywhere.
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: help with script correction

Post 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 .
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests