dzVents 1.1.1

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

fergalom
Posts: 74
Joined: Thursday 24 September 2015 11:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents 1.1.1

Post 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)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.1.1

Post 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?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
fergalom
Posts: 74
Joined: Thursday 24 September 2015 11:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents 1.1.1

Post 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
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.1.1

Post by dannybloe »

Can you try to remove the data file for this script? It is in scripts/storage/__data_<scriptname>.lua
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
fergalom
Posts: 74
Joined: Thursday 24 September 2015 11:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents 1.1.1

Post by fergalom »

thats sorted it, thank you
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.1.1

Post by dannybloe »

Did you change the variable alarmState at some point?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
fergalom
Posts: 74
Joined: Thursday 24 September 2015 11:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents 1.1.1

Post by fergalom »

No, I don't believe I did.
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: dzVents 1.1.1

Post 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 ?
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.1.1

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: dzVents 1.1.1

Post 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
Image

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))}
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.1.1

Post 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
Image

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).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Neutrino
Posts: 21
Joined: Sunday 08 May 2016 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: France
Contact:

Re: dzVents 1.1.1

Post 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().
dakipro
Posts: 49
Joined: Thursday 17 December 2015 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Norway
Contact:

Re: dzVents 1.1.1

Post 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 :)
Raspberry Pi 2 B - MySensors (dimmers, switches, motion, temperature, lux, humidity sensors)
zWave (220v switches)
various 433 via RFLink
dhanjel
Posts: 102
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Re: dzVents 1.1.1

Post 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)
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: dzVents 1.1.1

Post 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?
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
dhanjel
Posts: 102
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Re: dzVents 1.1.1

Post 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?

Image

Image

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 :)
jkimmel
Posts: 129
Joined: Monday 25 November 2013 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Mallorca
Contact:

Re: dzVents 1.1.1

Post 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

Code: Select all

permission denied
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.
Rfxcom
Raspi 4
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: dzVents 1.1.1

Post 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: ===================================================== 
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.1.1

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents 1.1.1

Post 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".
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest