Ragdag wrote: Tuesday 21 April 2020 14:36
Would this be something that I put in each dzvents script or would this be a standalone script which I can call from the scripts I need it in.
For instance I have a simple Washing machine done script, how would I integrate it into that?
If you only use it in one or two script then I would integrate it into these scripts like attached.
But if you expect to use it in many scripts then I suggest to make it a dzVents
Shared helper function
Code: Select all
scriptVar = 'myPushover'
return
{
on =
{
timer =
{
'every 1 minutes',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
--level = domoticz.LOG_DEBUG,
marker = "Wasmachine"
},
data =
{
WasmachineTimeout = { initial = 1 },
WasmachineInUse = { initial = 0 },
},
execute = function(domoticz, item)
dz = domoticz
if item.isHTTPResponse then
dz.log(item.data,dz.LOG_DEBUG)
return
end
local function pushover(user, title, message, priority, sound)
dz.openURL({
url = 'https://api.pushover.net/1/messages.json',
method = 'POST',
callback = scriptVar,
postData =
{
token = user.token,
user = user.key,
message = message,
title = title or 'Pushover from dzVents',
priority = priority or 0,
sound = sound or 'echo',
},
})
end
local users =
{
['Jan'] = { ['token'] = 'a5mxxxxxxxxxxx', ['key'] = 'u1wxxxxxxxxxxxxxxxxxxx' },
['Piet'] = { ['token'] = 'a5myyyyyyyyyyyyyyy', ['key'] = 'u1wyyyyyyyyyyyyyyyyyy'},
['Joris'] = { ['token'] = 'a5mzzzzzzzzzzzzzz', ['key'] = 'u1w5zzzzzzzzzzzzzzzzzz'},
}
local WasmachineUsage = domoticz.devices(275)
local WasmachineStandbyUsage = 5.5
if (WasmachineUsage.actualWatt >= WasmachineStandbyUsage) then
if (domoticz.data.WasmachineInUse == 0) then
domoticz.data.WasmachineInUse = 1
-- domoticz.notify("Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "Nicky" , domoticz.NSS_PUSHOVER)
pushover(users.Jan, "Wasmachine aan", "De was wordt gestart.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT )
elseif (domoticz.data.WasmachineTimeout == 0) then
domoticz.data.WasmachineTimeout = 1
end
end
if (WasmachineUsage.actualWatt <= WasmachineStandbyUsage) and (domoticz.data.WasmachineInUse == 1) then
if (domoticz.data.WasmachineTimeout > 0) then
domoticz.data.WasmachineTimeout = domoticz.data.WasmachineTimeout - 1
elseif (domoticz.data.WasmachineTimeout == 0) then
domoticz.data.WasmachineInUse = 0
domoticz.data.WasmachineTimeout = 1
-- domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , domoticz.NSS_PUSHOVER)
pushover(users.Piet, "Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT )
domoticz.notify("Wasmachine klaar", "De was is klaar.", domoticz.PRIORITY_NORMAL, domoticz.SOUND_NONE, "" , domoticz.NSS_KODI)
end
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki