I have a timer script to turn on some lights when I need to leave early for work.
Yesterday the script ran without any issue but this morning I got errors.
I just tested again and got these error:
2020-11-04 21:30:00.206 Error: Error opening url: http://127.0.0.1:8080/json.htm?type=com ... %3A29%3A00
2020-11-04 21:30:00.284 Error: dzVents: Error: (3.0.16) HTTP/1.1 response: 401 ==>> Unauthorized
2020-11-04 21:30:00.300 Error: dzVents: Error: (3.0.16) An error occurred when calling event handler Wekker
2020-11-04 21:30:00.300 Error: dzVents: Error: (3.0.16) ...pi/domoticz/scripts/dzVents/generated_scripts/Wekker.lua:42: attempt to call a nil value (field 'aftermin')
The script is below.
Does anyone have a clue what I'm doing wrong?
Code: Select all
-- Alarm clock [ dzVents >= 2.4 ]
scriptVar = '20191030 Alarmclock'
return
{ active = true,
on =
{
timer = { 'every minute' }, -- hourly run once to pick up target time
httpResponses = { scriptVar }, -- Trigger the handle Json part
},
-- logging = { level = domoticz.LOG_DEBUG },
execute = function(dz, item)
local alarmTime = dz.devices('Wekker').levelName
if alarmTime ~= 'Off' then
local minutesIn24Hours = 24 * 60
local now = dz.time -- Get current time into time object
local Time = require('Time')
local targetTime = Time(dz.time.rawDate .. ' ' .. alarmTime .. ':00') -- Create target time object
local function triggerAlarm(delay)
local message = 'alarmclock ringing now. Was set on '.. dz.time.rawDate .. ', at ' .. dz.time.rawTime
local url = dz.settings['Domoticz url'] .. "/json.htm?type=command¶m=addlogmessage&message=" .. dz.utils.urlEncode(message)
dz.openURL({ url = url, callback = scriptVar }).afterMin(math.floor(delay))
end
if not(item.isHTTPResponse) then
dz.log('Alarm time is set at : ' .. alarmTime)
local deltaMinutes = math.floor(now.compare(targetTime).minutes)
if now.compare(targetTime).compare < 1 then -- targetTime is in future
deltaMinutes = minutesIn24Hours - deltaMinutes
end
dz.log('Alarmactions will be triggered in ' .. deltaMinutes .. ' minutes' ,dz.LOG_DEBUG)
triggerAlarm(deltaMinutes)
else
-- do wakeup actions.. here
dz.log('wake up actions here....' ,dz.LOG_DEBUG)
dz.devices('Schuurverlichting 1').switchOn().aftermin(10)
dz.devices('Schuurverlichting 1').switchOff().afterMin(25)
dz.devices('Buitenlamp').switchOn().aftermin(10)
dz.devices('Buitenlamp').switchOff().afterMin(30)
dz.notify('Wekker','Over 10 minuten moet je weg!', dz.PRIORITY_LOW, dz.SOUND_DEFAULT,nil, dz.NSS_TELEGRAM)
end
end
end
}