Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by remb0 »

I'm busy with a cost saving script but I got:
2016-05-23 21:35:00.368 Error: EventSystem: in script_time_Besparing: [string "function timedifference(s) ..."]:9: field 'day' missing in date table

I think it is not in my script because I changed the code a lot (now it's back to the basis and doesn't make sense, but still got the error.
Is it a domoticz bug in the event system?

my device is working well:

11 RFX 0A2FEA6 12 Slaapkamer Lighting 2 AC Off 6

the script.

Code: Select all

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 = {}

--		package.path 	= package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
--		My 				= require('MyFunc')
	-- Variable
		Script		  	= 'Besparing'						--
		Version       	= 1							--
		Notifications 	= uservariables["Notifications"] -- On/Off
		minuten_toegestaan	=	15 -- aantal minuten 180 = 3 uur
		StateDevice 	= 'Iemand_thuis'
		TH_Hour1        = 8		-- Treshold hour
		TH_Hour2        = 10		-- Treshold hour
		Nu_Hour			=tonumber(os.date('%H',time))
		Debug = 'Y'
		
		if ((Nu_Hour >= TH_Hour1) or (Nu_Hour <= TH_Hour2)) then Res_Hour=1   	else Res_Hour=0  end
	--	if (otherdevices['Slaapkamer'])  == 'On'   	        then Slaapkamer=1  	else Slaapkamer=0 end       -- omgedraait omdat het ook DO set dimmer level to 80% kan hebben ipv on.
	--	if (otherdevices['Gang']) 		 == 'On'	        then Gang=1   	    else Gang=0 end
		if (otherdevices['Iemand_thuis']) 		 == 'On'	    then Aanwezig=1   	else Aanwezig=0 end
--		TDiffGang		= My.Round(My.TimeDiff(os.time(),LastChange_Gang)/60,0)
--		TDiffSlaapkamer = My.Round(My.TimeDiff(os.time(),LastChange_Slaapkamer)/60,0)
	--logging
			print ('______________________________________________________________________')
			print('<b style="color:Blue"> '.. Script .. ".......v" .. Version .. "..Debugging=  " .. Debug .. '</b>')
			if (otherdevices['Bespaar_modus']) == 'Off' then 	print (".  Besparing wordt niet toegepast. ") 	goto done end
		if Debug == 'Y' then
		    --print ( ".  " .. Aanwezig .. " - Iemand thuis? " )
			-- print ( ".   Slaapkamer :    " .. TDiffSlaapkamer .. " minuten geleden naar: "  .. (otherdevices['Slaapkamer']) )
		else
		end
		
	-- Binnen gestelde tijd

--	commandArray['SendNotification']='Bespaaralert!#Gang staat al ' .. minuten_toegestaan .. ' minuten aan!#0#pushover'
		
--		if ((Aanwezig == 0) and (IetsAan >= 1))  then
--		    print(".  Niemand thuis terwijl" .. TDiffSlaapkamer .. " aan stond.")
--		    commandArray['SendNotification']='Bespaaralert!#Niemand aanwezig en devices aan!#1#pushover'
--		    commandArray['Alles']='On'
--        end
        
        
        --get status of all sensors
--if the sensor is dead for more than 1 day output the name of that sensors

for i, v in pairs(otherdevices) do
  timeon = 86400  -- 1 dag in seconden
  tc = tostring(i)

print("Alive: " .. tc .. " ");

     difference = timedifference(otherdevices_lastupdate[tc])
     if (difference > timeon) then
        tempdiff = tostring(difference)
        
        --remove garbage from the output, only report nodes that has not update for more than 1 day.
        v = i:sub(1,2)
        v2 = i:sub(1,4)
        v3 = i:sub(1,6)
        v4 = i:sub(1,17)
        if ( (v ~= 'IP') and (v2 ~= 'Talk') and (v3 ~= 'Tunein') and (v4 ~= 'Living Room - Hub') ) then
        print("Dead: " .. tc .. " : " .. difference);
        end
        
     end

end 




::done::

return commandArray


2016-05-23 21:35:00.368 Error: EventSystem: in script_time_Besparing: [string "function timedifference(s) ..."]:9: field 'day' missing in date table
FritzzJan
Posts: 4
Joined: Sunday 20 December 2015 11:07
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands, Hoorn
Contact:

Re: Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by FritzzJan »

Hello remb0,
I did some testing, and find out that the loop "for i, v in pairs(otherdevices) do" sometimes gives you an emty record.
If you pass an emty string to the timedifference function you get the "field day missing" error.
So your program is ok and you can go on testing if you check on an emty string.
It looks like a Domoticz error in the otherdevices function.

Good luck with the testing of your program!
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by remb0 »

Thanks!
I have more then 1 devices that gives a nill. only I don't know how to filter them out properly..
do you have a hint?
FritzzJan
Posts: 4
Joined: Sunday 20 December 2015 11:07
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands, Hoorn
Contact:

Re: Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by FritzzJan »

This is a quick and dirty solution:

Code: Select all

for i, v in pairs(otherdevices) do
    tc = tostring(i)
    if (tc == "") then
        print ("nil value")
    else
        timeon = 86400                                                  -- 1 dag in seconden
        difference = timedifference(otherdevices_lastupdate[tc])
        if (difference > timeon) then
            tempdiff = tostring(difference)
            --remove garbage from the output, only report nodes that has not update for more than 1 day.
            v1 = i:sub(1,2)
            v2 = i:sub(1,4)
                v3 = i:sub(1,6)
            v4 = i:sub(1,17)
            if ( (v1 ~= 'IP') and (v2 ~= 'Talk') and (v3 ~= 'Tunein') and (v4 ~= 'Living Room - Hub') ) then
                print("Dead: " .. tc .. " : " .. difference);
            end
        else
            print("Alive: " .. tc .. " ");
        end
    end
end 
User avatar
remb0
Posts: 499
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by remb0 »

Thanks I have a virtual text sensor that had no update or value yet.
solved.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by emme »

Hi...
I got a similar issue....
the problem is a fake device... and cannot understans what are these :(
they are not available in the device tab, not in the used ones...
do I have to remove them straight from the db?!
Attachments
Cattura-1.png
Cattura-1.png (10.6 KiB) Viewed 1590 times
The most dangerous phrase in any language is:
"We always done this way"
mjdb
Posts: 71
Joined: Thursday 12 January 2017 13:38
Target OS: Raspberry Pi / ODroid
Domoticz version: all beta
Location: NL - Pijnacker
Contact:

Re: Error: EventSystem: in script_time_Besparing: [string "-- Slaapkamer ..."]:49: field 'day' missing in date table

Post by mjdb »

There can be several causes that the input for this function is invalid. The error-message "day is missing" is not helpful.

I modified the function with some data-checking. An error shows also what is wrong.

Besides that I renamed the function to "SecondsSince", but that is a personal preference.

Code: Select all

  function SecondsSince(s)
    if (s == nil) then
      print('ERROR: Function SecondsSince got nil for Time')
      return 0
    else
      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)
      if  (year > '2000') and (year < '2050')
      and (month >= '01') and (month <= '12')
      and (day >= '01') and (day <= '31')
      and (hour >= '00') and (hour <= '23')
      and (minutes >= '00') and (minutes <= '59')
      and (seconds >= '00') and (seconds <= '59') then
        t1 = os.time()
        t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
        difference = os.difftime (t1, t2)
        return tonumber(difference)
      else
        print('ERROR: Function SecondsSince got invalid input: ' .. s)
        return 0
      end
    end
  end -- SecondsSince
- - - - - - - - - - -
2 x Domoticz on Raspberry Pi; 2 x RFXtrx433; Aeotec Z-Stick
KlikAanKlikUit ICS-2000 as Relay
Aeotec MultiSensors 6; Danfoss Z Thermostats 014G0013; Kaku Switches, Z-wave Switches
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest