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

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

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

Postby dannybloe » Wednesday 19 October 2016 14:50

Wroopy wrote:
dannybloe wrote:
dannybloe wrote:
Every time the script is executed it reads the persistent data and stores it when the script is finished. So each time the switch changes.


I just tested it here and it works with this script:

Code: Select all

return {
   active = true,
   on = {
      'mySensor'
   },
   data = {
      history = {history = true, maxItems = 10}
   },
   execute = function(domoticz, sensor)
      local reading = sensor.temperature
      domoticz.data.history.add(reading)
      local avg = domoticz.data.history.avg()
      local size = domoticz.data.history.size
      print(sensor.name .. ": last=" .. reading .. ", avg=" .. avg .. ", size= " .. size)
   end
}


and the data file is like this:

Code: Select all

-- Persistent Data
local multiRefObjects = {

} -- multiRefObjects
local obj1 = {
   ["history"] = {
      [1] = {
         ["time"] = "2016-10-19 09:45:59";
         ["data"] = 16.799999237061;
      };
      [2] = {
         ["time"] = "2016-10-19 09:45:58";
         ["data"] = 16.799999237061;
      };
      [3] = {
         ["time"] = "2016-10-19 09:45:30";
         ["data"] = 16.799999237061;
      };
      [4] = {
         ["time"] = "2016-10-19 09:45:29";
         ["data"] = 16.799999237061;
      };
      [5] = {
         ["time"] = "2016-10-19 09:44:59";
         ["data"] = 16.799999237061;
      };
      [6] = {
         ["time"] = "2016-10-19 09:44:58";
         ["data"] = 16.799999237061;
      };
      [7] = {
         ["time"] = "2016-10-19 09:44:29";
         ["data"] = 16.799999237061;
      };
      [8] = {
         ["time"] = "2016-10-19 09:44:28";
         ["data"] = 16.799999237061;
      };
      [9] = {
         ["time"] = "2016-10-19 09:43:59";
         ["data"] = 16.799999237061;
      };
      [10] = {
         ["time"] = "2016-10-19 09:43:58";
         ["data"] = 16.89999961853;
      };
   };
}
return obj1



Are you sure that the script is called multiple times?


Yes I'm sure it is calles several times. I can see it both in Domoticz log and the timestamp of the item is changed in the storage-file.

I've tested to increase the logging, i.e. change ['Log level'] = 3 in dzVents_settings.lua too see if I would get som extra useful information. Got some very confusing result

1. The size of the history variable where increasing. So finally I got 10 items as expected.
2. Changed back to ['Log level'] = 2 and now I get only one hisory item.
3. Switch to level 3 again and it worked as expected.
4. Changed back to 2 and got only one history item.

Does that give any hint on what the problem could be?


Wow, that is certainly weird. I'd have to debug that. Can you PM me your entire script code?
Creator dzVents - RPiB+ZWay - Aeotec MultiSensor (6x) - Fibaro/Popp/GreenWave wall plugs - TKB Home dimmer - Aeotec Door sensor - Toon - 2x FGD-212, 8x FGD-211, 3x Qubino Flush dimmers - EvoHome Wifi+HGI80 - ESPEasy

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

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

Postby dannybloe » Wednesday 19 October 2016 15:05

dannybloe wrote:
Wroopy wrote:
dannybloe wrote:
Wow, that is certainly weird. I'd have to debug that. Can you PM me your entire script code?


I cannot reproduce this. In my test the loglevel has no influence. :roll:
Creator dzVents - RPiB+ZWay - Aeotec MultiSensor (6x) - Fibaro/Popp/GreenWave wall plugs - TKB Home dimmer - Aeotec Door sensor - Toon - 2x FGD-212, 8x FGD-211, 3x Qubino Flush dimmers - EvoHome Wifi+HGI80 - ESPEasy

Wroopy
Posts: 8
Joined: Tuesday 18 October 2016 22:06
Target OS: Linux
Domoticz version: v3.5745
Contact:

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

Postby Wroopy » Wednesday 19 October 2016 16:36

dannybloe wrote:
Wroopy wrote:
dannybloe wrote:
I just tested it here and it works with this script:

Code: Select all

return {
   active = true,
   on = {
      'mySensor'
   },
   data = {
      history = {history = true, maxItems = 10}
   },
   execute = function(domoticz, sensor)
      local reading = sensor.temperature
      domoticz.data.history.add(reading)
      local avg = domoticz.data.history.avg()
      local size = domoticz.data.history.size
      print(sensor.name .. ": last=" .. reading .. ", avg=" .. avg .. ", size= " .. size)
   end
}




Wow, that is certainly weird. I'd have to debug that. Can you PM me your entire script code?


To make sure I don't have ant race conditions, I've removed all other scripts and have only the script that you've tested with.

Still the same problem.

Tested with different loglevels and it is only when having log level 2 it doesn't work. :?

Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Glatzi » Wednesday 19 October 2016 20:06

dannybloe wrote:Yea you can set it to true if you start the stuff in th evening for the first time. That's an easy one ;)

Hi dannybloe,

just came back from vacation & quickly implemented your script. It works fine!
Thanks for your input!!!

What I'm still generally searching for is some kind of logic to distinguish if a switch was triggered by a PIR or manually trough the light button which triggers a Fibaro relay.
An example is that someone manually triggers a light switch in our hall. There also is a PIR. So although the switch is triggered manually the PIR detects the motion & the state in the dzVents table changes. So how can I differentiate this case for a proper handling?

Any input is really appreciated :-)

Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Glatzi » Sunday 23 October 2016 20:39

Hi dannybloe,

can you please take a look at the latest beta of Domoticz? Something is going wrong with the scenes & dzEvents there. I'm getting the following error with all of my scenes:

Code: Select all

LUA: Cannot find the device. Skipping: KuecheLichtSchrank 1


2016-10-23_20-38-34.gif
2016-10-23_20-38-34.gif (42.11 KiB) Viewed 672 times


I've deleted all scenes & recreated just the one above but the error remains. No more errors even in debug level 3.
I've also stopped Domoticz & deleted the devices.lua file so it can be build up from scratch but no luck at all :-(

Best rergards

Stephan

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

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

Postby dannybloe » Sunday 23 October 2016 21:19

Glatzi wrote:Hi dannybloe,

can you please take a look at the latest beta of Domoticz? Something is going wrong with the scenes & dzEvents there. I'm getting the following error with all of my scenes:

Code: Select all

LUA: Cannot find the device. Skipping: KuecheLichtSchrank 1


2016-10-23_20-38-34.gif

I've deleted all scenes & recreated just the one above but the error remains. No more errors even in debug level 3.
I've also stopped Domoticz & deleted the devices.lua file so it can be build up from scratch but no luck at all :-(

Best rergards

Stephan


Upgrade to the latest dzvents release.
Creator dzVents - RPiB+ZWay - Aeotec MultiSensor (6x) - Fibaro/Popp/GreenWave wall plugs - TKB Home dimmer - Aeotec Door sensor - Toon - 2x FGD-212, 8x FGD-211, 3x Qubino Flush dimmers - EvoHome Wifi+HGI80 - ESPEasy

Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Glatzi » Monday 24 October 2016 7:45

Thx, that solved the error!

Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Glatzi » Monday 24 October 2016 10:05

I've got a question regarding the switchOn().for_min(x) method.

If I'm using this with a power switch in conjunction with a PIR like this:

Code: Select all

if ( PIRKeller.state == 'On' and Keller_Switch.state == 'Off' ) then

   Keller_Switch.switchOn().for_min(2)
               
 elseif ( PIRKeller.state == 'On' and Keller_Switch.state == 'On' ) then
 
        Keller_Switch.switchOn().for_min(2)
end


What happens with the for_min(x) timer when the elsif section is executed:

Is the first timer just canceled & the second will be executed with 2 minutes or is the
time added to the first timer?

Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Glatzi » Thursday 27 October 2016 19:19

Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif
2016-10-27_19-15-05.gif (10.43 KiB) Viewed 599 times

Wroopy
Posts: 8
Joined: Tuesday 18 October 2016 22:06
Target OS: Linux
Domoticz version: v3.5745
Contact:

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

Postby Wroopy » Monday 31 October 2016 10:11

Glatzi wrote:Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif


I got the same dot-file in the data directory. For me, the reason is that I'm using vi as editor and when you open a file in vi a backup file is created with a leading dot in the filename.

The backupfile is detected and evaluated as a ordinary script by dzVents/lua.

@dannybloe; A possible improvement to dzVents woul be to ignore script-files with a leading dot?

/Andreas

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

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

Postby dannybloe » Wednesday 02 November 2016 9:26

Wroopy wrote:
Glatzi wrote:Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif


I got the same dot-file in the data directory. For me, the reason is that I'm using vi as editor and when you open a file in vi a backup file is created with a leading dot in the filename.

The backupfile is detected and evaluated as a ordinary script by dzVents/lua.

@dannybloe; A possible improvement to dzVents woul be to ignore script-files with a leading dot?

/Andreas


Aha.. that explains... we should certainly ignore those .dotted scripts completely. Right now they are executed as normal scripts!!
I'm very busy at home right now (renovation) which will take at least one or two weeks so I don't have time to fix that I think. I will try but no promises. On the other hand... pull requests are always welcome ;-)
Creator dzVents - RPiB+ZWay - Aeotec MultiSensor (6x) - Fibaro/Popp/GreenWave wall plugs - TKB Home dimmer - Aeotec Door sensor - Toon - 2x FGD-212, 8x FGD-211, 3x Qubino Flush dimmers - EvoHome Wifi+HGI80 - ESPEasy

Markvr
Posts: 1
Joined: Thursday 04 December 2014 19:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Markvr » Wednesday 02 November 2016 18:04

Hi Danny,

I'm trying to read the CounterDelivToday from a P1 Smart Meter device. But I only get a nil value returned. The CounterToday value is working well!

Can you help me?

Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby Glatzi » Friday 04 November 2016 8:26

Wroopy wrote:
Glatzi wrote:Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif


I got the same dot-file in the data directory. For me, the reason is that I'm using vi as editor and when you open a file in vi a backup file is created with a leading dot in the filename.

The backupfile is detected and evaluated as a ordinary script by dzVents/lua.

@dannybloe; A possible improvement to dzVents woul be to ignore script-files with a leading dot?

/Andreas


Hi Andreas,

when you edit files with vim the file is marked with a dot as a prefix & a suffix .swp

Anyway, this is no big deal.
Goold luck with your renovation project @dannybloe :-) This year we had do it in our whole house instead of taking a vacation :D
04-11-_2016_07-17-43.png
04-11-_2016_07-17-43.png (55.35 KiB) Viewed 488 times

Wroopy
Posts: 8
Joined: Tuesday 18 October 2016 22:06
Target OS: Linux
Domoticz version: v3.5745
Contact:

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

Postby Wroopy » Friday 04 November 2016 18:31

dannybloe wrote:Aha.. that explains... we should certainly ignore those .dotted scripts completely. Right now they are executed as normal scripts!!
I'm very busy at home right now (renovation) which will take at least one or two weeks so I don't have time to fix that I think. I will try but no promises. On the other hand... pull requests are always welcome ;-)


Made a pull request (my first time, but hope it was done correct).

The current logic is to include all files that contains .lua
Changed to logic to make sure that the file ends with .lua and does not begin with a dot.

User avatar
felix63
Posts: 70
Joined: Monday 07 December 2015 10:30
Target OS: Raspberry Pi
Domoticz version: 3.6214
Location: Gouda
Contact:

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

Postby felix63 » Monday 21 November 2016 23:27

Hi Danny,

Nice piece of software. My compliments. I have ported a few scripts. Easier then I thought. Two small questions. I have one script controlling two devices. If one is changed the other one follows. This requires more lines then I expected because apparently I can't copy the state of one device to the other. Is that true or am I missing something?

Code: Select all

return {
   active = true,                 
   on = { 'Subwoofer',
         'Versterker' },

   execute = function(domoticz, mySwitch)
      if domoticz.devices['Versterker'].changed and domoticz.devices['Subwoofer'].state ~= domoticz.devices['Versterker'].state then
         if domoticz.devices['Versterker'].state == 'On' then
            domoticz.devices['Subwoofer'].switchOn()
         else
            domoticz.devices['Subwoofer'].switchOff()
         end
      elseif  domoticz.devices['Subwoofer'].changed and domoticz.devices['Versterker'].state ~= domoticz.devices['Subwoofer'].state then
         if domoticz.devices['Subwoofer'].state == 'On' then
            domoticz.devices['Versterker'].switchOn()
         else
            domoticz.devices['Versterker'].switchOff()
         end
      end
   end
}


Secondly can I use a (selector-type) switch in domoticz to dynamically set the log-level? If yes then how?

Cheers,
Lex

Doler
Posts: 90
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi
Domoticz version: v3.6277
Location: Sint-Oedenrode, Netherlands
Contact:

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

Postby Doler » Monday 21 November 2016 23:49

Something like

Code: Select all

Domoticz.devices['Subwoofer'].setState(Domoticz.devices['Versterker'].state)
Mark: Domoticz Beta on Raspberry Pi B2 running Debian Jessie - RaZberry - RFXCom - MySensors - SolarEdge - Nefit

User avatar
felix63
Posts: 70
Joined: Monday 07 December 2015 10:30
Target OS: Raspberry Pi
Domoticz version: 3.6214
Location: Gouda
Contact:

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

Postby felix63 » Sunday 04 December 2016 19:09

Doler wrote:Something like

Code: Select all

Domoticz.devices['Subwoofer'].setState(Domoticz.devices['Versterker'].state)


That works better, thanks!



Verzonden vanaf mijn iPad met Tapatalk

User avatar
felix63
Posts: 70
Joined: Monday 07 December 2015 10:30
Target OS: Raspberry Pi
Domoticz version: 3.6214
Location: Gouda
Contact:

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

Postby felix63 » Sunday 04 December 2016 19:17

Wouldn't it be possible to set/change the debug level using a (selector)switch?

gus
Posts: 13
Joined: Tuesday 04 November 2014 11:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

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

Postby gus » Saturday 10 December 2016 15:22

Hi!

Trying to switch on groups with dzvents but don't get it to work...

Shouldn't this work:
domoticz.switchGroups('Innelampor Basement', 'On')


Please advice


/Rickard
Last edited by gus on Saturday 10 December 2016 15:30, edited 2 times in total.

Doler
Posts: 90
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi
Domoticz version: v3.6277
Location: Sint-Oedenrode, Netherlands
Contact:

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

Postby Doler » Saturday 10 December 2016 15:27

gus wrote:Hi!

Trying to switch on groups with dzvents but don't get it to work...

Shouldn't this work:
domoticz.groups['Innelampor Basement'].switchOn()


Please advice


/Rickard

You should use

Code: Select all

 domoticz.switchGroup('Innelampor Basement', 'On')

(see Domoticz methods)
Mark: Domoticz Beta on Raspberry Pi B2 running Debian Jessie - RaZberry - RFXCom - MySensors - SolarEdge - Nefit


Return to “dzVents Lua Framework”

Who is online

Users browsing this forum: No registered users and 1 guest