Page 3 of 4
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 11:09
by fergalom
I've noticed an error repeating on my log related to dzvents lately - was previously working ok, running pretty much latest Domoticz 3.5454 and have tried upgrading but it does not solve, any ideas what the problem is?
Code: Select all
2016-08-10 10:05:00.547 LUA: =====================================================
2016-08-10 10:05:00.547 LUA: >>> Handler: spc_alarm
2016-08-10 10:05:00.547 LUA: .....................................................
2016-08-10 10:05:00.548 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_main.lua: /home/pi/domoticz/scripts/lua/dzVents/EventHelpers.lua:80: attempt to index local 'fileStorage' (a boolean value)
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 11:14
by dannybloe
fergalom wrote:I've noticed an error repeating on my log related to dzvents lately - was previously working ok, running pretty much latest Domoticz 3.5454 and have tried upgrading but it does not solve, any ideas what the problem is?
Code: Select all
2016-08-10 10:05:00.547 LUA: =====================================================
2016-08-10 10:05:00.547 LUA: >>> Handler: spc_alarm
2016-08-10 10:05:00.547 LUA: .....................................................
2016-08-10 10:05:00.548 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_main.lua: /home/pi/domoticz/scripts/lua/dzVents/EventHelpers.lua:80: attempt to index local 'fileStorage' (a boolean value)
Can paste the data section of this particular script?
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 11:28
by fergalom
here's the script
Code: Select all
return {
active = true ,
on = { 'timer' },
data = { alarmState = {initial=0} },
execute = function(domoticz)
local alarmTrigger = domoticz.devices['Alarm Triggered']
local switchCmd = 'Off'
-- local alarmState = 0
domoticz.variables.forEach(function(variable)
if (variable.value == 'alarm') then
switchCmd = 'On'
domoticz.data.alarmState = domoticz.data.alarmState + 1
end
end)
if (switchCmd == 'On' and alarmTrigger.state == 'Off') then
alarmTrigger.switchOn()
domoticz.notify('ALARM Triggered!!!!!', 'ALARM Triggered!!!!!!', domoticz.PRIORITY_EMERGENCY, SOUND_CLIMB)
elseif (alarmTrigger.state == 'On' and domoticz.data.alarmState == 0)then
-- only switchOff if it is not still alarming
alarmTrigger.switchOff()
end
print(domoticz.data.alarmState)
domoticz.variables.forEach(function(variable)
if (variable.value == 'alarm') then
domoticz.data.alarmState = domoticz.data.alarmState + 1
else
domoticz.data.alarmState = 0
end
end)
domoticz.variables.filter(function(device)
return (device.lastUpdate.minutesAgo < 5 and device.lastUpdate.minutesAgo > 2 and alarmTrigger.state == 'On')
end).forEach(function(zombie)
domoticz.notify('ALARM Triggered! - still Alarming', 'ALARM Triggered! - still Alarming', domoticz.PRIORITY_EMERGENCY, SOUND_CLIMB)
end)
end
}
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 11:33
by dannybloe
Can you try to remove the data file for this script? It is in scripts/storage/__data_<scriptname>.lua
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 11:54
by fergalom
thats sorted it, thank you
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 11:55
by dannybloe
Did you change the variable alarmState at some point?
Re: dzVents 1.1.1
Posted: Wednesday 10 August 2016 12:10
by fergalom
No, I don't believe I did.
Re: dzVents 1.1.1
Posted: Saturday 13 August 2016 9:40
by jmleglise
Hi danny,
I have a custom sensor "Lux" updated every 5 minutes. But this script is never triggered :
Code: Select all
return {
active = true,
on = { 'Lux'
...
Some more info here :
viewtopic.php?f=6&t=12628
What do you think about it ?
Re: dzVents 1.1.1
Posted: Saturday 13 August 2016 9:43
by dannybloe
Make sure you got the name of the device correct (as you can see it in the UI of Domoticz). You can also try the device id as listed in the devices tab in Domoticz.
Re: dzVents 1.1.1
Posted: Saturday 13 August 2016 11:16
by jmleglise
Sadly, no way to make a mistake in the name , with a 3 characters name ... 'Lux'
For the IDX, it may be written like this ?
Code: Select all
return {
active = true,
on = { 'Lux', 72
},
72 is my IDX
It doesn't work neither.
This Virtual sensor is updated in another Lua script with this line. (and of course it works).
commandArray[indexArray] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))}
Re: dzVents 1.1.1
Posted: Saturday 13 August 2016 11:58
by dannybloe
jmleglise wrote:Sadly, no way to make a mistake in the name , with a 3 characters name ... 'Lux'
For the IDX, it may be written like this ?
Code: Select all
return {
active = true,
on = { 'Lux', 72
},
72 is my IDX
It doesn't work neither.
This Virtual sensor is updated in another Lua script with this line. (and of course it works).
commandArray[indexArray] = {['UpdateDevice'] = idxLux..'|0|'..tostring(round(weightedLux,0))}
I don't know why that is. Maybe you can check in the script_device_main if there is a devicechanged for this sensor. Perhaps Domoticz doesn't trigger for a virtual lux device. I'm afraid you'll have to do some debugging here. If you dare you can turn on debug logging in dzVents settings. (And try the dev branch from github).
Re: dzVents 1.1.1
Posted: Saturday 20 August 2016 19:57
by Neutrino
Hi danybloe,
I just find a bug :
In the device methods, close() and open() functions do nothing.
It works when I use switchOn() instead of open() and switchOff() instead of close().
Re: dzVents 1.1.1
Posted: Wednesday 24 August 2016 22:45
by dakipro
Hi, i might have a suggestion (that was probably mentioned or "thought" about). I was just looking at the examples again (looking for inspiration

) and I noticed example that checks if a switch in gui is "on" or 'off" for the "is_active" part. from example "only run script when button pressed.lua"
Code: Select all
active = function(domoticz)
return (domoticz.devices['script_blabla'].state == 'On')
end,
I also noticed there is persistant storage now (awesome feature btw!), so I had an idea about combining it maybe in order to gain performance for "active" parameter by caching switch state?
F.eks. we would define which switches are "script controll", either by name or id, and then in the "active" logic it would be enought to read "is_active" state from the memory rather then checking for the devices all the time. When switch state changes, it is being re-read and cached again in persistant storage (and maybe cached every 30mins for synchronisation improvement).
But it could be that benefits are zero to none and it would just complicate functionality (not to mention falling out of sync etc...)
But just a thought

Re: dzVents 1.1.1
Posted: Sunday 28 August 2016 13:29
by dhanjel
Is it possible to add a feature to get response from OpenURL, like this?
Code: Select all
local response = domoticz.openURL("http://192.168.1.200:5005/Vardagsrum/state");
domoticz.log("URL Response: " .. response, domoticz.LOG_INFO);
maybe call it fetchURL?
I would like to simplify this case, and get rid of the dependency to JSON.lua in all scripts.
Code: Select all
local json = (loadfile "/home/daniel/domoticz/scripts/lua/JSON.lua")()
local sonos=assert(io.popen('curl http://192.168.1.200:5005/Vardagsrum/state'))
local status = sonos:read('*all')
sonos:close()
local jsonStatus = json:decode(status)
Re: dzVents 1.1.1
Posted: Thursday 03 November 2016 17:18
by Doler
Hello Danny,
I'm having trouble getting the right/current state of groups. When querying with
Code: Select all
domoticz.devices[group_name].state
I only get the state that is retrieved by the HTTP fetch (so it's only updated every half hour).
I looked into your code and got to the point that in the function updateGroupAndScenes in Domoticz.lua the state is correctly updated after a change (verified with "print(device.name .. device.state)" after device._setStateAttribute(state)).
So this looks right but nevertheless I cannot retrieve it in the way mentioned above. Could you take a look at this when the dust of your renovation works has settled?
Thanks, Mark
Edit: Discovered that the change in state is recorded in domoticz.groups[group_name].state and not in domoticz.devices as expected and suggested by documentation. So the question remains what the intention is: use domoticz.devices or domoticz.groups/scenes?
Re: dzVents 1.1.1
Posted: Sunday 06 November 2016 13:17
by dhanjel
I have issues with updating devices for some reason, and I cannot figure out why.
No errors appear at all. Have anyone else experienced anything similar?
Code: Select all
return {
active = true,
on = { ['timer'] = 'every minute' },
execute = function(domoticz)
-- Includes
local json = (loadfile "/home/daniel/domoticz/scripts/lua/JSON.lua")()
-- Device names
local sonos_player = 'Bathroom'
local device_main = 'Badrum, Sonos'
local device_trackinfo = 'Badrum, Sonos Playing'
local device_volume = 'Badrum, Sonos Volume'
-- Get status
local sonos=assert(io.popen('curl http://192.168.1.200:5005/' .. sonos_player .. '/state'))
local status = sonos:read('*all')
sonos:close()
local jsonStatus = json:decode(status)
local volume = tonumber(jsonStatus['volume'])
-- Set state
local playerstate = jsonStatus['playerState']
if (playerstate == nil)
then
playerstate = 'OFFLINE'
end
if (playerstate == 'PLAYING')
then
domoticz.devices[device_main].switchOn()
else
domoticz.devices[device_main].switchOff()
end
-- Set track
local trackInfo = jsonStatus['currentTrack']
local trackText = trackInfo['artist'] .. ' - ' .. trackInfo['title']
-- Update only when necessary to keep the history clean
local currentText = domoticz.devices[device_trackinfo].text
if (currentText ~= trackText)
then
domoticz.devices[device_trackinfo].updateText(trackText)
domoticz.log(sonos_player .. " old track: " .. currentText)
end
-- Set Volume
domoticz.devices[device_volume].dimTo(volume)
-- Debug output
domoticz.log(sonos_player .. " state: " .. playerstate, domoticz.LOG_INFO)
domoticz.log(sonos_player .. " track: " .. trackText, domoticz.LOG_INFO)
domoticz.log(sonos_player .. " volume: " .. volume, domoticz.LOG_INFO)
end
}
I´m hoping its just a stupid typo somewhere

Re: dzVents 1.1.1
Posted: Saturday 04 February 2017 22:36
by jkimmel
dannybloe wrote:Can you try to remove the data file for this script? It is in scripts/storage/__data_<scriptname>.lua
I can't open storage
Just sudo your way into it

Or chown the folder and it's contents (sudo chown root:pi -R path/to/storage/*
Or something like that.
Re: dzVents 1.1.1
Posted: Wednesday 01 March 2017 21:40
by jake
Is it possible that the '.after_sec(20) is not supported for all actions?
My code
Code: Select all
kodidevice.devices.kodiPlay().after_sec(5)
gives the following error in the log
Code: Select all
2017-03-01 21:36:53.353 LUA: Handling events for: "Kodi Woonkamer - Status", value: "Audio"
2017-03-01 21:36:53.353 LUA: =====================================================
2017-03-01 21:36:53.354 LUA: >>> Handler: kodi
2017-03-01 21:36:53.354 LUA: >>> Device: "Kodi Woonkamer - Status" Index: 146
2017-03-01 21:36:53.354 LUA: .....................................................
2017-03-01 21:37:01.891 LUA: An error occured when calling event handler kodi
2017-03-01 21:37:01.891 LUA: /home/pi/domoticz/scripts/lua/scripts/kodi.lua:25: attempt to index field 'devices' (a nil value)
2017-03-01 21:37:01.892 LUA: .....................................................
2017-03-01 21:37:01.892 LUA: <<< Done
2017-03-01 21:37:01.893 LUA: -----------------------------------------------------
2017-03-01 21:37:01.893 LUA: =====================================================
Re: dzVents 1.1.1
Posted: Wednesday 01 March 2017 22:02
by dannybloe
You can check this by trying it the traditional way (using command-array instructions).
Oh and please create a new topic in the dzVents forum.
Re: dzVents 1.1.1
Posted: Saturday 11 March 2017 11:30
by BakSeeDaa
dannybloe wrote:Good question

I think you can do it like this:
Code: Select all
domoticz.sendCommand('Security Panel', domoticz.SECURITY_ARMEDHOME)
Maybe you can check this then I can make a dedicated command like:
Code: Select all
domoticz.setSecurity(domoticz.SECURITY_ARMEDHOME)
Or something like that.
That won't work.
domoticz.sendCommand('Security Panel', 'Arm Home') would work though.
See:
https://www.domoticz.com/forum/viewtopi ... 785#p11075
The constants currently defined in Domoticz.lua can not be used to set the security panel status.
Code: Select all
['SECURITY_DISARMED'] = 'Disarmed',
['SECURITY_ARMEDAWAY'] = 'Armed Away',
['SECURITY_ARMEDHOME'] = 'Armed Home',
Consider adding the following constants
Code: Select all
['SET_SECURITY_DISARM'] = 'Disarm',
['SET_SECURITY_ARMAWAY'] = 'Arm Away',
['SET_SECURITY_ARMHOME'] = 'Arm Home',
Also note that the original constants can be used for comparing with globalvariables['Security']. It will not work for comparing with otherdevices['Security Panel'] which will return "Normal" instead of "Disarmed".