Page 1 of 1

[Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 12:43
by deennoo
Hi there,

Got an error on my script and don't know how to solve, maybe someone can help me

1 - Situation :
Running Domoticz (Version: 3.5228) on a Syno + RFLink + RFXTRXE

2 - Goal :
Manage Milight Bulb or wall socket true wall switch with chacon module inside, i want to be able to turn on/off the device or group depending of his previous state who can be drive by a scene or a remote

I Don't care about ON or Off wall switch status, just want : when his status change, script check "esclave device" status and toggle it from On to OFF or OFF to ON

3 - Script :

This one have to drive a wall plug From IDK with a Chacon wall switch

Inter lum Salon : the wall switch
Lumiere Salon = the wall plug

Code: Select all

commandArray = {}
 if (devicechanged['Inter lum salon'])  then
     commandArray['Lumiere Salon']='Toggle'
 end
 return commandArray
 

4 - Current status :

For the Wall switch

Code: Select all

1297	Inter lum salon	On	2016-06-09 09:46:59	15

{
   "ActTime" : 1465469517,
   "ServerTime" : "2016-06-09 12:51:57",
   "Sunrise" : "06:17",
   "Sunset" : "21:45",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "On",
         "Description" : "",
         "Favorite" : 0,
         "HardwareID" : 11,
         "HardwareName" : "RFXTRXE",
         "HardwareType" : "RFXCOM - RFXtrx433 USB 433.92MHz Transceiver",
         "HardwareTypeVal" : 1,
         "HaveDimmer" : true,
         "HaveGroupCmd" : true,
         "HaveTimeout" : false,
         "ID" : "1145DC6",
         "Image" : "Light",
         "IsSubDevice" : false,
         "LastUpdate" : "2016-06-09 09:46:59",
         "Level" : 100,
         "LevelInt" : 15,
         "MaxDimLevel" : 15,
         "Name" : "Inter lum salon",
         "Notifications" : "false",
         "PlanID" : "1",
         "PlanIDs" : [ 1 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : 7,
         "Status" : "On",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "AC",
         "SwitchType" : "On/Off",
         "SwitchTypeVal" : 0,
         "Timers" : "false",
         "Type" : "Lighting 2",
         "TypeImg" : "lightbulb",
         "Unit" : 1,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "1297"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}

For the wall Plug

Code: Select all

105	Lumiere Salon	Off	2016-06-09 09:47:03	0

{
   "ActTime" : 1465469552,
   "ServerTime" : "2016-06-09 12:52:32",
   "Sunrise" : "06:17",
   "Sunset" : "21:45",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 110,
         "Data" : "Off",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 25,
         "HardwareName" : "RFLink Ser2net",
         "HardwareType" : "RFLink Gateway with LAN interface",
         "HardwareTypeVal" : 62,
         "HaveDimmer" : true,
         "HaveGroupCmd" : true,
         "HaveTimeout" : false,
         "ID" : "00000060",
         "Image" : "Lampadaire",
         "IsSubDevice" : false,
         "LastUpdate" : "2016-06-09 09:47:03",
         "Level" : 0,
         "LevelInt" : 0,
         "MaxDimLevel" : 100,
         "Name" : "Lumiere Salon",
         "Notifications" : "false",
         "PlanID" : "2",
         "PlanIDs" : [ 2, 11 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "Off",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "ELRO AB400",
         "SwitchType" : "On/Off",
         "SwitchTypeVal" : 0,
         "Timers" : "true",
         "Type" : "Light/Switch",
         "TypeImg" : "lightbulb",
         "Unit" : 4,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "105"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}
5 - Error :

Code: Select all

2016-06-09 12:40:00.959 Error: EventSystem: in Lum salon: [string "commandArray = {} ..."]:2: attempt to index global 'devicechanged' (a nil value)

Your Help will be very appriciated to solve this.

Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 13:33
by Raducanu
I'm also new to LUA, but if i understand https://www.domoticz.com/wiki/Events correctly, you have to specify what changed...

Code: Select all

commandArray = {}
 if (devicechanged['Inter lum salon'] == 'On')  then
     commandArray['Lumiere Salon']='Toggle'
 end
 return commandArray


Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 13:58
by Westcott
Is it a 'time' script rather than a 'device' script?

Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 14:45
by deennoo
@Westcott t
That a device script i'm looking for a device status change (Chacon wall switch)

Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 14:54
by deennoo
@Raducanu

even if i try this :

Code: Select all

commandArray = {}
 if (devicechanged['Inter loisir'] == 'On')  then
     commandArray['Plafonnier Loisir']='Toggle'
 end
  if (devicechanged['Inter loisir'] == 'Off')  then
     commandArray['Plafonnier Loisir']='Toggle'
 end
 return commandArray
Log give this :

Code: Select all

2016-06-09 14:53:00.288 Error: EventSystem: in Lum Loisir: [string "commandArray = {} ..."]:2: attempt to index global 'devicechanged' (a nil value)
Both script works very well and as i'm leasy guy i will use the first, but i don't like thos red line on my log

Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 17:03
by jvdz
When you use the internal script editor make sure you do not have "All" but "Device" selected underneath LUA.

Jos

Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 09 June 2016 20:40
by deennoo
jvdz wrote:When you use the internal script editor make sure you do not have "All" but "Device" selected underneath LUA.

Jos
that it !!!
thank you very much !

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Tuesday 13 December 2016 23:34
by sangve
Oh, that's just lovely!
Thank you for helping me with the exact same thing! <3

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Wednesday 05 April 2017 13:16
by mbeefcake
Helped me too :) Thanks!

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 20 April 2017 15:17
by freijn
Helped me , many thanks !

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Sunday 06 August 2017 13:31
by Stefan
helped me too :D bedankt

Re: LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Monday 13 November 2017 18:06
by rammstan
jvdz wrote: Thursday 09 June 2016 17:03 When you use the internal script editor make sure you do not have "All" but "Device" selected underneath LUA.

Jos

That's it. thanks

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Sunday 28 January 2018 16:12
by digdilem
Another one this helped!

Really non-intuitive behaviour and not a very helpful error message, so glad for this help.

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Tuesday 17 April 2018 14:37
by Medzu
Thnx! :D

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Thursday 25 April 2019 15:51
by u01026366
solved also for me

thanks !!!

Re: [Solve] LUA : attempt to index global 'devicechanged' (a nil value)

Posted: Saturday 06 June 2020 21:54
by imautohuttraeger
Helped me, too. Thx!