how i can launch an script in dzvents depending on the proximity at xx:15 or xx:45 hours for listen weather news

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

Moderator: leecollings

Post Reply
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

how i can launch an script in dzvents depending on the proximity at xx:15 or xx:45 hours for listen weather news

Post by kitopopo »

Dear friends an dear @waaren,

In my city they broadcast the weather information on the radio every hour at xx: 15 minutes and at xx: 45. I would like to make a script that when I press a button that calculates if I am closer to xx: 15 or if I am closer to xx: 45 at the time of pressing the button depending on the proximity at one hour or another hour then that my home cinema is turned on for 2 minutes to reproduce the time information (this last part is clear to me) the most difficult thing is to compare the current time with respect to xx: 15 minutes or xx: 45 minutes and schedule the launch. For example, if I press the button at 11:05 am, since I am closer to 11:15, then the script is launched at 11:15. but instead if I press the button at 11:31 min, as I am closer to 11:45, the script is launched at 11:45. I've been trying for a long time but I can't. thanks in advance, best regards.
mgugu
Posts: 218
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: how i can launch an script in dzvents depending on the proximity at xx:15 or xx:45 hours for listen weather news

Post by mgugu »

Maybe something like that.
In the pushbutton event :
local nowMin = domoticz.time.minutes
if nowMin < 15 then
domoticz.devices('homecinema').active().afterMin(15- nowMin)
elseif nowMin >= 15 and nowMin < 45 then
domoticz.devices('homecinema').active().afterMin(45- nowMin)
elseif nowMin >= 45 and nowMin < 0 then
domoticz.devices('homecinema').active().afterMin(60- nowMin + 15)
end
Create the switch 'homecinema' which launch your home cinema code
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how i can launch an script in dzvents depending on the proximity at xx:15 or xx:45 hours for listen weather news

Post by kitopopo »

mgugu wrote: Wednesday 14 July 2021 16:10 Maybe something like that.
In the pushbutton event :
local nowMin = domoticz.time.minutes
if nowMin < 15 then
domoticz.devices('homecinema').active().afterMin(15- nowMin)
elseif nowMin >= 15 and nowMin < 45 then
domoticz.devices('homecinema').active().afterMin(45- nowMin)
elseif nowMin >= 45 and nowMin < 0 then
domoticz.devices('homecinema').active().afterMin(60- nowMin + 15)
end
Create the switch 'homecinema' which launch your home cinema code
Ohh yeah, works perfectly. The mathematical operation was ingenious for me, it had never occurred to me. Difficult for me but easy for others. Thank you very much, kind regards
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how i can launch an script in dzvents depending on the proximity at xx:15 or xx:45 hours for listen weather news

Post by kitopopo »

mgugu wrote: Wednesday 14 July 2021 16:10 Maybe something like that.
In the pushbutton event :
local nowMin = domoticz.time.minutes
if nowMin < 15 then
domoticz.devices('homecinema').active().afterMin(15- nowMin)
elseif nowMin >= 15 and nowMin < 45 then
domoticz.devices('homecinema').active().afterMin(45- nowMin)
elseif nowMin >= 45 and nowMin < 0 then
domoticz.devices('homecinema').active().afterMin(60- nowMin + 15)
end
Create the switch 'homecinema' which launch your home cinema code
Hello again dear friend @mgugu,

I think I have found a problem in the script. The problem is the seconds. If I activate the script with a push button at 14h:05':50'', the whole script is delayed until 14h15'50'' . As it starts 50 seconds late, I have already lost all the weather information. the script should start the script at 14h:05'00'' '', can you think of a way to solve it? Thanks for your collaboration and thanks in advance, kind regards
mgugu
Posts: 218
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: how i can launch an script in dzvents depending on the proximity at xx:15 or xx:45 hours for listen weather news

Post by mgugu »

Simplest way is to substract 1 minute to the delays to be sure the homecinema starts before:
local nowMin = domoticz.time.minutes
if nowMin < 15 then
domoticz.devices('homecinema').switchOn().afterMin(math.max(15- nowMin - 1 , 0))
elseif nowMin >= 15 and nowMin < 45 then
domoticz.devices('homecinema').switchOn().afterMin(math.max(45- nowMin - 1 , 0))
elseif nowMin >= 45 and nowMin < 0 then
domoticz.devices('homecinema').switchOn().afterMin(math.max(60- nowMin + 15 - 1, 0))
end
With a force delay to be positive.
Also changed active() to switchOn()
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest