waaren wrote: ↑Saturday 06 June 2020 11:07
Ragdag wrote: ↑Saturday 06 June 2020 10:42
Is there a way to check a switches previous state to see if it actually toggled from off to on?
No
I'll probably need to work with persistent variable for the 3 switches
Yes persistent variables or use virtual devices in your script. In pseudo code something like:
Code: Select all
on =
{ actualswitches }
if virtualSwitch.state ~= actualSwitch.state then
virtualSwitch.toggleSwitch()
otherActions based on new state
else
noAction needed
end
Man as always you are fast
I went with the Persistant variables
could you do a sanity check of my code
Code: Select all
local scriptVar = 'FireAlarm'
return
{
on =
{
devices =
{
303, -- Schuur
320, -- Overloop
330, -- Zolder
}
},
data =
{
lastStateSchuur = { initial = '' },
lastStateOverloop = { initial = '' },
lastStateZolder = { initial = '' },
}, ,
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
if item.isHTTPResponse then
dz.log(item.data,dz.LOG_DEBUG)
return
end
local function pushover(PushoverUser, PushoverApp, title, message, priority, sound)
dz.openURL({
url = 'https://api.pushover.net/1/messages.json',
method = 'POST',
callback = scriptVar,
postData =
{
token = PushoverApp.token,
user = PushoverUser.key,
message = message,
title = title or 'Pushover from dzVents',
priority = priority or 0,
sound = sound or 'echo',
},
})
end
local PushoverUsers =
{
['User1'] = { ['key'] = 'aaa' },
['User2'] = { ['key'] = 'bbb'},
['Familie'] = { ['key'] = 'ccc'},
}
local PushoverApps =
{
['Domoticz'] = { ['token'] = 'ddd' },
['Huis'] = { ['token'] = 'eee' },
['Test'] = { ['token'] = 'fff' },
['Was'] = { ['token'] = 'ggg' },
['Alarm'] = { ['token'] = 'hhh' },
}
if item == dz.devices(303) then
if dz.devices(303).state ~= dz.data.lastStateSchuur then
item.alarmDevice = 336
item.alarmText = 'Schuur'
dz.log('Schuur current State: ' .. dz.devices(303).state, dz.LOG_DEBUG)
dz.log('Schuur previous State: ' .. dz.data.lastStateSchuur, dz.LOG_DEBUG)
dz.data.lastStateSchuur = dz.devices(303).state
else
dz.log('Nothing to do with Schuur', dz.LOG_DEBUG)
return
end
elseif item == dz.devices(320) then
if dz.devices(320).state ~= dz.data.lastStateOverloop then
item.alarmDevice = 326
item.alarmText = 'Overloop'
dz.log('Overloop current State: ' .. dz.devices(303).state, dz.LOG_DEBUG)
dz.log('Overloop previous State: ' .. dz.data.lastStateSchuur, dz.LOG_DEBUG)
dz.data.lastStateOverloop = dz.devices(320).state
else
dz.log('Nothing to do with Overloop', dz.LOG_DEBUG)
return
end
elseif item == dz.devices(330) then
if dz.devices(330).state ~= dz.data.lastStateZolder then
item.alarmDevice = 329
item.alarmText = 'Zolder'
dz.log('Zolder current State: ' .. dz.devices(303).state, dz.LOG_DEBUG)
dz.log('Zolder previous State: ' .. dz.data.lastStateSchuur, dz.LOG_DEBUG)
dz.data.lastStateZolder = dz.devices(330).state
else
dz.log('Nothing to do with Zolder', dz.LOG_DEBUG)
return
end
else
dz.log('Unknown device', dz.LOG_ERROR)
return
end
pushover(PushoverUsers.User1, PushoverApps.Alarm, 'Brand Alarm', 'Brand Alarm ' .. item.alarmText .. '\nStatus: ' .. dz.devices(item.alarmDevice).state, 1, 'siren' )
end
}