dzVents 1.1.1

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

Moderator: leecollings

dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

dzVents 1.1.1

Post by dannybloe »

For those interested. I just released version 1.1.1 of dzVents with a couple of fixes and additions:

[1.1.1]
  • Added support for a devices table in the 'on' section.
  • Added extra log level for only showing information about the execution of a script module.
  • Added example script for System-alive checker notifications (preventing false negatives).
[1.1]
  • Added example script for controlling the temperature in a room with hysteresis control.
  • Fixed updateLux (thanks to neutrino)
  • Added Kodi commands to the device methods.
  • Fixed updateCounter
  • Added counterToday and counterTotal attributes for counter devices. Only available when http fetching is enabled.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: dzVents 1.1.1

Post by elmortero »

Nice!

I will give it a try tonight.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: dzVents 1.1.1

Post by EddyG »

Just a thought.
Might it be an idea to have a variable setting(s) in dzVents_setting.lua for alternative paths for the http fetch file and the storage files?
I then could put them on a tmpfs. It prevents the sd-card for too many writes.
I already optimized my whole system this way.
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 »

good idea :)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: dzVents 1.1.1

Post by Eduard »

Very nice! Thanks for all the good work.

One thing that's bothering me is that i stil have issues when the httpdata is fetched. I think it has to do with the great amount of devices i have that fetching them via the httprequest is taking a long time.
It might be an issue that the script whats to acces the devices.lua file while it is still being created by the httprequest.

Errors:

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:452: attempt to index local 'device' (a nil value)

Code: Select all

LUA: devices.lua cannot be loaded
LUA: error loading module 'devices' from file '/home/pi/domoticz/scripts/lua/devices.lua':
/home/pi/domoticz/scripts/lua/devices.lua:2065: unexpected symbol near
Maybe it is a good idea to fetch the devices to a tempfile and then rename it after is has finished. In that case the (previous) devices.lua is still available for the script to read, while being fetched at the same time.
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 »

Yes, I have noticed that too. I will try to implement such a scheme.
Hopefully we can get by the need for this http stuff really soon. I see it as a temporary thing (/me looks at giz... ;-) )
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: dzVents 1.1.1

Post by elmortero »

Errors:

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:452: attempt to index local 'device' (a nil value)

Code: Select all

LUA: devices.lua cannot be loaded
LUA: error loading module 'devices' from file '/home/pi/domoticz/scripts/lua/devices.lua':
/home/pi/domoticz/scripts/lua/devices.lua:2065: unexpected symbol near
Maybe it is a good idea to fetch the devices to a tempfile and then rename it after is has finished. In that case the (previous) devices.lua is still available for the script to read, while being fetched at the same time.[/quote]

I noticed these too, but usually (cannot say with 100% certainty) they happen on the hour xx:00, which coincides with the hourly backup. So I figured that the file is for a brief moment not accesible and thus causing the error
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 »

I'll try to implement it today or so. Shouldn't be too hard.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

I added support for this in the dev branch. Can you please test it? It now uses a tmp file first when downloading the json and only when it is done writing it copies it over to devices.lua.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: dzVents 1.1.1

Post by Eduard »

dannybloe wrote:I added support for this in the dev branch. Can you please test it? It now uses a tmp file first when downloading the json and only when it is done writing it copies it over to devices.lua.
Thanks! Seems to work. Not getting errors until now. Will continue to test the next days...
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: dzVents 1.1.1

Post by Eduard »

:shock:
Still getting issues with the dev-branch ;(

Code: Select all

2016-07-14 08:00:02.578 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:452: attempt to index local 'device' (a nil value)
velkrosmaak
Posts: 8
Joined: Friday 15 April 2016 23:45
Target OS: Linux
Domoticz version:
Contact:

Re: dzVents 1.1.1

Post by velkrosmaak »

Is there a beginners tutorial for dzVents anywhere? It looks so useful, but I've no idea how to get started. I've read the wiki, but I'm still stuck on how to get started. Any guidance for a LUA newb?
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 »

Not completely sure it is related to 1.1.1, but setting the level on a selector switch does not work anymore.
(Domoticz 3.5290)

No errors, and nothing happens. This script used to work before.

Code: Select all

return  {
  active = true,
  on = { ['timer'] = 'every minute' }, 
  execute = function(domoticz)            
    
        local json = (loadfile "/home/daniel/domoticz/scripts/lua/JSON.lua")()

        local sonos=assert(io.popen('curl http://192.168.1.200:5005/Altan/state'))
        local sonos_name = 'Utomhus, Sonos'

        local status = sonos:read('*all')
        sonos:close()
        local jsonStatus = json:decode(status)
        
        playerstate = jsonStatus['playerState']
        if (playerstate == nil)
        then
            playerstate = 'OFFLINE'
        end

        if (playerstate == 'PLAYING')
        then
            domoticz.devices[sonos_name].level = 10
        elseif (playerstate == 'PAUSED_PLAYBACK')
        then
            domoticz.devices[sonos_name].level = 20
        else
            domoticz.devices[sonos_name].level = 0    
        end

        domoticz.log(sonos_name .. " state:" .. playerstate, domoticz.LOG_INFO)
    
  end
}

Code: Select all

2016-07-15 07:09:00.439 LUA: =====================================================
2016-07-15 07:09:00.439 LUA: >>> Handler: sonos_patio
2016-07-15 07:09:00.439 LUA: .....................................................
2016-07-15 07:09:00.453 LUA: Utomhus, Sonos state:PLAYING
2016-07-15 07:09:00.453 LUA: .....................................................
2016-07-15 07:09:00.453 LUA: <<< Done
2016-07-15 07:09:00.453 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 »

dhanjel wrote:Not completely sure it is related to 1.1.1, but setting the level on a selector switch does not work anymore.
(Domoticz 3.5290)

No errors, and nothing happens. This script used to work before.

Code: Select all

return  {
  active = true,
  on = { ['timer'] = 'every minute' }, 
  execute = function(domoticz)            
    
        local json = (loadfile "/home/daniel/domoticz/scripts/lua/JSON.lua")()

        local sonos=assert(io.popen('curl http://192.168.1.200:5005/Altan/state'))
        local sonos_name = 'Utomhus, Sonos'

        local status = sonos:read('*all')
        sonos:close()
        local jsonStatus = json:decode(status)
        
        playerstate = jsonStatus['playerState']
        if (playerstate == nil)
        then
            playerstate = 'OFFLINE'
        end

        if (playerstate == 'PLAYING')
        then
            domoticz.devices[sonos_name].level = 10
        elseif (playerstate == 'PAUSED_PLAYBACK')
        then
            domoticz.devices[sonos_name].level = 20
        else
            domoticz.devices[sonos_name].level = 0    
        end

        domoticz.log(sonos_name .. " state:" .. playerstate, domoticz.LOG_INFO)
    
  end
}

Code: Select all

2016-07-15 07:09:00.439 LUA: =====================================================
2016-07-15 07:09:00.439 LUA: >>> Handler: sonos_patio
2016-07-15 07:09:00.439 LUA: .....................................................
2016-07-15 07:09:00.453 LUA: Utomhus, Sonos state:PLAYING
2016-07-15 07:09:00.453 LUA: .....................................................
2016-07-15 07:09:00.453 LUA: <<< Done
2016-07-15 07:09:00.453 LUA: -----------------------------------------------------
I think it is because you are not using any of the update methods on a device :). You cannot do device.level=xxx. In your case you could use the switchSelector(level) command or the dimTo(level) command. Both result in a 'Set Level xxx' that is sent to domoticz.

Lemme know if that works for you.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

velkrosmaak wrote:Is there a beginners tutorial for dzVents anywhere? It looks so useful, but I've no idea how to get started. I've read the wiki, but I'm still stuck on how to get started. Any guidance for a LUA newb?
Are you talking about a tutorial for Domoticz events in general or using dzVents? For the latter, if you follow the installation instructions you are about 80% done ;-).
Then it's just a matter of creating one or more script files in the scripts/lua/scripts folder. There are a couple of examples in the dzVents folder that may get you started.

So assuming you have Domoticz up and running, got at least one switch (or a dummy switch) created and you installed dzVents to the proper location you can look at dzVents/examples/respond to switch.lua. That's a simple script that will respond to a switch being turned on. Oh, and it sends a notification so you may have to configure that in Domoticz as well.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

dannybloe wrote: I think it is because you are not using any of the update methods on a device :). You cannot do device.level=xxx. In your case you could use the switchSelector(level) command or the dimTo(level) command. Both result in a 'Set Level xxx' that is sent to domoticz.

Lemme know if that works for you.
Works perfectly fine, missed that method (switchSelector) when reading the docs. I´m a .net developer, so that kind of justifies that I tried to set a property in that way :)
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 »

dhanjel wrote:
dannybloe wrote: I think it is because you are not using any of the update methods on a device :). You cannot do device.level=xxx. In your case you could use the switchSelector(level) command or the dimTo(level) command. Both result in a 'Set Level xxx' that is sent to domoticz.

Lemme know if that works for you.
Works perfectly fine, missed that method (switchSelector) when reading the docs. I´m a .net developer, so that kind of justifies that I tried to set a property in that way :)
Yeah, I don't think Lua supports this kind of attribute manipulation. (If it does, I'm not gonna change it anymore anyway :lol: )
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: dzVents 1.1.1

Post by Eduard »

Eduard wrote::shock:
Still getting issues with the dev-branch ;(

Code: Select all

2016-07-14 08:00:02.578 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:452: attempt to index local 'device' (a nil value)
Latest dev-branch is error-free now for the last couple of days :D
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 »

Well, it swallows that specific error. Did you check the logs because when it does I print a message.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

Forgive me If I have missed something, but is it possible to set the security state of the house/system from the scripts?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest