Hello everyone.
I would like to achieve something like this in domoticz:
I turn on the switch / socket and then a window pops up with a choice of time from 1h to 24h.
I set it and after the selected time the socket is turned off.
What's the matter: I have an online socket ready and sometimes I have to charge:
-car for a child - 8h,
-powerbank for headphones - 2h,
-toothbrush - 14h,
and more ..
Someone can guide me?
delayed shutdown and input user data pop-up window
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: delayed shutdown and input user data pop-up window
I don't think this is possible in standard domoticz.
You can do something that gets close to this by creating a virtual selector with the various labels (headphones, toothbrush, car, etc.. ) and use a script to power the socket for the set time based on the selector level chosen.
in dzVents it could look like below script
__________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________
Code: Select all
return
{
on =
{
devices =
{
'socketTimer', -- change to name of selector
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is clock
marker = 'socket timer',
},
execute = function(dz, item)
dz.log('Selector ' .. item.name .. ' set to ' .. item.levelName, dz.LOG_DEBUG)
if item.levelName ~= 'Off' then
local socket = dz.devices('socket') -- change to name of socket / switch
choices =
{ -- levelName set time in minutes
Toothbrush = 840,
Car = 480,
Powerbank = 120,
}
if choices[item.levelName] then
socket.switchOn()
socket.switchOff().afterMin(item.levelName)
-- socket.switchOff().afterSec(choices[item.levelName] / 30) -- Test only
else
dz.log(item.levelName ..' is unknown; no time set', dz.LOG_ERROR)
end
item.switchSelector('Off').afterSec(2).silent() -- reset selector
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
Re: delayed shutdown and input user data pop-up window
Thanks for the answer. I thought of creating as many switches as tasks, plugging them into one socket and that's it. But your solution is much more elegant.
I'm just surprised that none of the scripts can use pop ups - maybe in the future
I'm getting to reading about dzVents and testing the script. Thanks.
Added:
Summarizing. I spent almost 2 hours learning it all. There is an error in the script:
It is: "afterMin (item.levelName)"
should be: "afterMin (choices [item.levelName])"
At least I learned something new. Thanks!
Added:
I changed your script a bit by moving the selector disable fragment right after socket.switchOff (). Now you can immediately see what is happening with the socket.
Can I know where you got the extra icons from?
I'm just surprised that none of the scripts can use pop ups - maybe in the future

I'm getting to reading about dzVents and testing the script. Thanks.

Added:
Summarizing. I spent almost 2 hours learning it all. There is an error in the script:
It is: "afterMin (item.levelName)"
should be: "afterMin (choices [item.levelName])"

At least I learned something new. Thanks!
Added:
I changed your script a bit by moving the selector disable fragment right after socket.switchOff (). Now you can immediately see what is happening with the socket.
Can I know where you got the extra icons from?
-
- Posts: 36
- Joined: Tuesday 13 August 2019 10:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: delayed shutdown and input user data pop-up window
hello waaren,waaren wrote: ↑Friday 05 February 2021 0:20 I don't think this is possible in standard domoticz.
You can do something that gets close to this by creating a virtual selector with the various labels (headphones, toothbrush, car, etc.. ) and use a script to power the socket for the set time based on the selector level chosen.
in dzVents it could look like below script
your idea is realy great. This is what I made out of it, but I got an error
Code: Select all
return {
on = {
devices = {'TimerTV_DG'}
},
logging = {level = domoticz.LOG_DEBUG,
marker = 'TV_DG_Timer',
},
execute = function(dz, item)
local tvdg = dz.devices('TV DG')
tvdg.cancelQueuedCommands()
if item.levelName ~= 'Off' then
choices =
{ 30Min = 30,
45Min = 45,
60Min = 60,
90Min = 90,
2h = 120,
3h = 240,
}
if choices[item.levelName] then
--tvdg.switchOn()
--tvdg.switchOff().afterMin(choices[item.levelName])
dz.log('TV im DG freigeschlatet für ' .. item.levelName)
else
--tvdg.switchOn()
dz.log('TV im DG freigeschlatet ohne Limit')
end
else
--tvdg.switchOff()
dz.log('TV im DG ausgeschaltet')
end
end
}
Code: Select all
2021-02-07 13:12:05.970 Error: dzVents: Error: (3.0.2) error loading module 'TV_DG_Timer' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/TV_DG_Timer.lua':
2021-02-07 13:12:05.970 ...moticz/scripts/dzVents/generated_scripts/TV_DG_Timer.lua:14: '}' expected near 'Min'
thx,
zavjah
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: delayed shutdown and input user data pop-up window
A variable or table key cannot start with a number in Lua (and dzVents = Lua)
A workaround is to force these table keys to be string literals using below syntax
Code: Select all
choices =
{
['30Min'] = 30,
['45Min'] = 45,
['60Min'] = 60,
['90Min'] = 90,
['2h'] = 120,
['3h'] = 240,
}
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 1 guest