Page 1 of 1

Xiaomi Cube - shake_air

Posted: Sunday 19 February 2017 19:27
by DreaMare
Hello every one !

With this code (1) in web interface : all work well but I got this error :
2017-02-19 19:24:00.198 Error: EventSystem: in script_device_cube.lua: [string "-- script_device_cube.lua..."]:5: attempt to index global 'devicechanged' (a nil value)

When i put this lua script in /home/pi/domoticz/scripts/lua, the error disappear but the shake_air doesn't work : / (the other change work well)

Thank you !

(1)

Code: Select all

-- script_device_cube.lua

commandArray = {}

if devicechanged['Xiaomi Cube Switch'] == "shake_air" then

    commandArray['Scene Tout éteindre'] = "On"    
    
elseif devicechanged['Xiaomi Cube Switch'] == "flip180" then
    
    commandArray['Scene Catoune on'] = "On"  
    
elseif devicechanged['Xiaomi Cube Switch'] == "tap_twice" then
    
    commandArray['Scene Office on 1426365250000'] = "On"     
    
elseif devicechanged['Xiaomi Cube Switch'] == "flip90" then
    
    commandArray['Scene Cinema on 1438118688000'] = "On"       
    
elseif devicechanged['Xiaomi Cube Switch'] == "move" then
    
    commandArray['Scene Saenger Sky on 1403011832000'] = "On"           

elseif devicechanged['Xiaomi Cube Switch'] == "clock_wise" then
    
    commandArray['Scene 12th Man on 1403013718000'] = "On"       

elseif devicechanged['Xiaomi Cube Switch'] == "anti_clock_wise" then
    
     commandArray['Scene Détente'] = "On"   

end


return commandArray

Re: Xiaomi Cube - shake_air

Posted: Wednesday 22 February 2017 11:31
by bertbigb
First be sure that you store this script as a device script and let start to do that in the web interface since that is the most easy way

--> devicechanged commands only works in device scripts

Then the script complaints about Line 5 --> if devicechanged['Xiaomi Cube Switch'] == "shake_air" then

are you sure that you have a device 'Xiaomi Cube Scene' defined in domoticz?

Re: Xiaomi Cube - shake_air

Posted: Wednesday 22 February 2017 20:30
by DreaMare
bertbigb wrote:First be sure that you store this script as a device script and let start to do that in the web interface since that is the most easy way

--> devicechanged commands only works in device scripts
=> the name of file is : script_device_cube2.lua so i guess it's ok ?

bertbigb wrote:are you sure that you have a device 'Xiaomi Cube Scene' defined in domoticz?
I don't have set "Xiaomi Cube Scene", so I have to set one ?

I don't understand why the script on the interface work well, but not the one in folder :"/home/pi/domoticz/scripts/lua" : /

Re: Xiaomi Cube - shake_air

Posted: Wednesday 22 February 2017 21:42
by bertbigb
DreaMare wrote: => the name of file is : script_device_cube2.lua so i guess it's ok ?
Yes that should be OK

DreaMare wrote: I don't have set "Xiaomi Cube Scene", so I have to set one ?
I don't understand why the script on the interface work well, but not the one in folder :"/home/pi/domoticz/scripts/lua" : /
No I made a mistake by not reading correct (I read Xiaomi Cube Scene instead of Xiaomi Cube Switch) you have defined the Xiaomi Cube Switch so that can't be the case for the error 2017-02-19 19:24:00.198 Error: EventSystem: in script_device_cube.lua: [string "-- script_device_cube.lua..."]:5: attempt to index global 'devicechanged' (a nil value)

Do you still got this error?
I don't understand why the script on the interface work well, but not the one in folder :"/home/pi/domoticz/scripts/lua" : /
That I do not understand either, I myself always use the webinterface. Since I work on a Synology the path is different as yours on a pi also. Hope someone else can help you with that.

I'm waiting for my own Cube Switch and then will try it myself also.

Re: Xiaomi Cube - shake_air

Posted: Thursday 23 February 2017 22:39
by DreaMare
thank you anyway : )
I try out somethings but still got error.
And the script is a bit laggy and shake_air doesn't work :(

Re: Xiaomi Cube - shake_air

Posted: Thursday 23 February 2017 23:08
by deennoo
As this is a device script, you have to set your script to device and not to all, just under LUA string

Re: Xiaomi Cube - shake_air

Posted: Friday 24 February 2017 14:48
by DreaMare
deennoo wrote:As this is a device script, you have to set your script to device and not to all, just under LUA string
How ?

Re: Xiaomi Cube - shake_air

Posted: Friday 24 February 2017 16:20
by bertbigb
Event Settings.png
Event Settings.png (11.01 KiB) Viewed 2399 times
Here you tell what type of script it is, like Dennoo writes not All but Device

I hope this pictures helps you to get it fixed

Re: Xiaomi Cube - shake_air

Posted: Friday 24 February 2017 18:50
by DreaMare
thank's a lot ; )