Page 1 of 4

dzVents 1.1.1

Posted: Monday 04 July 2016 21:12
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.

Re: dzVents 1.1.1

Posted: Tuesday 05 July 2016 12:36
by elmortero
Nice!

I will give it a try tonight.

Re: dzVents 1.1.1

Posted: Friday 08 July 2016 14:58
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.

Re: dzVents 1.1.1

Posted: Friday 08 July 2016 15:00
by dannybloe
good idea :)

Re: dzVents 1.1.1

Posted: Monday 11 July 2016 18:34
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.

Re: dzVents 1.1.1

Posted: Tuesday 12 July 2016 8:17
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... ;-) )

Re: dzVents 1.1.1

Posted: Tuesday 12 July 2016 12:08
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

Re: dzVents 1.1.1

Posted: Tuesday 12 July 2016 12:11
by dannybloe
I'll try to implement it today or so. Shouldn't be too hard.

Re: dzVents 1.1.1

Posted: Tuesday 12 July 2016 21:19
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.

Re: dzVents 1.1.1

Posted: Wednesday 13 July 2016 22:29
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...

Re: dzVents 1.1.1

Posted: Thursday 14 July 2016 19:03
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)

Re: dzVents 1.1.1

Posted: Friday 15 July 2016 1:17
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?

Re: dzVents 1.1.1

Posted: Friday 15 July 2016 7:12
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: -----------------------------------------------------

Re: dzVents 1.1.1

Posted: Friday 15 July 2016 8:12
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.

Re: dzVents 1.1.1

Posted: Friday 15 July 2016 8:17
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.

Re: dzVents 1.1.1

Posted: Friday 15 July 2016 8:37
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 :)

Re: dzVents 1.1.1

Posted: Friday 15 July 2016 8:40
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: )

Re: dzVents 1.1.1

Posted: Monday 18 July 2016 14:27
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

Re: dzVents 1.1.1

Posted: Monday 18 July 2016 14:28
by dannybloe
Well, it swallows that specific error. Did you check the logs because when it does I print a message.

Re: dzVents 1.1.1

Posted: Tuesday 19 July 2016 13:57
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?