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

Moderator: leecollings

Post Reply
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post 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.
Last edited by deennoo on Thursday 09 June 2016 20:41, edited 2 times in total.
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
Raducanu
Posts: 5
Joined: Monday 06 June 2016 9:39
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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

User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

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

Post by Westcott »

Is it a 'time' script rather than a 'device' script?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post by deennoo »

@Westcott t
That a device script i'm looking for a device status change (Chacon wall switch)
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post 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
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

When you use the internal script editor make sure you do not have "All" but "Device" selected underneath LUA.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post 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 !
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
sangve
Posts: 4
Joined: Friday 02 December 2016 0:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by sangve »

Oh, that's just lovely!
Thank you for helping me with the exact same thing! <3
mbeefcake
Posts: 1
Joined: Monday 03 April 2017 10:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by mbeefcake »

Helped me too :) Thanks!
Raspberry Pi 2B with RFXCOM RFXtrx433E
Raspbian Jessie Lite with Domoticz Beta v3.7253
Amazon Echo Dot v2, NEST Thermostat, Smart P1 Meter, YeeLights (White, Color and LED Strip), KaKu switches, Conrad RSLU, Alecto WS1700 and Digoo SB-XYZ Video doorbell
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

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

Post by freijn »

Helped me , many thanks !
Stefan
Posts: 6
Joined: Tuesday 27 June 2017 9:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: The Netherlands
Contact:

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

Post by Stefan »

helped me too :D bedankt
rammstan
Posts: 12
Joined: Monday 04 January 2016 12:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
RPi 2 + UPS Pico + enOcean + RFXCOM ext 250
digdilem
Posts: 5
Joined: Sunday 14 January 2018 14:31
Target OS: Linux
Domoticz version:
Contact:

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

Post by digdilem »

Another one this helped!

Really non-intuitive behaviour and not a very helpful error message, so glad for this help.
Medzu
Posts: 1
Joined: Tuesday 17 April 2018 14:36
Target OS: Linux
Domoticz version:
Contact:

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

Post by Medzu »

Thnx! :D
u01026366
Posts: 4
Joined: Friday 31 January 2014 0:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Italy
Contact:

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

Post by u01026366 »

solved also for me

thanks !!!
imautohuttraeger
Posts: 97
Joined: Saturday 14 March 2020 13:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by imautohuttraeger »

Helped me, too. Thx!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest