Introducing dzVents - Domoticz Lua file based event scripting made e-z!

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

Moderator: leecollings

Locked
jimphelps
Posts: 2
Joined: Friday 08 April 2016 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by jimphelps »

Hi,
i've got a problem with Time:

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_main.lua: /home/pi/domoticz/scripts/lua/event_helpers.lua:179: attempt to call global 'getDayOfWeek' (a nil value)
It happens at domoticz start and every minute when a script like "schedule fish pond pump.lua" (based on day of week) is active:

Code: Select all

return {
	active = true,
	on = {
		['timer'] = {
			'at 8:30 on mon,tue,wed,thu,fri'
		}
	},
	...
	
Other "every minute" scripts are working well...
Does somone have an idea?
thanks
Jim
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Looks like a bug. I'll check later today. See if I can reproduce it.
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: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

jimphelps wrote:Hi,
i've got a problem with Time:

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_main.lua: /home/pi/domoticz/scripts/lua/event_helpers.lua:179: attempt to call global 'getDayOfWeek' (a nil value)
It happens at domoticz start and every minute when a script like "schedule fish pond pump.lua" (based on day of week) is active:

Code: Select all

return {
	active = true,
	on = {
		['timer'] = {
			'at 8:30 on mon,tue,wed,thu,fri'
		}
	},
	...
	
Other "every minute" scripts are working well...
Does somone have an idea?
thanks
Jim
It was indeed a bug that I already fixed in the other branches. I hope to release them this weekend. In the mean time what you can do is open the file event-helpers.lua and move the function getDayOfWeek near the bottom of the file to above the function at line 179. That should fix it.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jimphelps
Posts: 2
Joined: Friday 08 April 2016 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: RE: Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by jimphelps »

dannybloe wrote:
jimphelps wrote:Hi,
i've got a problem with Time:

Code: Select all

Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_main.lua: /home/pi/domoticz/scripts/lua/event_helpers.lua:179: attempt to call global 'getDayOfWeek' (a nil value)
It happens at domoticz start and every minute when a script like "schedule fish pond pump.lua" (based on day of week) is active:

Code: Select all

return {
	active = true,
	on = {
		['timer'] = {
			'at 8:30 on mon,tue,wed,thu,fri'
		}
	},
	...
	
Other "every minute" scripts are working well...
Does somone have an idea?
thanks
Jim
It was indeed a bug that I already fixed in the other branches. I hope to release them this weekend. In the mean time what you can do is open the file event-helpers.lua and move the function getDayOfWeek near the bottom of the file to above the function at line 179. That should fix it.
Great! Thank you Dannybloe !
It is fixed and work now.
Jim


Envoyé de mon SM-G900F en utilisant Tapatalk
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

I have some issues with scenes, groups & virtual text devices.

The calls that won't work with scenes & groups:

Code: Select all

domoticz.devices['Scene1'].name
domoticz.devices['Group1'].name
It gives an error

Code: Select all

attempt to index field 'Scene1' (a nil value)
attempt to index field 'Group1' (a nil value)
And with virtual text devices when i try to change the text:

Code: Select all

domoticz.devices['Logging'].updateText('Hello!')
domoticz.devices['Logging'].update('Hello!')
It gives an error

Code: Select all

attempt to index field 'Logging' (a nil value)
How can i get scene/groupnames and how can i update virtual text devices?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Eduard wrote:I have some issues with scenes, groups & virtual text devices.

The calls that won't work with scenes & groups:

Code: Select all

domoticz.devices['Scene1'].name
domoticz.devices['Group1'].name
It gives an error

Code: Select all

attempt to index field 'Scene1' (a nil value)
attempt to index field 'Group1' (a nil value)
And with virtual text devices when i try to change the text:

Code: Select all

domoticz.devices['Logging'].updateText('Hello!')
domoticz.devices['Logging'].update('Hello!')
It gives an error

Code: Select all

attempt to index field 'Logging' (a nil value)
How can i get scene/groupnames and how can i update virtual text devices?
Ah, that's interesting indeed. Domoticz doesn't pass this information to the scripts at all so that's why dzVents doesn't process it.
What I can do is use the http data for this. The only downside to this is that this data is fetched by default every 30 minutes (see the settings file) so it may not be there (yet) when you just created such a device (scene, group, text) (of course you can easily create a dummy switch with a dzVents script that forces to fetch this data on switch click using domoticz.fetchHttpDomoticzData().
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

dannybloe wrote: What I can do is use the http data for this. The only downside to this is that this data is fetched by default every 30 minutes (see the settings file) so it may not be there (yet) when you just created such a device (scene, group, text) (of course you can easily create a dummy switch with a dzVents script that forces to fetch this data on switch click using domoticz.fetchHttpDomoticzData().
Seems ok solution with me. I don't create or change scenes that much.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Ok, that works now here (dev branch). For text dummies I added a text property (devices['mytextdevice'].text). Only thing is that, for text dummy devices, since the current value isn't passed by Domoticz but fetched through http, this property may be old (if you fetch every 30 minutes, which is the default).
Same applies for groups and their state.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

Should be ok. I use the text device only for writing status, not reading.
For scenes/groups i only use the methods to see if a certain scene/group exists (~= nil)
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

@dannybloe
Saw your code (in createMissingHTTPDevices) on the dev-branch (did not test is yet) but do you keep the idx'es from devices & scene/groups apart? Because in Domoticz they can have the same idx!
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Eduard wrote:@dannybloe
Saw your code (in createMissingHTTPDevices) on the dev-branch (did not test is yet) but do you keep the idx'es from devices & scene/groups apart? Because in Domoticz they can have the same idx!
OMG! Why!?!? :roll: That sux! Crap.. ok.. then I will separate collections:

Code: Select all

	domoticz.devices[]
	domoticz.variables[]
	domoticz.scenes[]
	domoticz.groups[]
Thanks for reporting this. There are still a lot of areas in Domoticz that I haven't discovered yet ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

Scenes & groups use the same idx-pool, so they an use the same collection imo
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

@dannybloe
What exactly do you have to fetch via the httprequest? I know my way a little bit in the Domoticz-code, so maybe we can expose the missing data via the 'normal' way.
I think it is possible to expose the missing scene/group info for example to dzVents by adding code to Domoticz...
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Eduard wrote:@dannybloe
What exactly do you have to fetch via the httprequest? I know my way a little bit in the Domoticz-code, so maybe we can expose the missing data via the 'normal' way.
I think it is possible to expose the missing scene/group info for example to dzVents by adding code to Domoticz...
Well, don't try me here... ;-)

Of course, it would be awesome that you use the code that generates the json that is sent through json.htm?type=devices&displayhidden=1&filter=all&used=true and have that generate a Lua table with exactly the same data. You can see the result when you open devices.lua after dzVents downloaded and converted this data. But that may be too much to ask.

Right now, apart from extracting groups and scenes I do this additionally with the data coming through http.

Code: Select all

	local function extendDevicesWithHTTPData()
		local httpData = readHttpDomoticzData()

		if (httpData) then
			for i, httpDevice in pairs(httpData.result) do
				if (self.devices[tonumber(httpDevice['idx'])]) then
					local device = self.devices[tonumber(httpDevice['idx'])]
					device.addAttribute('batteryLevel', httpDevice.BatteryLevel)
					device.addAttribute('signalLevel', httpDevice.SignalLevel)
					device.addAttribute('deviceSubType', httpDevice.SubType)
					device.addAttribute('deviceType', httpDevice.Type)
					device.addAttribute('hardwareName', httpDevice.HardwareName)
					device.addAttribute('hardwareType', httpDevice.HardwareType)
					device.addAttribute('hardwareId', httpDevice.HardwareID)
					device.addAttribute('hardwareTypeVal', httpDevice.HardwareTypeVal)
					device.addAttribute('switchType', httpDevice.SwitchType)
					device.addAttribute('switchTypeValue', httpDevice.SwitchTypeVal)

					if (device.deviceType == 'Heating' and device.deviceSubType == 'Zone') then
						device.addAttribute('setPoint', tonumber(device.rawData[2]))
						device.addAttribute('heatingMode', device.rawData[3])
					end

					if (device.deviceType ==  'Lux' and device.deviceSubType == 'Lux') then
						device.addAttribute('lux', tonumber(device.rawData[1]))
					end

					if (device.deviceType ==  'General' and device.deviceSubType == 'kWh') then
						device.addAttribute('WhTotal', tonumber(device.rawData[2]))
						device.addAttribute('WhToday', tonumber(device.rawData[1]))
					end
					if (device.deviceType ==  'P1 Smart Meter' and device.deviceSubType == 'Energy') then
						device.addAttribute('WActual', tonumber(device.rawData[5]))
					end

					if (device.deviceType == 'Thermostat' and device.deviceSubType == 'SetPoint') then
						device.addAttribute('setPoint', tonumber(device.rawData[1]))
					end

					if (device.deviceSubType == 'Text') then
						device.addAttribute('text', httpDevice.Data) -- could be old because it may not be fetched
					end
				end
			end
		end
	end
	
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

dannybloe wrote:Of course, it would be awesome that you use the code that generates the json that is sent through json.htm?type=devices&displayhidden=1&filter=all&used=true and have that generate a Lua table with exactly the same data. You can see the result when you open devices.lua after dzVents downloaded and converted this data. But that may be too much to ask.
For extracting data like battery status, switch type etc. etc. it would be too much to expose all this data to a lua table every time a script has to be evaluated. I think it would be best to leave this method in place for 'static' data and to expend the other devices-table with 1) scene & groups 2) actual status of all devices incl. virtual (text-)devices.

What do you think?

ps.: i managed to add a custom lua-table in Domoticz-code with extra info that can be read from lua-script ;)
Last edited by Eduard on Tuesday 12 April 2016 9:48, edited 1 time in total.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

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

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

dannybloe wrote:Sounds great.
@dannybloe
I've created a patch for the missing states of textlog-devices & several virtual devices. I also added a new LUA-table "otherdevices_scenesgroups" with all the Scenes/Groups with their status.

Are you able to test this patch with dzVents before i make a pull-request to merge it with the master-branch? You can find it at https://github.com/EddyK69/domoticz/tree/lua_expose

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

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Eduard wrote:
dannybloe wrote:Sounds great.
@dannybloe
I've created a patch for the missing states of textlog-devices & several virtual devices. I also added a new LUA-table "otherdevices_scenesgroups" with all the Scenes/Groups with their status.

Are you able to test this patch with dzVents before i make a pull-request to merge it with the master-branch? You can find it at https://github.com/EddyK69/domoticz/tree/lua_expose

Thanx ;)
I don't have such a test setup but I will add the functionality in the dev branch this weekend so maybe you can test it. I'll let you know.
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: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Eduard wrote:
dannybloe wrote:Sounds great.
@dannybloe
I've created a patch for the missing states of textlog-devices & several virtual devices. I also added a new LUA-table "otherdevices_scenesgroups" with all the Scenes/Groups with their status.

Are you able to test this patch with dzVents before i make a pull-request to merge it with the master-branch? You can find it at https://github.com/EddyK69/domoticz/tree/lua_expose

Thanx ;)
How do we get to the id of a scene or a group? It isn't part of the otherdevices_idx table but I do need it for completeness. I can still get that from the http data or you should create a table like otherdevices_groupsandscenes_idx or something like that.

And.. I want to have scenes and groups split so I can create domoticz.scenes[<name>/<id>] and domoticz.groups[<name>/<id>]. So I need a way to distinguish these two. If they are all in one table then I still cannot make that distinction without using the http data.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Eduard
Posts: 139
Joined: Monday 19 January 2015 9:14
Target OS: -
Domoticz version:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Eduard »

dannybloe wrote:How do we get to the id of a scene or a group? It isn't part of the otherdevices_idx table but I do need it for completeness. I can still get that from the http data or you should create a table like otherdevices_groupsandscenes_idx or something like that.
How do you get them for devices? Via the http data? If yes, i propose to get them for scenes/groups also via http data.
dannybloe wrote:And.. I want to have scenes and groups split so I can create domoticz.scenes[<name>/<id>] and domoticz.groups[<name>/<id>]. So I need a way to distinguish these two. If they are all in one table then I still cannot make that distinction without using the http data.
It's ok by me to split those... If you do a http data with json.htm?type=devices&displayhidden=1&filter=all&used=true, you can look at the "Type" tag. For scenes it is "Scene" and for groups "Group" :D

Code: Select all

      {
         "Data" : "Mixed",
         "Description" : "",
         "Favorite" : 0,
         "LastUpdate" : "2016-03-17 12:35:42",
         "Name" : "Scene1",
         "PlanID" : "",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "Status" : "Mixed",
         "Type" : "Scene",
         "TypeImg" : "scene",
         "UsedByCamera" : false,
         "XOffset" : 0,
         "YOffset" : 0,
         "idx" : "1"
      },
      {
         "Data" : "Off",
         "Description" : "",
         "Favorite" : 0,
         "LastUpdate" : "2016-02-06 16:57:47",
         "Name" : "Group1",
         "PlanID" : "",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "Status" : "Off",
         "Type" : "Group",
         "TypeImg" : "group",
         "UsedByCamera" : false,
         "XOffset" : 0,
         "YOffset" : 0,
         "idx" : "2"
      }
Locked

Who is online

Users browsing this forum: No registered users and 1 guest