Script help

Moderator: leecollings

Post Reply
Alfagek
Posts: 26
Joined: Sunday 09 February 2020 15:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Leeuwarden
Contact:

Script help

Post by Alfagek »

I need a little help.

I did try to make a script to turn on/off my tablet screen with my motion sensor.
It function, but i see in my log that i get 2 times a screen off command, when sensor is off. And when sensor is on, it sends first off command and then on command.
What do i have wrong in my script.

Code: Select all

commandArray = {}

if (devicechanged['MotionWoonkamer']) then
	if (otherdevices['MotionWoonkamer']) == 'On' then
            commandArray={['OpenURL']='http://xxx.xxx.xxx.xxx:2323/?cmd=screenOn&password=xxxxxx'}
    	    print('Tablet Scherm Aan.')
	    elseif (otherdevices['MotionWoonkamer']) == 'Off' then
            commandArray={['OpenURL']='http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxx'}
    	    print('Tablet Scherm Uit.')
    end
end

return commandArray
This is what i get when motionsensor is going off:

Code: Select all

 2020-04-04 14:17:48.190 Status: OpenZWave: Alarm received (Home Security: Clear), NodeID: 7 (0x07)
2020-04-04 14:17:48.320 Status: LUA: Tablet Scherm Uit.
2020-04-04 14:17:48.321 Status: EventSystem: Fetching URL http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxx after 0.2 seconds...
2020-04-04 14:17:48.321 Status: EventSystem: Script event triggered: Scherm Tablet
2020-04-04 14:17:48.401 Status: LUA: Tablet Scherm Uit.
2020-04-04 14:17:48.403 Status: EventSystem: Fetching URL http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxx after 0.2 seconds...
2020-04-04 14:17:48.403 Status: EventSystem: Script event triggered: Scherm Tablet 
And this when motionsensor on:

Code: Select all

 2020-04-04 14:17:59.937 Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 7 (0x07)
2020-04-04 14:18:00.020 Status: LUA: Tablet Scherm Uit.
2020-04-04 14:18:00.021 Status: EventSystem: Fetching URL http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxx after 0.2 seconds...
2020-04-04 14:18:00.021 Status: EventSystem: Script event triggered: Scherm Tablet
2020-04-04 14:18:00.102 Status: LUA: Tablet Scherm Aan.
2020-04-04 14:18:00.103 Status: EventSystem: Fetching URL http://xxx.xxx.xxx.xxx:2323/?cmd=screenOn&password=xxxxx after 0.2 seconds...
2020-04-04 14:18:00.103 Status: EventSystem: Script event triggered: Scherm Tablet 
Thanks in advanced
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Script help

Post by bewo »

Hi Alfagek,

the way you've done your script is nice, but i think it's to "slow" to have the right state... I would try it in a way like this:

Code: Select all

motion_sensor = 'MotionWoonkamer'

commandArray = {}

if devicechanged[motion_sensor] == 'On' then
    commandArray={['OpenURL']='http://xxx.xxx.xxx.xxx:2323/?cmd=screenOn&password=xxxxxx'}
    print('Tablet Scherm -> Aan.')
elseif devicechanged[motion_sensor] == 'Off' then
    commandArray={['OpenURL']='http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxx'}
    print('Tablet Scherm -> Uit.')
end

return commandArray
Or if you don't need the URL-line in log you can use:

Code: Select all

motion_sensor = 'MotionWoonkamer'

commandArray = {}

if devicechanged[motion_sensor] == 'On' then
    os.execute('curl --max-time 5 "http://xxx.xxx.xxx.xxx:2323/?cmd=screenOn&password=xxxxxx"')
    print('Tablet Scherm Aan.')
elseif devicechanged[motion_sensor] == 'Off' then
    os.execute('curl --max-time 5 "http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxxx"')
    print('Tablet Scherm Uit.')
end

return commandArray
:)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Alfagek
Posts: 26
Joined: Sunday 09 February 2020 15:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Leeuwarden
Contact:

Re: Script help

Post by Alfagek »

bewo wrote: Monday 06 April 2020 14:00 Hi Alfagek,

the way you've done your script is nice, but i think it's to "slow" to have the right state... I would try it in a way like this:

Code: Select all

motion_sensor = 'MotionWoonkamer'

commandArray = {}

if devicechanged[motion_sensor] == 'On' then
    commandArray={['OpenURL']='http://xxx.xxx.xxx.xxx:2323/?cmd=screenOn&password=xxxxxx'}
    print('Tablet Scherm -> Aan.')
elseif devicechanged[motion_sensor] == 'Off' then
    commandArray={['OpenURL']='http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxx'}
    print('Tablet Scherm -> Uit.')
end

return commandArray
Or if you don't need the URL-line in log you can use:

Code: Select all

motion_sensor = 'MotionWoonkamer'

commandArray = {}

if devicechanged[motion_sensor] == 'On' then
    os.execute('curl --max-time 5 "http://xxx.xxx.xxx.xxx:2323/?cmd=screenOn&password=xxxxxx"')
    print('Tablet Scherm Aan.')
elseif devicechanged[motion_sensor] == 'Off' then
    os.execute('curl --max-time 5 "http://xxx.xxx.xxx.xxx:2323/?cmd=screenOff&password=xxxxxx"')
    print('Tablet Scherm Uit.')
end

return commandArray
:)
Thanks Bewo 8-)

It looks like indeed that the scripts to "slow" for the right state.
Did try the both scripts you provided, but i did get the same. OFF, ON and OFF OFF.
But i like the second one you suggested because off no extra text in the log. Thanks fot that :D
I could also give the commands in the "switch" self. But i would make the off command with a delay of 3 minutes.

Code: Select all

 2020-04-06 16:18:45.297 Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 7 (0x07)
2020-04-06 16:18:46.512 Status: LUA: Tablet Scherm Uit.
2020-04-06 16:18:47.778 Status: LUA: Tablet Scherm Aan.
2020-04-06 16:19:28.583 Status: OpenZWave: Alarm received (Home Security: Clear), NodeID: 7 (0x07)
2020-04-06 16:19:29.374 Status: LUA: Tablet Scherm Uit.
2020-04-06 16:19:30.135 Status: LUA: Tablet Scherm Uit. 
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Script help

Post by bewo »

Hmm... that's spooky...
Is it possible, that Zwave reports this On/Off/On..... I mean, if you look in the device log (motion sensor) are there this lines, too?
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Alfagek
Posts: 26
Joined: Sunday 09 February 2020 15:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Leeuwarden
Contact:

Re: Script help

Post by Alfagek »

bewo wrote: Monday 06 April 2020 17:12 Hmm... that's spooky...
Is it possible, that Zwave reports this On/Off/On..... I mean, if you look in the device log (motion sensor) are there this lines, too?
Sorry for the late reaction Bewo.

Yesterday Domoticz crashed, so i installed Monit. And after a restart i did had problems that my z-wave didn't work anymore.
Now all is working again, gladly.

Now also no double Off/On and Off/Off. Even my own script is working normal. Only now figering out to use a delay for sending command ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest