Page 1 of 1

What do i mis? Strange behaviour of script(s)

Posted: Friday 17 May 2019 21:49
by hoeby
I have a script which monitor if my dashboard is ON or OFF.
Between times it will be switched OFF.
In stable 4.0097 i had it as 1 script. But didn't used it to much, so testing was not 100%
Now in the next stable version 4.10717 i can't get it to work. Althouged not 100% tested in the previous version, it still looks like it reacts different now

I saved both codes with little scripts. Not 1 script with both in it.
This to overlook in de log, which scripts is triggered.
But when i switch, both scripts are triggered. I don't know why, because i ask to look at the device.state.

What do i mis here?

Code: Select all

return {
	on = {
		devices = {'Backlight Dashboard'}
		},
		
	execute = function(domoticz, device)
        if(
	        device.state == 'Off' and
	        domoticz.time.matchesRule('on thu,fri,sat,sun') and
	        domoticz.time.matchesRule('between 07:00 and 21:00')) then
	            domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,1'})
                domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,0'}).afterSec(1)
	end
end
}

Code: Select all

return {
	on = {
		devices = {'Backlight Dashboard'}
		},
		
	execute = function(domoticz, device)
        if(
            device.state == 'On' and
	        domoticz.time.matchesRule('on mon,tue,wed,thu,fri,sat,sun') and
	        (domoticz.time.hour >= 21 or domoticz.time.hour < 7)) then
	            domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,1'}).afterSec(150)
                domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,0'}).afterSec(151)
	end
end
}

Re: What do i mis? Strange behaviour of script(s)

Posted: Friday 17 May 2019 23:16
by hoeby
I think i got it solved.
The problem was i used the wrong triggers.

Changed it to this, but it is the right way?
Now every minut the script is checked by domoticz. I prefered only when there is a change.

don't look at the esp url, need to change it mqtt, sorry.

Code: Select all

return {
	on = {timer =   {'between 07:00 and 21:00 on thu,fri,sat,sun',}
		},
		
	execute = function(domoticz, device)
        if (domoticz.devices('Backlight Dashboard').state == 'Off') then
	            domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,1'})
                domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,0'}).afterSec(1)
	end
end
}

Code: Select all

return {
	on = {timer =   {'at 21:00-07:00 on mon,tue,wed,thu,fri,sat,sun'}
		},
		
	execute = function(domoticz, device)
        if (domoticz.devices('Backlight Dashboard').state == 'On' and
            domoticz.devices('Dashboard Homepage Trigger').state == 'Off') then
	            domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,1'})
                domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,0'}).afterSec(1)
	end
end
}

Re: What do i mis? Strange behaviour of script(s)

Posted: Saturday 18 May 2019 7:26
by waaren
hoeby wrote: Friday 17 May 2019 23:16 Now every minute the script is checked by domoticz. I preferred only when there is a change.
Not sure if I completely understand but could you check this ?

Code: Select all

return {
    on = {  devices = {'Backlight Dashboard'} },   -- Script will be triggered when device state changed
        
        
        logging =   {   level   =   domoticz.LOG_DEBUG,    -- change to LOG_ERROR when script executes OK
                        marker  =   'GPIO Control'},
                        
    execute = function(domoticz, item)
    
        local function controlGPIO(switch,delay)
            domoticz.openURL('http://192.168.178.189/control?cmd=gpio,13,' .. switch).afterSec(delay)
        end
        
        domoticz.log("Device state of " .. item.name .. " is " .. item.state,domoticz.LOG_DEBUG)
        domoticz.log('on thu,fri,sat,sun between 07:00 and 21:00 is ' .. tostring(domoticz.time.matchesRule('on thu,fri,sat,sun between 07:00 and 21:00')) ,domoticz.LOG_DEBUG)
        domoticz.log('at 21:00-07:00 is ' .. tostring(domoticz.time.matchesRule('at 21:00-07:00')) ,domoticz.LOG_DEBUG)
        
        if item.state == 'Off' and domoticz.time.matchesRule('on thu,fri,sat,sun between 07:00 and 21:00') then
            controlGPIO(1,0)
            controlGPIO(0,1)
        elseif item.state == 'Off' and domoticz.time.matchesRule('at 21:00-07:00') then
            controlGPIO(1,150)
            controlGPIO(0,151)
        end
    end
}

Re: What do i mis? Strange behaviour of script(s)

Posted: Saturday 18 May 2019 8:00
by hoeby
Thanks Waaren, need to change something, but i can work with it.

Backlight Dashboard is only to see if the display is on or off, therefor not useable as trigger.

How does it work:
- The GPIO switch is connected with the on/off hardware switch of the display.
- An input is made, which monitors if the display is on or off, this is Backlight Dashboard.
- Another device (dashboard trigger), that one is controlled by a touch on the touchscreen. This will switch on the display, when it is OFF

Re: What do i mis? Strange behaviour of script(s)

Posted: Saturday 18 May 2019 9:23
by hoeby
I changed to script, so it looks to a variable.
This keeps the risk to a minimum, that i use a dummy switch and i switch i by accident
Now the script is trigger on 2 times and not every minut.
Still work to do, but the basic works.

Code: Select all

return {
	on = { timer   = {'at 7:00',
        	                'at 21:00'}
         },
		
	execute = function(domoticz, device)
        if  (domoticz.variables('DashboardVariable').value == '07:00' and 
             domoticz.devices('Backlight Dashboard').state == 'Off') then
	            domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,1'})
                    domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,0'}).afterSec(1)
                    domoticz.variables('DashboardVariable').set('21:00')
        elseif 
            (domoticz.variables('DashboardVariable').value == '21:00' and 
             domoticz.devices('Backlight Dashboard').state == 'On') then
	            domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,1'})
                    domoticz.openURL({url = 'http://192.168.178.189/control?cmd=gpio,13,0'}).afterSec(1)
                    domoticz.variables('DashboardVariable').set('07:00')
	end
end
}