hello i have a problem with this event.
this is what i try to achieve.
when I turn off the lights in woonkamer in the evening between 22:30 and 1:00 o'clock
I want the lights to turn on in the slaapkamer for 20 minutes.
The problem is that once the 10 minutes are past, the lights in slaapkamer turn off and turn on again for 10 minutes in a loop till 1:00 o'clock
help would be appreciated.
how to do action once in period of time
Moderator: leecollings
Re: how to do action once in period of time
Hello dorzel,
I am suprised that the blockly does something at all. In my opinion there is a problem with the time statements. When it's 00:30h, it's not after 22:30h. The day ends after 23:59h and a new one starts at 00:00h.
But then there is this: time changes every minute. So when the lights in woonkamer are off and time is changing every minute, then every minute the statement would be true. Then when the lights in slaapkamer turn off after 10 minutes (you say you want it to be on for 20 minutes, but in blockly you put 10?), then a minute later it will turn on the light again as the condition is still true. So it will turn on the light in slaapkamer again.
When I want something only to happen once during a certain period of time, I use a variable. I set it default to 0. In the blockly I check the value of the variable and when it is 0, I let the blocky change it to 1. Then next time it checks the variable, it's not 0 anymore so it won't act. If the period of time ends at 01:00h, I would make another blockly that states: If time = 01:00 then set variable = 0.
I am suprised that the blockly does something at all. In my opinion there is a problem with the time statements. When it's 00:30h, it's not after 22:30h. The day ends after 23:59h and a new one starts at 00:00h.
But then there is this: time changes every minute. So when the lights in woonkamer are off and time is changing every minute, then every minute the statement would be true. Then when the lights in slaapkamer turn off after 10 minutes (you say you want it to be on for 20 minutes, but in blockly you put 10?), then a minute later it will turn on the light again as the condition is still true. So it will turn on the light in slaapkamer again.
When I want something only to happen once during a certain period of time, I use a variable. I set it default to 0. In the blockly I check the value of the variable and when it is 0, I let the blocky change it to 1. Then next time it checks the variable, it's not 0 anymore so it won't act. If the period of time ends at 01:00h, I would make another blockly that states: If time = 01:00 then set variable = 0.
Re: how to do action once in period of time
hi mrf68,
i mistaked the 20 minutes, and as the blocky shows it should be 10 minutes,.
you made a lot clear, this weekend i will try to make an new evend in blocky like you described.
thanks for your answer.
i mistaked the 20 minutes, and as the blocky shows it should be 10 minutes,.
you made a lot clear, this weekend i will try to make an new evend in blocky like you described.
thanks for your answer.
-
- Posts: 16
- Joined: Saturday 01 March 2014 18:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: how to do action once in period of time
Otherwise, use a simple lua script.
Verzonden vanaf mijn iPhone met Tapatalk
Verzonden vanaf mijn iPhone met Tapatalk
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: how to do action once in period of time
Assuming I have read your descriptiong correctly then, this untested Lua code would do what you want, you need to create a dummy switch called 'goneupstairs' which is set to 'Off' and has timer set to turn it 'Off' at 2:00 every day.
You need to either use the built in script editor choose, Lua, device and enable, or place this script in your Lua script directory.
Basically just a series of if statements, detect the switch being turned off, check its not a Sunday, check time is between 22:30 and 1.30, check goneupstairs is 'Off' only if all true then switch slaapkamer on for 20 minutes and turn goneupstairs 'On', so it won't happen again.
Your Blockly is going in the right direction, accepting comments above, and not possible to both greater than22 and less than 1, but I am not quite sure the logic would be as you expected as the way you have grouped things with ands, it is very difficult to see with Blockly which conditions will occur together, the code above separating out different concepts, days, minutes and switches would be easier to debug.
You need to either use the built in script editor choose, Lua, device and enable, or place this script in your Lua script directory.
Basically just a series of if statements, detect the switch being turned off, check its not a Sunday, check time is between 22:30 and 1.30, check goneupstairs is 'Off' only if all true then switch slaapkamer on for 20 minutes and turn goneupstairs 'On', so it won't happen again.
Code: Select all
-- /domoticz/scripts/lua/script_device_onceanight.lua
commandArray = {}
-- Only react when woonkamer is turned off
if (devicechanged['woonkamer'] == 'Off') then
-- Get time
time = os.date("*t")
-- Caculate current time in minutes
dayminutes = time.min + time.hour * 60
dm2230 = 30 + 22 * 60
-- Only react when time is between 22:30 and 1.30
if (dayminutes > dm2230) or (dayminutes < 90) then
wday = time.wday
-- Account for 00:00 - 01:30 on Sunday should be treated as Saturday night, not Sunday night
if (dayminutes < 90) then
if wday == 1 then
wday = 7
elseif wday = 2 then
wday = 1
end
end
-- Only react when it isn't a Sunday (wday = 1 on Sunday)
if wday > 1 then
-- Only react if goneupstairs is off
if (goneupstairs == 'Off') then
commandArray['slaapkamer'] = 'On FOR 20'
commandArray['goneupstairs'] = 'On'
print('Once a night')
print(time.year..' '..time.month..' '..time.day..' '..time.hour..' '..time.min)
end
end
end
end
return commandArray
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
Re: how to do action once in period of time
hello simonrg,
I'm fairly new to domoticz and I admire people who can write scripts.
I also understand that blockly has its limitations.
your script example will help me to understand this Lua script.
So my next project will be to learn writing scripts.
I will definitely try this script.
Thanks for your help.
I'm fairly new to domoticz and I admire people who can write scripts.
I also understand that blockly has its limitations.
your script example will help me to understand this Lua script.
So my next project will be to learn writing scripts.

I will definitely try this script.
Thanks for your help.
Who is online
Users browsing this forum: No registered users and 1 guest