another event script for irrigation
Posted: Wednesday 20 January 2021 10:40
Hi,
Last week a created (with a bit of help) a master event/timer script for alle my light switches. It works GREAT!
I like to use the same setup for my irrigation events.
I have 5 irrigation zones with different settings.
For example:
Tuinirrigatie_border_links_timer is a selector switch for zone 1 irrigation with a timer/event as content
There a 4 more zones with 4 selector switches with timer/events
Script
1. I want to read the content of the 5 timerevent devices (see array dashboardTimersdevices) and filling an array (dashboardTimers) with the timers
2. Add manual off events to this array(dashboardTimers) with the content of array (dashboardTimersadd)
3. Let the on statement use the filled array(dashboardTimers) to execute the events
4. print the content of the dashboardTimers so i can check if it works
I think i am almost there but still an error
2021-01-20 10:38:02.066 Error: dzVents: Error: (3.1.1) ...scripts/dzVents/generated_scripts/test_irrigatieklok.lua:24: attempt to call a nil value (field 'devices')
2
Last week a created (with a bit of help) a master event/timer script for alle my light switches. It works GREAT!
I like to use the same setup for my irrigation events.
I have 5 irrigation zones with different settings.
For example:
Tuinirrigatie_border_links_timer is a selector switch for zone 1 irrigation with a timer/event as content
There a 4 more zones with 4 selector switches with timer/events
Script
1. I want to read the content of the 5 timerevent devices (see array dashboardTimersdevices) and filling an array (dashboardTimers) with the timers
2. Add manual off events to this array(dashboardTimers) with the content of array (dashboardTimersadd)
3. Let the on statement use the filled array(dashboardTimers) to execute the events
4. print the content of the dashboardTimers so i can check if it works
I think i am almost there but still an error
2021-01-20 10:38:02.066 Error: dzVents: Error: (3.1.1) ...scripts/dzVents/generated_scripts/test_irrigatieklok.lua:24: attempt to call a nil value (field 'devices')
2
Code: Select all
--------------------------------------------------------------------------------------------------------------------------------------------------
local dashboardTimersdevices =
{
{ 'timer_on1','Tuinirrigatie_border_links_timer',true},
{ 'timer_on2','Tuinirrigatie_border_rechts_timer',true},
{ 'timer_on3','Tuinirrigatie_gazon_timer',true},
{ 'timer_on4','Tuinirrigatie_planten_timer',true},
{ 'timer_on5','Tuinirrigatie_voortuin_rechts_timer',true},
}
local dashboardTimersadd =
{
{ 'Allways','every minute',true}, -- nodig om te testen, kan bij werking uit
{ 'timer_off','every day 90 minutes after sunset',true}, -- deze moet alle timers bij elkaar geteld + pauzes later zijn dan de start van de timer
}
--------------------------------------------------------------------------------------------------------------------------------------------------
local function get_dashboard_timers(dz,item,info,dashboardTimersdevices,dashboardTimersadd)
local dashboardTimers = {}
for _, record in ipairs(dashboardTimersdevices) do
table.insert(dashboardTimers, dz.devices(record[2]).state) -- timerwaarden ophalen van de 5 timersdevices
end
for _, record in ipairs(dashboardTimersadd) do
table.insert(dashboardTimers, record[2]) -- timers toevoegen om alles voor de zekerheid te stoppen
end
return dashboardTimers
end
return
{
on ={
timer = get_dashboard_timers(domoticz,item,info,dashboardTimersdevices,dashboardTimersadd),
},
execute = function(dz,item,info)
_G.logLevel = dz.helpers.get_logtype(dz) -- dz.log('debug test',dz.LOG_DEBUG) this will only make it to the log when LOG_DEBUG is set AND dz.log('blabla',dz.LOG_FORCE) -- this will allways make it tp the log
_G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem
local messageTable = {} -- log alles, 0 = niets, 1 dom, 2 global, 3 alles... evt per regel ook in te regelen
-- HIER START DE EXECUTIE
-- hier komt een reeds werkend irrigatiescript
dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' Timers: ' .. dashboardTimers,10) -- inhoud van de timers laten zien
dz.helpers.globalMessage2(dz,item,info,messageTable,'chg') -- dump
end
}