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

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

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

Post by deennoo » Thursday 09 June 2016 12:43

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 / ESP8266 / MQTT / BLE
http://domo-attitude.fr

Raducanu
Posts: 5
Joined: Monday 06 June 2016 9:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by Raducanu » Thursday 09 June 2016 13:33

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: 547
Joined: Tuesday 09 December 2014 18:04
Target OS: Raspberry Pi
Domoticz version: Beta
Location: UK - Glos
Contact:

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

Post by Westcott » Thursday 09 June 2016 13:58

Is it a 'time' script rather than a 'device' script?
Zwave - Sigma Z+ stick, Fibaro 2x FGSD002, FGMS001
Horstmann - 2x HRT4, 2x C-stat-11, 4x ASR-ZW, TKB 2x TZ56, 2x TZ68E
Max-EQ Cube, Valve, Neo 2x door
RFXtrx433E, RFlink - 1byone driveway, doorbell, Oregon and BangGood temp
Wifi - YeeLight RGB, 3x ESP8266

deennoo
Posts: 914
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post by deennoo » Thursday 09 June 2016 14:45

@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 / ESP8266 / MQTT / BLE
http://domo-attitude.fr

deennoo
Posts: 914
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post by deennoo » Thursday 09 June 2016 14:54

@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 / ESP8266 / MQTT / BLE
http://domo-attitude.fr

User avatar
jvdz
Posts: 1073
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

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

Post by jvdz » 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

deennoo
Posts: 914
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

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

Post by deennoo » Thursday 09 June 2016 20:40

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 / ESP8266 / MQTT / BLE
http://domo-attitude.fr

sangve
Posts: 4
Joined: Friday 02 December 2016 1:02
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by sangve » Wednesday 14 December 2016 0:34

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
Domoticz version:
Contact:

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

Post by mbeefcake » Wednesday 05 April 2017 13:16

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: 178
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

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

Post by freijn » Thursday 20 April 2017 15:17

Helped me , many thanks !

Stefan
Posts: 9
Joined: Tuesday 27 June 2017 9:02
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: The Netherlands
Contact:

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

Post by Stefan » Sunday 06 August 2017 13:31

helped me too :D bedankt

rammstan
Posts: 12
Joined: Monday 04 January 2016 13:35
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Post by rammstan » Monday 13 November 2017 19:06

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

Kappler704
Posts: 1
Joined: Friday 15 December 2017 14:10
Target OS: Linux
Domoticz version:
Contact:

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

Post by Kappler704 » Friday 15 December 2017 14:11

Now you will locate the list of outcome appears on your pc display, mobdroapptv the globe with its terrific streaming capability.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests