Page 5 of 7

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 13:46
by dhanjel
ah yes, must be this one, right?

Code: Select all

2016-06-16 13:45:09.426 LUA: =====================================================
2016-06-16 13:45:09.426 LUA: >>> Handler: virtualdevice_wiiu
2016-06-16 13:45:09.426 LUA: .....................................................
2016-06-16 13:45:10.374 Error: EventSystem: Warning!, lua script /home/daniel/domoticz/scripts/lua/script_time_main.lua has been running for more than 10 seconds
2016-06-16 13:45:12.434 LUA: .....................................................
2016-06-16 13:45:12.434 LUA: <<< Done
2016-06-16 13:45:12.434 LUA: -----------------------------------------------------

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 13:48
by dannybloe
Well, that script takes 3 seconds. So there must be more. Btw, 3 seconds is enormous, time-wise. What are you doing in that script?

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 14:00
by dhanjel
did a ping to check if a device was online, but did not have a timeout. added a 1s timeout and it seems to work.
is the 10 s limit for all scripts in total, or one separate script?

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 14:02
by dannybloe
Well, there is a hardware plugin for this. Use that to set the state of a switch and link a script to that switch.

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 14:10
by dhanjel
Really, which one? You learn something new every day :)

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 14:19
by dannybloe
System Alive Checker. It creates switches for devices that you want to ping. What I would do is create a dzVents script using a persistent variable that counts consecutive ping timeouts and only when there have been a couple in a row perform some action.

System Alive Checker > $hiddenMyDevice > dzVents script > counter > myDevice.switchOn/Off

Something like that. Thing is that sometimes you get an occasional time-out while the device is still online. By counting consecutive timeouts you can prevent false negatives.

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 15:44
by dhanjel
dannybloe wrote:System Alive Checker. It creates switches for devices that you want to ping. What I would do is create a dzVents script using a persistent variable that counts consecutive ping timeouts and only when there have been a couple in a row perform some action.

System Alive Checker > $hiddenMyDevice > dzVents script > counter > myDevice.switchOn/Off

Something like that. Thing is that sometimes you get an occasional time-out while the device is still online. By counting consecutive timeouts you can prevent false negatives.
the ping device does not seem to end up in devices.lua (I deleted the file and checked in the recreated file, and it is not there)

Code: Select all

{
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "On",
         "Description" : "",
         "Favorite" : 0,
         "HardwareID" : 6,
         "HardwareName" : "System Alive Checker",
         "HardwareType" : "System Alive Checker (Ping)",
         "HardwareTypeVal" : 51,
         "HaveDimmer" : true,
         "HaveGroupCmd" : true,
         "HaveTimeout" : false,
         "ID" : "0000003",
         "Image" : "Light",
         "IsSubDevice" : false,
         "LastUpdate" : "2016-06-16 15:21:37",
         "Level" : 0,
         "LevelInt" : 0,
         "MaxDimLevel" : 15,
         "Name" : "Vardagsrum, Sony TV Ping",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "On",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "AC",
         "SwitchType" : "On/Off",
         "SwitchTypeVal" : 0,
         "Timers" : "false",
         "Type" : "Lighting 2",
         "TypeImg" : "lightbulb",
         "Unit" : 1,
         "Used" : 0,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "214"
      }

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 15:49
by dannybloe
Are you sure? That file is the direct result of getting the device information from Domoticz. If you do a manual fetch you see the same data.
What do you see when you do: http://..../json.htm?type=devices&displayhidden=1&filter=all&used=true

But, what do you get when you do domoticz.devices['Vardagsrum, Sony TV Ping'] or [214]. Isn't that enough to be useful?

Re: dzVents 1.0 released

Posted: Friday 17 June 2016 13:46
by blackdog65
Hi guys,
I'm new to dzVents and finding it easier than trying to learn "lua full fat" :D

I have a question Ref. sounds for example domoticz.SOUND_SIREN seems like a simple enough request/command but what siren? Where is it? :?

I have 4 Siemens mp3 doorbells in my house each with 10 sounds that can be triggered by Domoticz (including siren) these chimes work as a switch... pretty straight forward, but what are the dzVents sounds all about?

Many thanks
Sean

PS calling all 4 of my sirens with "Siren*" is so much easier than calling all 4 separately :D

Re: dzVents 1.0 released

Posted: Friday 17 June 2016 13:54
by dannybloe
Good question, I really have no idea ;-)
These are notify() options. Someone added them.

Re: dzVents 1.0 released

Posted: Friday 17 June 2016 14:12
by blackdog65
:lol: I like your honesty :lol:

I'll dig a little deeper into the code as it may be possible to modify either the code or my sounders to meet in the middle :D

Thanks for the quick reply Danny

Sean

Re: dzVents 1.0 released

Posted: Friday 17 June 2016 23:00
by jmleglise
Hi,

I wonder if Dzvents can manage the execution of a lua script 30 seconds after an execution of a first script ? Here is my need :

Code: Select all

First script triggered by a PIR
- check some uservariables and conditions
- VocalSynthesis "Domoticz will sound the Alarm in 30 seconds. You have 30 seconds to disarm it."

2nd script: 30 seconds after
- check some uservariables and conditions 
- trigger some switchs
Regards ,

Re: dzVents 1.0 released

Posted: Saturday 18 June 2016 10:33
by NetEye
Dear Danny,
I' am impressed, maybe you can help cq coache me with my topic? ( 8e onder die van jou: Lua script for pressure sensor).
Groet

Re: dzVents 1.0 released

Posted: Sunday 19 June 2016 15:36
by dannybloe
jmleglise wrote:Hi,

I wonder if Dzvents can manage the execution of a lua script 30 seconds after an execution of a first script ? Here is my need :

Code: Select all

First script triggered by a PIR
- check some uservariables and conditions
- VocalSynthesis "Domoticz will sound the Alarm in 30 seconds. You have 30 seconds to disarm it."

2nd script: 30 seconds after
- check some uservariables and conditions 
- trigger some switchs
Regards ,
Maybe something like this:

Code: Select all

return {
	active = true, -- set to true to activate this script
	on = {
		'pir',
		'disarmer', -- some switch that indicates the alarm is disarmed
		'alarmActivator' -- dummy switch
	},
	data = {
		triggerAlarm = { initial = false }
	},
	execute = function(domoticz, device)
		
		if (device.name == 'pir' and device.state == 'Motion') then

			domoticz.data.triggerAlarm = true
			domoticz.devices['alarmActivator'].switchOn().after_sec(30) -- will trigger this script after 30 seconds (hopefully)
			domoticz.sendCommand('') -- command for the vocal stuff

		elseif (device.name == 'disarmer') then

			domoticz.data.triggerAlarm = false
			domoticz.devices['alarmActivator'].switchOff()
			domoticz.devices['alarm'].switchOff()

		elseif (device.name == 'alarmActivor' and device.state == 'On' and domoticz.data.triggerAlarm) then

			domoticz.devices['alarm'].switchOn()
			domoticz.data.triggerAlarm = false
			-- do whatever 

		end
	end
}
I use the persistent variable triggerAlarm just to make sure that the after_sec() command isn't executed after all even if do you switchOff(). Maybe you don't need this extra check. I'm not sure. Of course the 'disarmer' switch represents whatever device reports that the alarm is turned off.

Update: fixed a typo in the script

Re: dzVents 1.0 released

Posted: Sunday 19 June 2016 23:05
by jmleglise
But of course !!! The script activates a switch 30 sec After, and detects the change of it , all this in the same script !
It's brilliant !

Thank you danny,

Re: dzVents 1.0 released

Posted: Monday 20 June 2016 10:45
by Eduard
Atmosphere wrote:
dannybloe wrote:
Did you find anything yet?
Hi Danny, It's still happening...

Code: Select all

 2016-06-06 03:40:03.465 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:445: attempt to index local 'device' (a nil value)
2016-06-06 05:25:02.595 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:445: attempt to index local 'device' (a nil value)
2016-06-06 10:55:03.267 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:445: attempt to index local 'device' (a nil value)
2016-06-06 14:35:03.204 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:445: attempt to index local 'device' (a nil value)
2016-06-06 17:25:03.270 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:445: attempt to index local 'device' (a nil value) 
I have the same issues:

Code: Select all

2016-06-12 08:30:01.682  LUA: devices.lua cannot be loaded
2016-06-12 08:30:01.682  LUA: error loading module 'devices' from file '/home/pi/domoticz/scripts/lua/devices.lua':
	/home/pi/domoticz/scripts/lua/devices.lua:5604: unfinished string near <eof>
2016-06-12 08:30:01.732  Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/dzVents/Domoticz.lua:446: attempt to index local 'device' (a nil value)
Looks like at some point that the http-fetch was not successful and created an empty devices.lua. Parsing the devices into the array will give an error then.
Maybe add a check to see if the devices.lua is empty before trying to parse the data...

Re: dzVents 1.0 released

Posted: Monday 20 June 2016 19:52
by elmortero
Hi Danny,

I am loving dzvents, all my switches have already been migrated to it.
Now I started to try and migrate some other scripts but I am a bit lost.
In this one case I want to get the humidity value from a (physical) sensor named soil1 and write it to a virtual sensor, called humsoil 1 with id 340.

Until now I read it from the sensor and wrote it to the virtual sensor by updating it using json.
Have been trying for some hours to try to get it in dzvents but without luck.

This is the original (in non-magical LUA):

Code: Select all

	bodem = 'soil1'
	domoticzserver = 'http://192.168.1.6:8080'

	smoistsensorTemp, smoistsensorHumidity = otherdevices_svalues[bodem]:match("([^;]+);([^;]+);([^;]+)")
	smoistsensorHumidity = tonumber(smoistsensorHumidity);
	print("xt300: Humidity soil1  is " .. smoistsensorHumidity .. " ");

    commandArray['OpenURL'] = domoticzserver .. '/json.htm?type=command&param=udevice&idx=340&nvalue=' .. smoistsensorHumidity
Can you help me get started please?

Re: dzVents 1.0 released

Posted: Monday 20 June 2016 20:22
by dannybloe
elmortero wrote:Hi Danny,

I am loving dzvents, all my switches have already been migrated to it.
Now I started to try and migrate some other scripts but I am a bit lost.
In this one case I want to get the humidity value from a (physical) sensor named soil1 and write it to a virtual sensor, called humsoil 1 with id 340.

Until now I read it from the sensor and wrote it to the virtual sensor by updating it using json.
Have been trying for some hours to try to get it in dzvents but without luck.

This is the original (in non-magical LUA):

Code: Select all

	bodem = 'soil1'
	domoticzserver = 'http://192.168.1.6:8080'

	smoistsensorTemp, smoistsensorHumidity = otherdevices_svalues[bodem]:match("([^;]+);([^;]+);([^;]+)")
	smoistsensorHumidity = tonumber(smoistsensorHumidity);
	print("xt300: Humidity soil1  is " .. smoistsensorHumidity .. " ");

    commandArray['OpenURL'] = domoticzserver .. '/json.htm?type=command&param=udevice&idx=340&nvalue=' .. smoistsensorHumidity
Can you help me get started please?
Have you tried this:

Code: Select all


	domoticz.devices[340].updateHumidity(smoistsensorHumidity, domoticz.HUM_NORMAL)

It should work.

Re: dzVents 1.0 released

Posted: Tuesday 21 June 2016 10:58
by elmortero
dannybloe wrote:

Code: Select all


	domoticz.devices[340].updateHumidity(smoistsensorHumidity, domoticz.HUM_NORMAL)

It should work.

It did! Works like a charm.
Thanks a lot.

Re: dzVents 1.0 released

Posted: Tuesday 21 June 2016 11:27
by dannybloe
Nice.
Read the docs ;)