Script Error Topic is solved

Moderator: leecollings

Post Reply
frizby66
Posts: 33
Joined: Friday 13 November 2015 17:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Script Error

Post by frizby66 »

Getting a storage error in Lua script for PIR control of lighting.
Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_PIRs.lua: /home/pi/domoticz/scripts/lua/script_time_PIRs.lua:35: attempt to perform arithmetic on a nil value
Below is the script it is referring to, with line 35 being "timeon = (tonumber(onmode) * 60) - 1" :-

Code: Select all

-- ~/domoticz/scripts/lua/script_time_pirs.lua
-- Each of the motion sensors in Domoticz follow this name convention:
-- PIRxrzSwitchName or PIRxgzGroupName
-- x speicifies when the PIR controls - a=all day, n=nighttime, d=daytime,
--   1=custom timer 1 set to 22:00 to 07:30
-- y specifies what the PIR is controlling -
--   r = room (single Domoticz) switch and g = group
-- z specifies how long the ligth will stay on for in minutes, so z = 5 turns
--   the switch or the group on for 5 minutes
-- N.B. be careful as currently there is little error checking so wrongly
--      named PIRs in Domoticz may cause an error
-- N.B. one wrongly named PIR may stop the script, check log for any issues

function timedifference(s)
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
end

commandArray = {}

for i, v in pairs(otherdevices) do
   tc = tostring(i)
   v = i:sub(1,3)
   if (v == 'PIR') then
      onmode = i:sub(6,6)
      if onmode ~= "u" then
         timeon = (tonumber(onmode) * 60) - 1
--         print(tostring(60 * tonumber(onmode) ^ 2) - 1)
         difference = timedifference(otherdevices_lastupdate[tc])
--         print(i..difference)
         if (difference > timeon and difference < (timeon + 60)) then
            tempdiff = tostring(difference)
            c = i:sub(7)
            if i:sub(5,5) == "g" then
               c="Group:"..c
            end 
            tempmessage = c.." Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
            print(tempmessage)
            commandArray[c] = 'Off'
         end
      end
   end
end

return commandArray
PIR is called "PIRng2KCab" and Group is called "KCab"
Any idea why I am getting the error?
--------------------
Raspberry Pi2, RTX433e USB, Philips Hue, Nest, LightwaveRF.
frizby66
Posts: 33
Joined: Friday 13 November 2015 17:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script Error

Post by frizby66 »

Solved..my bad...had two other PIR's which had no time values set on them, so hence the reason for the nil value error!!
--------------------
Raspberry Pi2, RTX433e USB, Philips Hue, Nest, LightwaveRF.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script Error

Post by waaren »

frizby66 wrote: Monday 02 September 2019 23:45

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_PIRs.lua: /home/pi/domoticz/scripts/lua/script_time_PIRs.lua:35: attempt to perform arithmetic on a nil value
PIR is called "PIRng2KCab" and Group is called "KCab"
Any idea why I am getting the error?
[EDIT] You solved it already :)
To see what happens during execution of this script add

Code: Select all

print("deviceName: " .. tostring(i) .. " ==>> onmode: " .. tostring(onmode) )
Between line 34 and 35
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest