I am trying to write a script that relies on a device id. According to the documentation the method is ".id"
Here is a fragment of my code:
Code: Select all
(53) printf("Device is: %s (%s)", _device.name, _device.id)
(54) print("Alarm "..domoticz.devices['Alarm'].id)
When the script executes while dzVent logging level is set to 2, the log shows the following:
2016-04-06 18:07:54.252 LUA: Handling events for: "envKitchen_Temperature", value: "20.39999961853"
2016-04-06 18:07:54.252 LUA: =====================================================
2016-04-06 18:07:54.252 LUA: >>> Handler: heating
2016-04-06 18:07:54.253 LUA: >>> Device: "envKitchen" Index: nil
2016-04-06 18:07:54.253 LUA: .....................................................
2016-04-06 18:07:54.253 LUA: heating: Boiler is : On - Heating set to On
2016-04-06 18:07:54.253 LUA: heating: current: 20.39999961853
2016-04-06 18:07:54.254 LUA: heating: target: 20
2016-04-06 18:07:54.254 LUA: heating: Device is: envKitchen (nil)
2016-04-06 18:07:54.254 LUA: An error occured when calling event handler heating
2016-04-06 18:07:54.255 LUA: /home/pi/domoticz/scripts/lua/scripts/heating.lua:54: attempt to index global 'device' (a nil value)
2016-04-06 18:07:54.255 LUA: .....................................................
2016-04-06 18:07:54.255 LUA: <<< Done
2016-04-06 18:07:54.255 LUA: -----------------------------------------------------
The script bombs executing line 54.
This highlights two problems:
1) the debug log entry fails to decode the device id when scripts run when a device has interrupted. c.f
2016-04-06 18:07:54.252 LUA: >>> Handler: heating
2016-04-06 18:07:54.253 LUA: >>> Device: "envKitchen" Index: nil
and
2) the ".id" method doesn't seem to work and bombs with a strange device name referred to:
2016-04-06 18:07:54.258 LUA: An error occured when calling event handler heating
2016-04-06 18:07:54.258 LUA: /home/pi/domoticz/scripts/lua/scripts/heating.lua:54: attempt to index global 'device' (a nil value)
Is the issue in dzVents or with the bio-degradeable carbon-based life-form pressing the buttons?