Action script only executing a few times Topic is solved

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
StevenK
Posts: 3
Joined: Saturday 18 February 2017 22:23
Target OS: -
Domoticz version:
Contact:

Action script only executing a few times

Post by StevenK »

I've got a number of devices which I usually control through either webinterface of app. Now I've got myself a few switches and want to use these switch lights on and of.
I've got a small php script:

Code: Select all

#!/usr/bin/php
<?php
$id=$argv[1];
print "Id: $id";
$js=file_get_contents("http://192.168.11.119:8080/json.htm?type=devices&rid=$id");
$p=json_decode($js);
if ($p->result[0]->Data=='On') {
        print "Uitschakelen";
        $r=file_get_contents("http://192.168.11.119:8080/json.htm?type=command&param=switchlight&switchcmd=Off&idx=$id");
} else {
        print "Aanzetten";
        $r=file_get_contents("http://192.168.11.119:8080/json.htm?type=command&param=switchlight&switchcmd=On&idx=$id");
}
?>
Which runs file. Calling 'switch.php 30' for instance toggles my bathroom light.Then I put

Code: Select all

script://switch.php 30
In the 'on' action of one of the buttons. Tested it and it worked. I got to switch the bathroom light on and off. So far, so good. But after 5 or 6 times, it appears not to invoke the script anymore.
Each press of a button is neatly recorded in the switch's log:

Code: Select all

2020-07-25 08:52:30	On	Admin
2020-07-25 08:50:04	On	Admin
2020-07-25 08:17:01	On	Admin
2020-07-25 08:16:49	On	Admin
2020-07-25 08:16:01	On	Admin
2020-07-25 08:15:46	On	Admin
But only the first few of these triggered the php script. Then removed these action scripts and created a script in Domoticz:

Code: Select all

return {
	on = {
		devices = {
			46,47
		}
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was clicked', domoticz.LOG_INFO)
		if (device.id == 46) then
		    if (domoticz.devices(30).state == 'On') then
		        domoticz.devices(30).switchOff()
        		domoticz.log('Device 30 was switched off', domoticz.LOG_INFO)
	        else
	            domoticz.devices(30).switchOn()
        		domoticz.log('Device 30 was switched on', domoticz.LOG_INFO)
            end
        end
		if (device.id == 47) then
		    if (domoticz.devices(31).state == 'On') then
		        domoticz.devices(31).switchOff()
        		domoticz.log('Device 31 was switched off', domoticz.LOG_INFO)
	        else
	            domoticz.devices(31).switchOn()
        		domoticz.log('Device 31 was switched on', domoticz.LOG_INFO)
            end
        end
	end
}
This is script is for both buttons. 46 to trigger the bathroom light, 47 to trigger the bathroom ventilator. If I look at the log, it should be working:

Code: Select all

2020-07-25 09:02:52.386 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 09:02:52.386 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 09:02:52.387 Status: dzVents: Info: Device SW Badkamer was clicked
2020-07-25 09:02:52.403 Status: dzVents: Info: Device 30 was switched on
2020-07-25 09:02:52.403 Status: dzVents: Info: ------ Finished Script #1
2020-07-25 09:02:52.407 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 09:03:11.377 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 09:03:11.377 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 09:03:11.378 Status: dzVents: Info: Device SW Badkamer was clicked
2020-07-25 09:03:11.394 Status: dzVents: Info: Device 30 was switched on
2020-07-25 09:03:11.394 Status: dzVents: Info: ------ Finished Script #1
But as you can tell, @9:02:52 it thinks it switched the bathroom on, but it didn't, since @9:03:11 it tries to switch it on again.
Does anyone have a clue where to look?
BTW:

Code: Select all

Version: 2020.2
Build Hash: b63341bc0
Compile Date: 2020-04-26 13:47:55
dzVents Version: 3.0.2
Python Version: 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Action script only executing a few times

Post by waaren »

StevenK wrote: Saturday 25 July 2020 9:08 I've got a number of devices which I usually control through either webinterface of app. Now I've got myself a few switches and want to use these switch lights on and of.
But as you can tell, @9:02:52 it thinks it switched the bathroom on, but it didn't, since @9:03:11 it tries to switch it on again.
Does anyone have a clue where to look?
Not yet but if you add some debug lines it might show something useful

Code: Select all

return {
    on = {
        devices = {
            46,47
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'toggler',
    },

    execute = function(domoticz, device)

        slave1 = domoticz.devices(30)
        slave2 = domoticz.devices(31)

        domoticz.log('Device ' .. device.name .. ' was clicked', domoticz.LOG_DEBUG)
        domoticz.log('State of device ' .. device.name .. ', (' .. device.id .. ') is ' .. device.state, domoticz.LOG_DEBUG)
        domoticz.log('State of device ' .. slave1.name .. ', (' .. slave1.id .. ') is ' .. slave1.state, domoticz.LOG_DEBUG)
        domoticz.log('State of device ' .. slave2.name .. ', (' .. slave2.id .. ') is ' .. slave2.state, domoticz.LOG_DEBUG)

        if device.id == 46 then
            slave1.toggleSwitch()
            domoticz.log(slave1.name .. ' will be toggled ', domoticz.LOG_DEBUG)
        elseif device.id == 47 then
            slave2.toggleSwitch()
            domoticz.log(slave2.name .. ' will be toggled ', domoticz.LOG_DEBUG)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
StevenK
Posts: 3
Joined: Saturday 18 February 2017 22:23
Target OS: -
Domoticz version:
Contact:

Re: Action script only executing a few times

Post by StevenK »

Thanks @waaren, debugging added. I've just been able to switch them a few times, but after that it failed again.

Code: Select all

2020-07-25 13:10:41.106 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:10:41.107 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:10:41.107 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:10:41.114 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:10:41.115 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:10:41.116 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:10:41.116 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:10:41.120 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:11:45.792 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:11:45.793 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:11:45.794 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:11:45.799 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:11:45.801 Status: dzVents: Debug: toggler: Constructed timed-command: Off
2020-07-25 13:11:45.802 Status: dzVents: Info: toggler: Device 30 was switched off
2020-07-25 13:11:45.802 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:11:45.805 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:11:57.090 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:11:57.091 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:11:57.091 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:11:57.098 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:11:57.099 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:11:57.100 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:11:57.101 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:11:57.105 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:12:31.366 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:12:31.367 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:12:31.367 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:12:31.378 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:12:31.386 Status: dzVents: Debug: toggler: Constructed timed-command: Off
2020-07-25 13:12:31.388 Status: dzVents: Info: toggler: Device 30 was switched off
2020-07-25 13:12:31.388 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:12:31.392 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:12:37.168 Status: dzVents: Info: Handling events for: "SW Badkamer Ventilator", value: "On"
2020-07-25 13:12:37.169 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer Ventilator (Z-Stick gen5)", Index: 47
2020-07-25 13:12:37.169 Status: dzVents: Info: toggler: Device SW Badkamer Ventilator was clicked
2020-07-25 13:12:37.176 Status: dzVents: Debug: toggler: Processing device-adapter for Ventilator Badkamer: Switch device adapter
2020-07-25 13:12:37.177 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:12:37.178 Status: dzVents: Info: toggler: Device 31 was switched on
2020-07-25 13:12:37.178 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:12:37.182 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:12:37.451 Status: Executing script: /home/pi/domoticz/scripts/delayoff.php
2020-07-25 13:12:41.971 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:12:41.972 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:12:41.972 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:12:41.979 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:12:41.980 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:12:41.980 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:12:41.981 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:12:41.984 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:12:53.156 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:12:53.156 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:12:53.157 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:12:53.172 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:12:53.173 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:12:53.174 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:12:53.174 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:12:53.178 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:13:02.226 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:13:02.227 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:13:02.227 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:13:02.233 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:13:02.234 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:13:02.235 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:13:02.236 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:13:02.239 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:13:07.134 Status: dzVents: Info: Handling events for: "SW Badkamer Ventilator", value: "On"
2020-07-25 13:13:07.134 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer Ventilator (Z-Stick gen5)", Index: 47
2020-07-25 13:13:07.135 Status: dzVents: Info: toggler: Device SW Badkamer Ventilator was clicked
2020-07-25 13:13:07.142 Status: dzVents: Debug: toggler: Processing device-adapter for Ventilator Badkamer: Switch device adapter
2020-07-25 13:13:07.143 Status: dzVents: Debug: toggler: Constructed timed-command: Off
2020-07-25 13:13:07.143 Status: dzVents: Info: toggler: Device 31 was switched off
2020-07-25 13:13:07.144 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:13:07.148 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:13:49.366 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:13:49.367 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:13:49.367 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:13:49.374 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:13:49.375 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:13:49.376 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:13:49.376 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:13:49.380 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-07-25 13:14:21.935 Status: dzVents: Info: Handling events for: "SW Badkamer", value: "On"
2020-07-25 13:14:21.935 Status: dzVents: Info: toggler: ------ Start internal script: Script #1: Device: "SW Badkamer (Z-Stick gen5)", Index: 46
2020-07-25 13:14:21.936 Status: dzVents: Info: toggler: Device SW Badkamer was clicked
2020-07-25 13:14:21.951 Status: dzVents: Debug: toggler: Processing device-adapter for Lamp Badkamer: Switch device adapter
2020-07-25 13:14:21.952 Status: dzVents: Debug: toggler: Constructed timed-command: On
2020-07-25 13:14:21.953 Status: dzVents: Info: toggler: Device 30 was switched on
2020-07-25 13:14:21.954 Status: dzVents: Info: toggler: ------ Finished Script #1
2020-07-25 13:14:21.958 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
I don't see anything different in the log. The script engine thinks Device 30 was switched on, but that's just not the case :) In the mean time I can still toggle switch 30 by running

Code: Select all

/home/pi/domoticz/scripts/switch.php 30
Or by clicking it in the webinterface, so it's not about the switch not responding to commands.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Action script only executing a few times

Post by waaren »

StevenK wrote: Saturday 25 July 2020 13:18 Debugging added. I've just been able to switch them a few times, but after that it failed again.
The loglines you showed are not the ones I expected if you used the changed script I posted. Can you try with that one. it will not solve the issue but might point you in the right direction.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
StevenK
Posts: 3
Joined: Saturday 18 February 2017 22:23
Target OS: -
Domoticz version:
Contact:

Re: Action script only executing a few times

Post by StevenK »

Sorry, overlooked the rest of the code. After changing the code, I was able to switch 30 a couple of times, until I switched 31 once, after that it didn't work anymore. And that last one appeared to be part of the problem. 31 had a script attached that did a delay, but I just found a reference on how the event system is single threaded, meaning that the delay script locks up al event scripts.

Thanks a lot for helping me out so quickly, @waaren.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest