Page 4 of 7

Re: dzVents 1.0 released

Posted: Wednesday 08 June 2016 18:47
by dhanjel
Is it possible to set a RGB/RGBW device (Fibaro) colors?

Re: dzVents 1.0 released

Posted: Wednesday 08 June 2016 19:12
by dannybloe
How is that done with traditional scripting in Domoticz?

Re: dzVents 1.0 released

Posted: Wednesday 08 June 2016 19:35
by dhanjel
No idea :/

I´ve started a script that will set the rgb-list behind the tv to different colors depending on the state.
tv-off: yellow
tv-on: green
tv-on and chromecast active: red

(or something like that)

Re: dzVents 1.0 released

Posted: Wednesday 08 June 2016 20:01
by dannybloe
Well, I can't find anything on how to control rgbw values from Lua so if someone knows how to do it I can add support for it.

Re: dzVents 1.0 released

Posted: Wednesday 08 June 2016 20:18
by dhanjel
Doesn´t seem to be much info.
viewtopic.php?f=6&t=10458
Is the only relevant I find.

Re: dzVents 1.0 released

Posted: Thursday 09 June 2016 8:55
by dannybloe
jkimmel wrote: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.
Nice.

I just added an example script in the dev branch that controls heating in one room where a setpoint device, a temp-sensor and a boiler switch work together with some basic hysteresis control. You could duplicate the script for all device or adapt it to support multi-rooms. It uses one hystorical variable to catch unwanted peaks in the temperature readings. The script is triggered by device events and timer events all in one.

Re: dzVents 1.0 released

Posted: Thursday 09 June 2016 17:05
by Neutrino
Hi dannybloe,
Device method updateLux(Lux) doesn't work.
The nValue is updated instead of sValue.

I corrected the function in Device.lua

Code: Select all

function self.updateLux(lux)
		self.update(0,lux)
end
Thanks for all ;)

Re: dzVents 1.0 released

Posted: Thursday 09 June 2016 17:22
by dannybloe
Neutrino wrote:Hi dannybloe,
Device method updateLux(Lux) doesn't work.
The nValue is updated instead of sValue.

I corrected the function in Device.lua

Code: Select all

function self.updateLux(lux)
		self.update(0,lux)
end
Thanks for all ;)
Thanks! Fixed this in the dev branch. Keep them coming :lol:

Re: dzVents 1.0 released

Posted: Thursday 09 June 2016 20:24
by dannybloe
I just added the Kodi commands in dzVents. (dev branch).
  • kodiExecuteAddOn(addonId): Function. Will send an Execute Addon command sending no parameters. Addon IDs are embedded in the addon configuration and are not to be confused with the Addon Name. For example: http://forums.homeseer.com/showthread.php?p=1213403.
  • kodiPause(): Function. Will send a Pause command, only effective if the device is streaming.
  • kodiPlay(): Function. Will send a Play command, only effective if the device was streaming and has been paused.
  • kodiPlayFavorites([position]): Function. Will play an item from the Kodi's Favorites list optionally starting at position. Favorite positions start from 0 which is the default.
  • kodiPlayPlaylist(name, [position]): Function. Will play a music or video Smart Playlist with name optionally starting at position. Playlist positions start from 0 which is the default.
  • kodiSetVolume(level): Function. Set the volume for a Kodi device, 0 <= level <= 100.
  • kodiStop(): Function. Will send a Stop command, only effective if the device is streaming.
  • kodiSwitchOff(): Function. Will turn the device off if this is supported in settings on the device.
Cheers,
Danny

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 12:11
by NietGiftig
I am rebuilding my lua scripts to dzVents style.
I have an simple energiemeter with one LED (1000pulse/kw) via espeasy (counted pulses/minute) to an incremental counter in Domoticz named 'WattCountRaw'
In Domoticz LUA I split the pulses in high and low (cost) incremental counting depending on day/time
In my working existing script I read the recieved pulses with:

Code: Select all

local pulse_counter = 'WattCountRaw'
local pulses = tonumber(otherdevices_svalues[pulse_counter])
In dzVents lua I cannot find the received pulses, so to say, I do not find an Device attribute which has the counted pulses
I tried :

Code: Select all

local inWatt = domoticz.devices['WattCountRaw'].WActual
print  ('Watt Pulses = ' .. inWatt)
But then I get:

Code: Select all

 LUA: An error occured when calling event handler try
 LUA: /home/pi/domoticz/scripts/lua/scripts/wattcount.lua:14: attempt to concatenate local 'inWatt' (a nil value)
Some help would be nice, I am using dzVents [1.0.2]

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 12:13
by dannybloe
NietGiftig wrote:I am rebuilding my lua scripts to dzVents style.
I have an simple energiemeter with one LED (1000pulse/kw) via espeasy (counted pulses/minute) to an incremental counter in Domoticz named 'WattCountRaw'
In Domoticz LUA I split the pulses in high and low (cost) incremental counting depending on day/time
In my working existing script I read the recieved pulses with:

Code: Select all

local pulse_counter = 'WattCountRaw'
local pulses = tonumber(otherdevices_svalues[pulse_counter])
In dzVents lua I cannot find the received pulses, so to say, I do not find an Device attribute which has the counted pulses
I tried :

Code: Select all

local inWatt = domoticz.devices['WattCountRaw'].WActual
print  ('Watt Pulses = ' .. inWatt)
But then I get:

Code: Select all

 LUA: An error occured when calling event handler try
 LUA: /home/pi/domoticz/scripts/lua/scripts/wattcount.lua:14: attempt to concatenate local 'inWatt' (a nil value)
Some help would be nice, I am using dzVents [1.0.2]
Could you send me the json output for that device (it should be in devices.lua if you have http fetching enabled). It is very well possible that that devicetype is not yet recognized by dzVents.

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 12:23
by NietGiftig
Here you go, only totals to see not the last transmitted pulse count.

Code: Select all

      {
         ["AddjMulti"]= 1.0,
         ["AddjMulti2"]= 1.0,
         ["AddjValue"]= 0.0,
         ["AddjValue2"]= 0.0,
         ["BatteryLevel"]= 255,
         ["Counter"]= "751.338 kWh",
         ["CounterToday"]= "3.551 kWh",
         ["CustomImage"]= 0,
         ["Data"]= "751.338 kWh",
         ["Description"]= "",
         ["Favorite"]= 0,
         ["HardwareID"]= 2,
         ["HardwareName"]= "ESPNetwork",
         ["HardwareType"]= "Dummy (Does nothing, use for virtual switches only)",
         ["HardwareTypeVal"]= 15,
         ["HaveTimeout"]= false,
         ["ID"]= "82064",
         ["LastUpdate"]= "2016-06-10 11:59:11",
         ["Name"]= "WattCountRaw",
         ["Notifications"]= "false",
         ["PlanID"]= "0",
         ["PlanIDs"]= { 0 },
         ["Protected"]= false,
         ["ShowNotifications"]= true,
         ["SignalLevel"]= "-",
         ["SubType"]= "Counter Incremental",
         ["SwitchTypeVal"]= 0,
         ["Timers"]= "false",
         ["Type"]= "General",
         ["TypeImg"]= "counter",
         ["Unit"]= 1,
         ["Used"]= 1,
         ["ValueQuantity"]= "",
         ["ValueUnits"]= "",
         ["XOffset"]= "0",
         ["YOffset"]= "0",
         ["idx"]= "65"
      }, 

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 12:30
by dannybloe
Ah, I see. I will have a look to see if I can make a specific property for this device. For now you can use the rawData attribute I think:

Code: Select all


-- hidden attribute which will show the rawData:
print(domoticz.devices['WattCountRaw']._sValues)

-- get the index from _sValues using the rawData attribute:
domoticz.devices['WattCountRaw'].rawData[1] -- or 2

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 12:38
by NietGiftig
dannybloe wrote:Ah, I see. I will have a look to see if I can make a specific property for this device. For now you can use the rawData attribute I think:

Code: Select all


-- hidden attribute which will show the rawData:
print(domoticz.devices['WattCountRaw']._sValues)

-- get the index from _sValues using the rawData attribute:
domoticz.devices['WattCountRaw'].rawData[1] -- or 2
Thanks, I will do that.
I think it is good to retrieve all the send raw sensor data, it is not always clear how it is used in Domoticz, so rawData is also a good solution
Sometimes you want to manipulate it yourself in a nice script :D

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 12:39
by dannybloe
Yes indeed. But use device.rawData[xx] instead of device._sValues as the data is already split into nice usable chunks.

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 17:22
by dannybloe
I added counterToday and counterTotal attributes for counter devices (still in dev branch). This is a formatted value with unit unfortunately. Currently it is a real pain to get raw values out of Domoticz. Note that the values are as accurate as the latest http fetch.

Also fixed a bug (incorrect documentation) for updating counter devices from Lua.

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 19:35
by NietGiftig
dannybloe wrote:Note that the values are as accurate as the latest http fetch.
I assume that I must get the counted pulses/per minute with still with rawdata as you described
The http fetch is 30 min apart so i cannot use the totals in my script wich is supposed to run every minute.
I could make a workaround with the persistent data option, hmm to much ...
I think that I will wait with this script until Domoticz & dzVents have a direct interface. :)

Re: dzVents 1.0 released

Posted: Friday 10 June 2016 19:58
by dannybloe
You can easily increase the interval to every minute if you like. Or maybe a bit slower.

Yes, you can still use rawData[1]. I always try to never break anything when making changes :)

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 13:22
by dhanjel
I have a lot of log entries in the error tab of this type:

2016-06-16 13:22:10.470 Error: EventSystem: Warning!, lua script /home/daniel/domoticz/scripts/lua/script_time_main.lua has been running for more than 10 seconds

is that normal?

Re: dzVents 1.0 released

Posted: Thursday 16 June 2016 13:25
by dannybloe
dhanjel wrote:I have a lot of log entries in the error tab of this type:

2016-06-16 13:22:10.470 Error: EventSystem: Warning!, lua script /home/daniel/domoticz/scripts/lua/script_time_main.lua has been running for more than 10 seconds

is that normal?
Then there is script that is taking a lot of time. Or doesn't end. Check the logs. It should show you when a script starts and ends (if you have info messages enabled in dzVents_settings.lua).