dzVents 1.0 released

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:

Re: dzVents 1.0 released

Post by dannybloe »

Peepz, please use the tracker on GitHub for bugs/problems/errors. That way I can better keep tracker of things.
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.0 released

Post by dhanjel »

Seriously, this should be merged with the main code and be the main engine for lua scripts.
So much simpler to work with in every way possible.

I am trying to get a notification sent when my dishwasher is done (consumption stays around 3.3w for a couple of minutes),
but it seems to through some errors.

Code: Select all

2016-06-06 14:25:19.037 Error: EventSystem: in Dishwasher_Monitor: [string "commandArray = {}..."]:6: bad argument #1 to 'pairs' (table expected, got nil)
Any ideas?

Code: Select all

return  {
          active = false,
          on = {
            ['timer'] = 'every minute'
          },
          data = {
            readingHistory = { 
              history = true, 
              maxItems = 3 
            },
            notificationSent = { 
              initial = false
            }
          },
          execute = function(domoticz, switch, triggerInfo)            
            
            local consumption = domoticz.devices['Kök, Diskmaskin'].WActual
            domoticz.data.readingHistory.add(consumption)
            
            local average = domoticz.data.readingHistory.avg()
            
            if (average == 3.3 and not domoticz.data.notificationSent)
            then
              domoticz.data.notificationSent = true
              domoticz.notify('Diskmaskinen klar!', 
                              'Diskmaskinen har precis kört klart aktuellt program.', 
                               domoticz.PRIORITY_LOW)
            elseif (average > 100)
            then
              domoticz.data.notificationSent = false
            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.0 released

Post by dannybloe »

dhanjel wrote:Seriously, this should be merged with the main code and be the main engine for lua scripts.
So much simpler to work with in every way possible.
Working on it ;-)
dhanjel wrote: I am trying to get a notification sent when my dishwasher is done (consumption stays around 3.3w for a couple of minutes),
but it seems to through some errors.

Code: Select all

2016-06-06 14:25:19.037 Error: EventSystem: in Dishwasher_Monitor: [string "commandArray = {}..."]:6: bad argument #1 to 'pairs' (table expected, got nil)
Any ideas?

Code: Select all

return  {
          active = false,
          on = {
            ['timer'] = 'every minute'
          },
          data = {
            readingHistory = { 
              history = true, 
              maxItems = 3 
            },
            notificationSent = { 
              initial = false
            }
          },
          execute = function(domoticz, switch, triggerInfo)            
            
            local consumption = domoticz.devices['Kök, Diskmaskin'].WActual
            domoticz.data.readingHistory.add(consumption)
            
            local average = domoticz.data.readingHistory.avg()
            
            if (average == 3.3 and not domoticz.data.notificationSent)
            then
              domoticz.data.notificationSent = true
              domoticz.notify('Diskmaskinen klar!', 
                              'Diskmaskinen har precis kört klart aktuellt program.', 
                               domoticz.PRIORITY_LOW)
            elseif (average > 100)
            then
              domoticz.data.notificationSent = false
            end
            
          end
        }
In the same log there should be a list of all the command array items that dzVents prepares and sends back to Domoticz. Can you post that list?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
HenFre
Posts: 6
Joined: Thursday 12 May 2016 15:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8771
Location: Sweden
Contact:

Re: dzVents 1.0 released

Post by HenFre »

Excuse a beginner, but is this included when I started from BETA ver. 3.5187 och does I always have to install it separately?
Domoticz on Raspberry PI 3 since 2016.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.0 released

Post by dannybloe »

For now you have to install it separately (which means copying some files over to the right location and renaming the settings file). See the README.md.
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.0 released

Post by dhanjel »

Thats all I got.
I do have a single entry of this as well,

2016-06-06 15:02:51.720 Error: Getting error 'Transport endpoint is not connected' while getting remote_endpoint in connection_manager::start
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.0 released

Post by dannybloe »

dhanjel wrote:Thats all I got.
I do have a single entry of this as well,

2016-06-06 15:02:51.720 Error: Getting error 'Transport endpoint is not connected' while getting remote_endpoint in connection_manager::start
That line is not related to dzVents.
But what if you don't send the notification but do a print statement instead?
I get the feeling that there's some other script that is causing problems. Do you have other scripts in the ../scripts/lua folder besides script_device_main.lua?
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.0 released

Post by dhanjel »

Nope, this is my only script. Will debug a bit more later.

Sent from my Nexus 6P using Tapatalk
Atmosphere
Posts: 10
Joined: Wednesday 28 January 2015 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Utrecht
Contact:

Re: dzVents 1.0 released

Post by Atmosphere »

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

Re: dzVents 1.0 released

Post by dannybloe »

Well, u gotta do some debugging then :). Maybe turning on debug logging in the settings gives some clues.
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.0 released

Post by dhanjel »

One step in the right direction. It seemed I had to many parameters to the execute-function.

Next bump in the road, it seems that the power consumption always is null.

Code: Select all

return  {
          active = true,
          on = { ['timer'] = 'every minute' },
          data = {
            readingHistory = { history = true, maxItems = 3 },
            notificationSent = { initial = false }
          },
          execute = function(domoticz)            
            
            local consumption = domoticz.devices['Kök, Diskmaskin'].WActual
            if (consumption == nill)
            then
              domoticz.log("Consumption could not be read.", domoticz.LOG_INFO)
            else
              domoticz.data.readingHistory.add(consumption)
              domoticz.log("Current consumption: " .. consumption, domoticz.LOG_INFO)
             local average = domoticz.data.readingHistory.avg()
              
              if (average == 3.3 and not domoticz.data.notificationSent)
              then
                domoticz.data.notificationSent = true
                --domoticz.notify('Diskmaskinen klar!', 
                --                'Diskmaskinen har precis kört klart aktuellt program.', 
                --                 domoticz.PRIORITY_LOW)
                 domoticz.log("Dishwasher done", domoticz.LOG_INFO)
              elseif (average > 100)
              then
                domoticz.data.notificationSent = false
              end
            end
          end
        }

Code: Select all

2016-06-07 07:52:00.441 LUA: =====================================================
2016-06-07 07:52:00.441 LUA: >>> Handler: dishwasher
2016-06-07 07:52:00.441 LUA: .....................................................
2016-06-07 07:52:00.441 LUA: Consumption could not be read.
2016-06-07 07:52:00.441 LUA: .....................................................
2016-06-07 07:52:00.441 LUA: <<< Done
2016-06-07 07:52:00.441 LUA: -----------------------------------------------------
Image

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

Re: dzVents 1.0 released

Post by dannybloe »

dhanjel wrote:One step in the right direction. It seemed I had to many parameters to the execute-function.

Next bump in the road, it seems that the power consumption always is null.

Code: Select all

return  {
          active = true,
          on = { ['timer'] = 'every minute' },
          data = {
            readingHistory = { history = true, maxItems = 3 },
            notificationSent = { initial = false }
          },
          execute = function(domoticz)            
            
            local consumption = domoticz.devices['Kök, Diskmaskin'].WActual
            if (consumption == nill)
            then
              domoticz.log("Consumption could not be read.", domoticz.LOG_INFO)
            else
              domoticz.data.readingHistory.add(consumption)
              domoticz.log("Current consumption: " .. consumption, domoticz.LOG_INFO)
             local average = domoticz.data.readingHistory.avg()
              
              if (average == 3.3 and not domoticz.data.notificationSent)
              then
                domoticz.data.notificationSent = true
                --domoticz.notify('Diskmaskinen klar!', 
                --                'Diskmaskinen har precis kört klart aktuellt program.', 
                --                 domoticz.PRIORITY_LOW)
                 domoticz.log("Dishwasher done", domoticz.LOG_INFO)
              elseif (average > 100)
              then
                domoticz.data.notificationSent = false
              end
            end
          end
        }

Code: Select all

2016-06-07 07:52:00.441 LUA: =====================================================
2016-06-07 07:52:00.441 LUA: >>> Handler: dishwasher
2016-06-07 07:52:00.441 LUA: .....................................................
2016-06-07 07:52:00.441 LUA: Consumption could not be read.
2016-06-07 07:52:00.441 LUA: .....................................................
2016-06-07 07:52:00.441 LUA: <<< Done
2016-06-07 07:52:00.441 LUA: -----------------------------------------------------
Image

HTTP Fetch is configured
Ok, the best step next is to look into the file devices.lua. First of all, that file should exist and be recent (not older than the fetch interval as set in the setttings file). If that is the case you can open the file and find the Kök device and see if it has the proper wattage listed. Also check that the name is exactly the same as you use in your code. (Can you post the piece for your device here?)
Another thing you can do is dump the device state to the logs: domoticz.logDevice(domoticz.devices). It should show all the attributes on the device (although Domoticz has the tendency to swallow some log messages if they come too fast and too many in a row).

I'm just looking at the code that sets the WActual value:

Code: Select all

if (device.deviceType ==  'General' and device.deviceSubType == 'kWh') then
	device.addAttribute('WhTotal', tonumber(device.rawData[2]))
	device.addAttribute('WActual', tonumber(device.rawData[1]))
	local todayFormatted = httpDevice.CounterToday or ''
	-- risky business, we assume no decimals, just thousands separators
	-- there is no raw value available for today
	local s = string.gsub(todayFormatted, '%.', '')
	s = string.gsub(s, '%,', '')
	s = string.gsub(s, ' kWh', '')
	device.addAttribute('WhToday', tonumber(s))
end
As you can see it makes some assumptions. First of all, I suspect that it is also possible that the deviceType in your case is not General (see the devices.lua dump). Let me know what your deviceType is in this case so maybe I can add some more checks.

In the mean time you can also look at the rawData attribute of the device in your case. It is likely that it holds the actual usage as well.

So, plenty of starting points to investigate this. I'm sure we can nail this bugger :) Please be a bit more patient here...
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.0 released

Post by dhanjel »

I don´t see a deviceType, only subType.

Code: Select all

{
         ["AddjMulti"]= 1.0,
         ["AddjMulti2"]= 1.0,
         ["AddjValue"]= 0.0,
         ["AddjValue2"]= 0.0,
         ["BatteryLevel"]= 255,
         ["CustomImage"]= 0,
         ["Data"]= "3.4 Watt",
         ["Description"]= "",
         ["Favorite"]= 0,
         ["HardwareID"]= 2,
         ["HardwareName"]= "Z-Wave",
         ["HardwareType"]= "OpenZWave USB",
         ["HardwareTypeVal"]= 21,
         ["HaveTimeout"]= true,
         ["ID"]= "0001901",
         ["LastUpdate"]= "2016-06-07 07:40:22",
         ["Name"]= "Kök, Diskmaskin Förbrukning",
         ["Notifications"]= "false",
         ["PlanID"]= "0",
         ["PlanIDs"]= { 0 },
         ["Protected"]= false,
         ["ShowNotifications"]= true,
         ["SignalLevel"]= "-",
         ["SubType"]= "Electric",
         ["Timers"]= "false",
         ["Type"]= "Usage",
         ["TypeImg"]= "current",
         ["Unit"]= 2,
         ["Used"]= 1,
         ["XOffset"]= "0",
         ["YOffset"]= "0",
         ["idx"]= "97"
      }
It is a Fibaro Wall Plug.
(Tried to change the name since I have many with the same name since consumptions are separate devices in Domoticz compared to for instance Fibaro)

If I do

Code: Select all

  domoticz.logDevice(domoticz.devices)
I only get

Code: Select all

2016-06-07 09:03:00.261 LUA: =====================================================
2016-06-07 09:03:00.261 LUA: >>> Handler: dishwasher
2016-06-07 09:03:00.261 LUA: .....................................................
2016-06-07 09:03:00.261 LUA: ----------------------------
2016-06-07 09:03:00.261 LUA: An error occured when calling event handler dishwasher
2016-06-07 09:03:00.261 LUA: /home/daniel/domoticz/scripts/lua/dzVents/Domoticz.lua:269: attempt to concatenate field 'name' (a nil value)
2016-06-07 09:03:00.261 LUA: .....................................................
2016-06-07 09:03:00.261 LUA: <<< Done
2016-06-07 09:03:00.261 LUA: -----------------------------------------------------
Perhaps I managed so install someting incorrectly.

I don´t have any device in the devices.lua file with property WActual
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.0 released

Post by dannybloe »

Well, I found an omission in my code and indeed it didn't recognize Usage devices and their WActual information. I just release 1.0.2 that should fix this. Please check it out.

1.0.2:
  • Added device description attribute.
  • Added support for setting the setpoint for opentherm gateway.
  • Added timedOut boolean attribute to devices. Requires http data fetching to be anabled.
  • Properly detects usage devices and their Wattage.
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.0 released

Post by dhanjel »

Sweet, that part seems to work fine now.

Code: Select all

2016-06-07 09:38:00.233 LUA: =====================================================
2016-06-07 09:38:00.233 LUA: >>> Handler: dishwasher
2016-06-07 09:38:00.233 LUA: .....................................................
2016-06-07 09:38:00.233 LUA: Current consumption: 3.4
2016-06-07 09:38:00.233 LUA: .....................................................
2016-06-07 09:38:00.233 LUA: <<< Done
2016-06-07 09:38:00.233 LUA: -----------------------------------------------------
Just need to wait until I can run the dishwasher again to test :)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.0 released

Post by dannybloe »

dhanjel wrote:Sweet, that part seems to work fine now.

Code: Select all

2016-06-07 09:38:00.233 LUA: =====================================================
2016-06-07 09:38:00.233 LUA: >>> Handler: dishwasher
2016-06-07 09:38:00.233 LUA: .....................................................
2016-06-07 09:38:00.233 LUA: Current consumption: 3.4
2016-06-07 09:38:00.233 LUA: .....................................................
2016-06-07 09:38:00.233 LUA: <<< Done
2016-06-07 09:38:00.233 LUA: -----------------------------------------------------
Just need to wait until I can run the dishwasher again to test :)
3.4 Watt when it's not running? I'd get a new one ;-)
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.0 released

Post by dhanjel »

Its when it's idle. When it is powered off it is near 0. (It has a display that is on)

Sent from my Nexus 6P using Tapatalk
dhanjel
Posts: 102
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Re: dzVents 1.0 released

Post by dhanjel »

is it possible to retrieve a device by id instead of name? I have a lot of devices with the same name
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents 1.0 released

Post by dannybloe »

Of course you can do it by id: domoticz.devices[123]. However, I strongly advise against having devices with the same name as dzVents has no way of keeping them apart in an easy way because Domoticz sends the stuff name-based. I'd rename the devices to make them unique.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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.0 released

Post by jkimmel »

Because there s no other place where scripts can showed, here my contribution based on the help of @dannybloe.
It is about heating control:

1. control heat circuits by setpoints:

Code: Select all


return {
   active = true, 
   on = {
      ['timer'] = 'every 10 minutes', 
   },
   execute = function(domoticz)
      
      local function regulate(setpoint, temperature, boiler)
         if (temperature < setpoint) and (boiler.state == 'Off') then boiler.switchOn()
         else
            if (boiler.state == 'On') then boiler.switchOff()
            end
         end
      end
      
      local spSalon = tonumber(domoticz.devices['Setpoint Salon'].state)
      local tSalon = domoticz.devices['Salon'].temperature
      local bSalon = domoticz.devices['FB 21 Heizkreis Salon']

      local spBath = tonumber(domoticz.devices['Setpoint Bad'].state)
      local tBath = domoticz.devices['Bad'].temperature
      local bBath = domoticz.devices['FB 42 Heizkreis Bad']
      
      local spBuero = tonumber(domoticz.devices['Setpoint Buero'].state)
      local tBuero = domoticz.devices['Buero'].temperature
      local bBuero = domoticz.devices['FB 23 Heizkreis Buero']
      
      local spSchlafzimmer = tonumber(domoticz.devices['Setpoint Schlafzimmer'].state)
      local tSchlafzimmer = domoticz.devices['Schlafzimmer'].temperature
      local bSchlafzimmer = domoticz.devices['FB 32 Heizkreis Schlafzimmer']

	  local spGaestebad = tonumber(domoticz.devices['Setpoint Gaestebad'].state)
      local tGaestebad = domoticz.devices['Gaestebad'].temperature
      local bGaestebad = domoticz.devices['FB 41 Heizkreis Gaestebad']

      regulate(spSalon, tSalon, bSalon)
      regulate(spBath, tBath, bBath)
      regulate(spBuero, tBuero, bBuero)
      regulate(spSchlafzimmer, tSchlafzimmer, bSchlafzimmer)
      regulate(spGaestebad, tGaestebad, bGaestebad)
      
    
      
   end

   }
    
2. control heatpump:

Code: Select all


return {
   active = true, 
   on = {
      ['timer'] = 'every 10 minutes', 
   },
   execute = function(domoticz)
	local Wp = domoticz.devices['FB 33 Wärmepumpe']
	local bSalon = domoticz.devices['FB 21 Heizkreis Salon']
	local bBath = domoticz.devices['FB 42 Heizkreis Bad']
	local bBuero = domoticz.devices['FB 23 Heizkreis Buero']
	local bSchlafzimmer = domoticz.devices['FB 32 Heizkreis Schlafzimmer']
	local bGaestebad = domoticz.devices['FB 41 Heizkreis Gaestebad']
	
	if (bSalon == 'On') or (bBath == 'On') or (bBuero == 'On') or (bSchlafzimmer == 'On') or (bGaestebad == 'On') and (Wp.state == 'Off')
    	then Wp.switchOn()
    else if (Wp.state == 'On')
    	then Wp.switchOff()
     	 end
    end
      
end
}
I'm sure dannybloe will have a look at this and will comment if there is a need.
Rfxcom
Raspi 4
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest