Time widget
Moderator: leecollings
- Dutchsea
- Posts: 120
- Joined: Tuesday 08 December 2015 13:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v2023.2
- Location: The Netherlands
- Contact:
Time widget
Hi,
Is there a widget for setting a (alarm) time similar to the setpoint widget?
Thanks.
Is there a widget for setting a (alarm) time similar to the setpoint widget?
Thanks.
Raspberry PI 3B on USB drive, Debian version: 12 (bookworm), Domoticz 2024.7
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Time widget
No. You can simulate one with a selector switchDutchsea wrote: Saturday 31 October 2020 14:21 Hi,
Is there a widget for setting a (alarm) time similar to the setpoint widget?
Thanks.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- Dutchsea
- Posts: 120
- Joined: Tuesday 08 December 2015 13:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v2023.2
- Location: The Netherlands
- Contact:
Re: Time widget
Right!
But there is probably there no possbility to have 2 selector buttons on the switch?
So I can make a 0 to 24h hour selector list and a 00 to 59 minute selector list?
Else i can only specify a limited number of "alarm times" in order not to make the list manageble.
Or is there a some other smarter way to similate a time with the selector switch?
But there is probably there no possbility to have 2 selector buttons on the switch?
So I can make a 0 to 24h hour selector list and a 00 to 59 minute selector list?
Else i can only specify a limited number of "alarm times" in order not to make the list manageble.
Or is there a some other smarter way to similate a time with the selector switch?
Raspberry PI 3B on USB drive, Debian version: 12 (bookworm), Domoticz 2024.7
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Time widget
You could try below script to set an Alarm time in a selector type switchDutchsea wrote: Saturday 31 October 2020 20:23 Or is there a some other smarter way to similate a time with the selector switch?
Code: Select all
--[[
dzvents script to use a selector type switch to set and display the set time
selector levels must be set and named to:
0 Off
10 + 4 hours
20 + 1 hour
30 + 10 minutes
40 + 1 minute
50 - 4 hours
60 - 1 hour
70 - 10 minutes
90 Alarm off
100 Choose
Off level must be set to "hided and for lay-out purposes best to set Selector Style to "select Menu"
The name of the selector switch should initially be set to: Alarm set for 08:00
]]
return
{
on =
{
devices =
{
689, -- id of your selector type switch with initial name "Alarm set for 08:00" The name will change to include the time set
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domotiocz.LOG_ERROR when all OK
marker = ' set alarmTime' ,
},
data =
{
alarmTime =
{
initial = 480,
},
},
execute = function(dz, item)
if item.levelName == 'Alarm off' then
item.rename('Alarm off')
item.switchSelector('Choose').afterSec(1) -- force display of new name
return
end
if item.levelName ~='Choose' then
local sign = 1
local multiplier = 60
-- minutes to hh:mm
local function timeFmt(min)
hours = string.format("%02.f", math.floor(min/60) )
minutes = string.format("%02.f", min - ( hours * 60 ) )
return hours .. ':' .. minutes
end
local setTimeMinutes
if item.name:match("%d+") == nil then
setTimeMinutes = dz.data.alarmTime
else
--get the time set in minutes
setTimeMinutes = tonumber(item.name:match("%d+")) * 60 + tonumber(item.name:match(":(%d+)"))
end
-- Plus or minus
if item.levelName:find('-') then
sign = -1
end
-- Hours, minutes or 10 minutes
if item.levelName:find('4') then
multiplier = 240
elseif item.levelName:find('10') then
multiplier = 10
elseif item.levelName:find('minute') then
multiplier = 1
end
-- new minutes
local newTimeMinutes = ( setTimeMinutes + ( multiplier * sign ) + 1440 ) % 1440
local newTime = timeFmt(newTimeMinutes)
item.rename('Alarm set for ' .. newTime)
item.switchSelector('Choose').afterSec(1) -- force display of new name
dz.data.alarmTime = newTimeMinutes
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- Dutchsea
- Posts: 120
- Joined: Tuesday 08 December 2015 13:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v2023.2
- Location: The Netherlands
- Contact:
Re: Time widget
Thanks, I also got this working after I removed the double quote at the start of the code.
I am just curious now; did you already create this code before or has it been made based on my specifc request?
I am just curious now; did you already create this code before or has it been made based on my specifc request?
Raspberry PI 3B on USB drive, Debian version: 12 (bookworm), Domoticz 2024.7
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
- Dutchsea
- Posts: 120
- Joined: Tuesday 08 December 2015 13:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v2023.2
- Location: The Netherlands
- Contact:
Re: Time widget
Also, how can I get the alarm time to be used as input for another (your) script that triggers the alarm actions?
I need the value of local variable 'newTime' to be used as input for the script "Alarm Clock".
I can't use .devices(idx).name as this name includes text (e.g. "Alarm set for 9:00") while the Alarm Clock scripts requires a time.
Should I create another Dummy that gets as input the value 'newTime' and use that Dummy as input (local alarmTime = ) for the Alarm Clock Script?
I need the value of local variable 'newTime' to be used as input for the script "Alarm Clock".
I can't use .devices(idx).name as this name includes text (e.g. "Alarm set for 9:00") while the Alarm Clock scripts requires a time.
Should I create another Dummy that gets as input the value 'newTime' and use that Dummy as input (local alarmTime = ) for the Alarm Clock Script?
Raspberry PI 3B on USB drive, Debian version: 12 (bookworm), Domoticz 2024.7
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Time widget
I wrote it because I wanted to find out if it could be a working and useful mechanism. So yes it was created triggered by your request.Dutchsea wrote: Monday 02 November 2020 19:22 I am just curious now; did you already create this code before or has it been made based on my specifc request?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Time widget
If you show me your script I will adjust it to use the selector. (using a similar mechanism as now in the set time script)Dutchsea wrote: Monday 02 November 2020 21:05 Also, how can I get the alarm time to be used as input for another (your) script that triggers the alarm actions?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- Dutchsea
- Posts: 120
- Joined: Tuesday 08 December 2015 13:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v2023.2
- Location: The Netherlands
- Contact:
Re: Time widget
waaren wrote: Monday 02 November 2020 21:22 I wrote it because I wanted to find out if it could be a working and useful mechanism. So yes it was created triggered by your request.![]()
Nice! Special thanks!
Raspberry PI 3B on USB drive, Debian version: 12 (bookworm), Domoticz 2024.7
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
- Dutchsea
- Posts: 120
- Joined: Tuesday 08 December 2015 13:22
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v2023.2
- Location: The Netherlands
- Contact:
Re: Time widget
Here you go:waaren wrote: Monday 02 November 2020 21:26 If you show me your script I will adjust it to use the selector. (using a similar mechanism as now in the set time script)
Code: Select all
-- Alarm clock [ dzVents >= 2.4 ]
scriptVar = '20191030 Alarmclock'
return
{ active = true,
on =
{
timer = { 'every hour' }, -- hourly run once to pick up target time
httpResponses = { scriptVar }, -- Trigger the handle Json part
},
logging = { level = domoticz.LOG_DEBUG },
execute = function(dz, item)
local alarmTime = dz.devices('Wekker').levelName
-- dz.log('Alarm time name is: ' .. dz.devices(145).name, dz.LOG_DEBUG) -- Name alarm time device with idx 145
if alarmTime ~= 'Off' then
local minutesIn24Hours = 24 * 60
local now = dz.time -- Get current time into time object
local Time = require('Time')
local targetTime = Time(dz.time.rawDate .. ' ' .. alarmTime .. ':00') -- Create target time object
local function triggerAlarm(delay)
local message = 'tring, trrring, trrring alarmclock ringing now. Was set on '.. dz.time.rawDate .. ', at ' .. dz.time.rawTime
local url = dz.settings['Domoticz url'] .. "/json.htm?type=command¶m=addlogmessage&message=" .. dz.utils.urlEncode(message)
dz.openURL({ url = url, callback = scriptVar }).afterMin(math.floor(delay))
end
if not(item.isHTTPResponse) then
dz.log('Alarm time is set at : ' .. alarmTime)
local deltaMinutes = math.floor(now.compare(targetTime).minutes)
if now.compare(targetTime).compare < 1 then -- targetTime is in future
deltaMinutes = minutesIn24Hours - deltaMinutes
end
dz.log('Alarmactions will be triggered in ' .. deltaMinutes .. ' minutes' ,dz.LOG_DEBUG)
triggerAlarm(deltaMinutes)
else
-- do wakeup actions.. here
dz.log('wake up actions here....' ,dz.LOG_INFO)
dz.devices('Kachel badkamer').switchOn()
dz.devices('Kachel badkamer').switchOff().afterMin(15)
dz.openURL('http://192.xxx.xxx.xxx:5005/Slaapkamer/volume/10')
dz.openURL('http://192.xxx.xxx.xxx:5005/Slaapkamer/unmute')
dz.openURL('http://192.xxx.xxx.xxx:5005/Slaapkamer/favorite/ClassicFM')
dz.scenes('Awaken').switchOn()
end
end
end
}
Raspberry PI 3B on USB drive, Debian version: 12 (bookworm), Domoticz 2024.7
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
Aeon Z-Wave G5 stick, RFXCOM, Sonof Zigbee 3.0 Dongle plus E, Nefit Easy, Fritzbox, Buienradar, Sonos
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Time widget
I sent you a PM
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 0 guests