Using TIME in dzvents

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

Moderator: leecollings

Post Reply
solarboy
Posts: 357
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Using TIME in dzvents

Post by solarboy »

I am just getting started with dzvents but still struggling with using time in my scripts.

Could someone point out to me where I am going wrong, I find the dzvents wiki quite hard to understand.

Code: Select all

return {
	on = {
		
		timer = { 'every 1 minutes'},
		
	},
	
	execute = function(domoticz,Item)
	
	local Time = require('Time')
	local now = Time()
	
	if now == '16:54'
	then domoticz.log('PASSED TEST', domoticz.LOG_ERROR)
	    print(now)
    else 
        domoticz.log('FAILTEST', domoticz.LOG_ERROR)
        print(now)
	    end
	

	end
}
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
solarboy
Posts: 357
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Using TIME in dzvents

Post by solarboy »

Basically I am trying to recreate what in Blockly would be

Code: Select all

If TIME = 16:55 then ......
I have tried quite a few variations and still no luck.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
solarboy
Posts: 357
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Using TIME in dzvents

Post by solarboy »

For example this

Code: Select all

return {
	on = {
		
		timer = { 'every 1 minutes'},
		
	},
	
	execute = function(domoticz,Item)
	
	
	if domoticz.time() == '17:27'
	then domoticz.log('PASSED TEST2', domoticz.LOG_FORCE)
	    end
	

	end
}
Obviously I am missing something.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Using TIME in dzvents

Post by waltervl »

Use

Code: Select all

timer = { 'at 17:27' },
To start something at 17:27

For testing be sure you set a time > 2 minutes after current time. Else Domoticz will probably not be triggered as timers are stored every minute.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Using TIME in dzvents

Post by waltervl »

Tip: to switch something simple on/off use the standard timer function, see wiki https://www.domoticz.com/wiki/Managing_ ... ice_Timers
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
solarboy
Posts: 357
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Using TIME in dzvents

Post by solarboy »

Thanks for the response :mrgreen: . I am using virtual switches as timer devices for now,and calling them as devices...
if dz.device('My virtual switch').state == 'On'
then...
I just thought there might be another way.
So I guess with your first suggestion, I would add

Code: Select all

timer = { 'at 17:27' }
as my trigger, and then capture the triggered that as an item which triggered the script in the execute/function part.

Code: Select all

if item.trigger('at 17:27') -- ??
Sometimes I would like to have various timers in one script that can be individually referenced in the function.

Seems quite a complex way of working with time in a function.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
solarboy
Posts: 357
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Using TIME in dzvents

Post by solarboy »

For example. I often would like a script such as.

Code: Select all

If switch1 ==  'On' and time == '17:57'
then switch 2.switchOn()
elseif switch1 == 'On' and time == '23:00'
then switch3.switchOn()
end
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Using TIME in dzvents

Post by waltervl »

You can use the matchesRule(rule) function for this eg.

If switch1 == 'On' and domoticz.time.matchesRule(' at 17:27') then
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
solarboy
Posts: 357
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

Re: Using TIME in dzvents

Post by solarboy »

That's exactly what I was looking for ! Thank you so much !
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest