domoticz.time issue for turning on lights  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
jberinga
Posts: 67
Joined: Tuesday 11 August 2015 14:20
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: The Netherlands
Contact:

domoticz.time issue for turning on lights

Post by jberinga »

I am on a mission to convert my Blocky events into dzVents, but with one of my scripts I am having some issues: it isn't responding on domoticz.time in the script logic. When removing the domoticz.time logic it is responding. This is my script and hopefully someone can help me with it...

Code: Select all

return {
    on = {
        devices = { 'IsDonker', 'IemandThuis', 'JBElgtv' },
    },
    execute = function(domoticz, device)

      --Donker, Iemand thuis, TV uit = alle verlichting AAN 
	   if 
			domoticz.devices('IsDonker').state == 'On' and
            domoticz.devices('VerlichtingBeneden_IemandThuis').state == 'Off' and
			domoticz.devices('IemandThuis').state == 'On' and
			domoticz.devices('JBElgtv').state == 'Off' and
			--domoticz.time == 'Between sunset and 21:59'
			domoticz.time.matchesRule('between sunset and 22:15')
		then
                domoticz.scenes('VerlichtingBeneden_AllOn').switchOn()
                domoticz.log('Verlichting beneden aan', domoticz.LOG_INFO)

	   --Donker, Iemand thuis, TV aan = TV verlichting AAN
		elseif
			domoticz.devices('IsDonker').state == 'On' and
            domoticz.devices('VerlichtingBeneden_WatchTV').state == 'Off' and
			domoticz.devices('IemandThuis').state == 'On' and
			domoticz.devices('JBElgtv').state == 'On' and
			domoticz.time == 'Between sunset and 22:15'
		then
                domoticz.scenes('VerlichtingBenedenTVOn').switchOn()
                domoticz.log('TV Verlichting beneden aan', domoticz.LOG_INFO)
				
	   --Donker, Niemand thuis = Sommige verlichting AAN
		elseif
			domoticz.devices('IsDonker').state == 'On' and
            domoticz.devices('VerlichtingBeneden_NiemandThuis').state == 'Off' and
			domoticz.devices('IemandThuis').state == 'Off' and
			domoticz.time == 'Between sunset and 22:15'
		then
                domoticz.scenes('VerlichtingBeneden_SomeOn').switchOn()
                domoticz.log('Sommige Verlichting beneden aan', domoticz.LOG_INFO)	

	   --Donker, Iemand thuis, Na 22:15 = Keuken verlichting tijdelijk AAN
		elseif
			domoticz.devices('IsDonker').state == 'On' and
            domoticz.devices('VerlichtingBeneden_Tijdelijk').state == 'Off' and
			domoticz.devices('IemandThuis').state == 'On' and
			domoticz.time == 'Between 22:15 and sunrise'
		then
                domoticz.devices(DimmerKeukenTafel).dimTo(30)
				domoticz.devices(VerlichtingBeneden_Tijdelijk).switchOn()
                domoticz.log('Keuken Verlichting tijdelijk aan', domoticz.LOG_INFO)				
        end
    end
}
Some clarification:
- IsDonker is a switch that turns ON when the sun is set
- IemandThuis is a switch that turns ON when someone is home
- JBElgtv is a switch that turns ON when the TV is on
- VerlichtingBeneden_IemandThuis, VerlichtingBeneden_WatchTV, VerlichtingBeneden_NiemandThuis, VerlichtingBeneden_Tijdelijk are switches that are used to control what "state" the lights are in
- After 22:15 only the kitchen light has to be turned on (last logic)
- As you can see I have been playing around with domoticz.time == and domoticz.time.matchesRule but both aren't working for me

Thanks in advanced!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: domoticz.time issue for turning on lights  [Solved]

Post by waaren »

jberinga wrote: Sunday 09 June 2019 11:29 I am on a mission to convert my Blocky events into dzVents, but with one of my scripts I am having some issues: it isn't responding on domoticz.time in the script logic. When removing the domoticz.time logic it is responding. This is my script and hopefully someone can help me with it...
Case matters ! (Between ~= between)

Code: Select all

return {
    on = {
        timer = { 'between 00:00 and 23:59' },
    },
    execute = function(domoticz)

        domoticz.log("0 domoticz time (false)             : " .. tostring(domoticz.time == 'between sunset and 22:15')) -- always false because domoticz.time is a table not a string
        
        domoticz.log("1 matchesRule (true in the evening) : " .. tostring(domoticz.time.matchesRule('between sunset and 22:15'))) 
        domoticz.log("2 matchesRule (true at night)       : " .. tostring(domoticz.time.matchesRule('between 22:15 and sunrise'))) 
        domoticz.log("3 matchesRule (true during day)     : " .. tostring(domoticz.time.matchesRule('between sunrise and 22:15'))) 
        domoticz.log("4 matchesRule (true)                : " .. tostring(domoticz.time.matchesRule('between 00:00 and 23:59'))) 
        domoticz.log("5 matchesRule (false 'Uppercase')   : " .. tostring(domoticz.time.matchesRule('Between 00:00 and 23:59'))) 

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jberinga
Posts: 67
Joined: Tuesday 11 August 2015 14:20
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: The Netherlands
Contact:

Re: domoticz.time issue for turning on lights

Post by jberinga »

Thanks! That seems to be it!

I will know for sure when the sun is set :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest