idea for device within a timer

Easy to use, 100% Lua-based event scripting framework.
Post Reply
poudenes
Posts: 473
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

idea for device within a timer

Post by poudenes » Thursday 22 February 2018 10:44

Hi All,

I have some scripts that triggered by follow

Code: Select all

on = {
        timer = {'at nighttime'},
        devices = {SensorMasterBedroom},
    },
Maybe its a idea to add the device into the timer. So that device will only triggered within the timer. This example when its nighttime

Now it triggered always on the Sensor but does't do his actions. I see lots of log lines that are unnecessary.

cheers,
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

dannybloe
Posts: 1433
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: idea for device within a timer

Post by dannybloe » Thursday 22 February 2018 13:43

Check the docs: devices = { 'SensorMasterBedroom' = { 'at nighttime' } }
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

poudenes
Posts: 473
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: idea for device within a timer

Post by poudenes » Thursday 22 February 2018 13:47

dannybloe wrote:
Thursday 22 February 2018 13:43
Check the docs: devices = { 'SensorMasterBedroom' = { 'at nighttime' } }
Thanks, i was playing with that option but didn't find out the right way.

Thanks again for helping !!! :D
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

poudenes
Posts: 473
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: idea for device within a timer

Post by poudenes » Friday 23 February 2018 0:20

dannybloe wrote:
Thursday 22 February 2018 13:43
Check the docs: devices = { 'SensorMasterBedroom' = { 'at nighttime' } }
It is working but not the way how i expected. When sensor turn on it wait for when the time change 1 minute then it turn on the lights.
When sensor goes of it wait again to turn off the lights
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

dannybloe
Posts: 1433
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: idea for device within a timer

Post by dannybloe » Friday 23 February 2018 9:18

I can say that, given the current state of how everything works, this is technically impossible. When the device gets an update it immediately triggers the event system and dzVents will check if the current time is matching the 'at nighttime' rule. If that's the case then the event script is called immediately. There is no code in dzVents that can put the event on hold until the start of the minute. As a matter of fact, I just tested it. So.. having said that I can only conclude that the event is only raised every minute. Perhaps your sensor only reports to Domoticz every minute or your trigger rules in your script are not correct.
Btw, the rule above should be like (with the square brackets) but your probably already knew that:

Code: Select all

devices = { 
   { ['SensorMasterBedroom'] = { 'at nighttime' } }
}
Maybe you can post the entire script here.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

poudenes
Posts: 473
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: idea for device within a timer

Post by poudenes » Friday 23 February 2018 10:31

I tried lot of things and now it working.

Code: Select all

devices = {[SensorMasterBedroom] = { 'at nighttime' }},
This was the line for me to let it work.

Here the full script

Code: Select all

local Version               = '18.02.22'
local SensorMasterBedroom	= 529
local MasterBedroom		    = 7
local SwitchGoodnight   	= 65

return {
    active = true,
    on = {
        devices = {[SensorMasterBedroom] = { 'at nighttime' }},
    },
    logging = {marker = 'SLAAPKAMER Sensor ' ..Version..'......'},
    execute = function(domoticz, device)

    if
    domoticz.devices(SensorMasterBedroom).active and
    domoticz.devices(SwitchGoodnight).state == 'Off'
    then
        domoticz.devices(MasterBedroom).dimTo(100)
        domoticz.devices(MasterBedroom).dimTo(100)
        domoticz.devices(MasterBedroom).setKelvin(5000)

    elseif
    domoticz.devices(SensorMasterBedroom).toggleSwitch() and
    domoticz.devices(MasterBedroom).active and
    domoticz.devices(SwitchGoodnight).state == 'Off'
    then
        domoticz.devices(MasterBedroom).dimTo(1)
        domoticz.devices(MasterBedroom).switchOff().afterSec(1)
        end
    end
}
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

dannybloe
Posts: 1433
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: idea for device within a timer

Post by dannybloe » Friday 23 February 2018 10:57

Code: Select all

local Version               = '18.02.22'
local SensorMasterBedroom	= 529
local MasterBedroom		    = 7
local SwitchGoodnight   	= 65

return {
	on = {
		devices = {[SensorMasterBedroom] = { 'at nighttime' }},
	},
	logging = {marker = 'SLAAPKAMER Sensor ' ..Version..'......'},
	execute = function(domoticz, sensor)
		local goodnightSwitch = domoticz.devices(SwitchGoodnight)
		local light = domoticz.devices(MasterBedroom)
		
		if (sensor.active and not goodnightSwitch.active) then
			light.dimTo(100)
			light.setKelvin(5000)
		elseif (light.active and not goodnightSwitch.active) then
			light.dimTo(1)
			light.switchOff().afterSec(1)
		end
	end
}
You had a 'domoticz.devices(SensorMasterBedroom).toggleSwitch()' in your elseif statement and that is not correct as the function toggleSwitch() doesn't return anything (nil basically so your elseif will always fail).

Untested of course ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

poudenes
Posts: 473
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: idea for device within a timer

Post by poudenes » Friday 23 February 2018 11:07

Hmm... because its was working :).
Your script is working also. Look nicer :)
I have to learn a lot :) every time little bit more haha

If i understand it correct. execute = function(domoticz, sensor) refer to everything thats in devices = {[SensorMasterBedroom] = { 'at nighttime' }} ?

So if i put 2 devices in it then sensor.active will check if those devices are both active?
dannybloe wrote:
Friday 23 February 2018 10:57

Code: Select all

local Version               = '18.02.22'
local SensorMasterBedroom	= 529
local MasterBedroom		    = 7
local SwitchGoodnight   	= 65

return {
	on = {
		devices = {[SensorMasterBedroom] = { 'at nighttime' }},
	},
	logging = {marker = 'SLAAPKAMER Sensor ' ..Version..'......'},
	execute = function(domoticz, sensor)
		local goodnightSwitch = domoticz.devices(SwitchGoodnight)
		local light = domoticz.devices(MasterBedroom)
		
		if (sensor.active and not goodnightSwitch.active) then
			light.dimTo(100)
			light.setKelvin(5000)
		elseif (light.active and not goodnightSwitch.active) then
			light.dimTo(1)
			light.switchOff().afterSec(1)
		end
	end
}
You had a 'domoticz.devices(SensorMasterBedroom).toggleSwitch()' in your elseif statement and that is not correct as the function toggleSwitch() doesn't return anything (nil basically so your elseif will always fail).

Untested of course ;-)
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests