dzVents - event on temperature increase

Moderator: leecollings

Post Reply
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

dzVents - event on temperature increase

Post by tuxmartin »

Hi, I have following dzVents function:

Code: Select all

return {
	active = true, 
	on = {
		devices = {
			'temperature1', -- DS18B20 temperature sensor
			'switch1', -- domoticz virtual switch
			'thermostat1' -- domoticz temperature
		},	
	},

	execute = function(domoticz)
	-- ...
If I switch on/off "switch1" or change value on "thermostat1", function execute - it is ok.

But when "temperature1" change value (I mesure every 1 minute) nothing happens.
It is very bad. I need to compare temperature and thermostat and if temeprature is too hight stop heating.

How can I write "run function when temeprature1 change value"?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents - event on temperature increase

Post by dannybloe »

It should call your function immediately as soon as the temperature changes. Something is wrong if that doesn't happen. Turn dzVents into debug logging mode and carefully watch the domoticz.log.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

Re: dzVents - event on temperature increase

Post by tuxmartin »

I wrote this script:

Code: Select all

return {
	active = true,

    logging = {
        level = domoticz.LOG_DEBUG,
        marker = "TEST_"
    },

	on = {
		devices = {
			'temperature1'
		},
	},


	execute = function(domoticz, device)
	    domoticz.log("---aaaaaaaaaaaaaaaaaaaaaaaaa")
	    domoticz.log(device.name)
	    domoticz.log(device.temperature)
        domoticz.log("---bbbbbbbbbbbbbbbbbbbbbbbbb")
	end
}
I have DHT22 sensor. In Domoticz type "Temperature + Humidity"
it works:

Code: Select all

2017-12-14 17:48:45.643 dzVents: Info: Handling events for: "temperature1", value: "11.15;54.10;0"
2017-12-14 17:48:45.644 dzVents: Info: TEST_: ------ Start internal script: temperature_test: Device: "temperature1 (test)", Index: 10
2017-12-14 17:48:45.644 dzVents: Info: TEST_: ---aaaaaaaaaaaaaaaaaaaaaaaaa
2017-12-14 17:48:45.644 dzVents: Info: TEST_: temperature1
2017-12-14 17:48:45.644 dzVents: Info: TEST_: 11.14999961853
2017-12-14 17:48:45.645 dzVents: Info: TEST_: ---bbbbbbbbbbbbbbbbbbbbbbbbb
2017-12-14 17:48:45.645 dzVents: Info: TEST_: ------ Finished temperature_test 
But I have virtual domoticz thermometer, that extract only temperature from DHT22 "Temperature + Humidity". I'm using this code found something at domoticz wiki/forum:

Code: Select all

         # /home/domoticz/domoticz/scripts/lua/script_device_DHT22.lua
-- http://www.domoticz.com/wiki/Virtual_weather_devices#Scraping_only_temperature

--Script To Parse WeatherUnderground Multi-Value Sensor, Additionally using PWS: system from WU with a new output format
--This script assumes the output (which can be viewed in events show current state button) is like this 19.5;79;3;1019;3 (temp;humidity;null;pressure;null)
--more details at this wiki http://www.domoticz.com/wiki/Virtual_weather_devices
--
--The following need updated for your environment get the 'Idx' or 'Name' off the Device tab. By default only the Temp is 'uncommented or enabled' in this script.

local sensorwu = 'dht22' --name of the sensor that gets created when you add the WU device (and that contains multiple values like temperature, humidity, barometer etc)
local idxt = 14 --idx of the virtual temperature sensor you need to change this to your own Device IDx
local idxh = 15 --idx of the virtual humidity sensor you need to change this to your own Device IDx

--local idxp = 999 --idx of the virtual pressure sensor you need to change this to your own Device IDx
--

commandArray = {}

if devicechanged[sensorwu] then
        sWeatherTemp, sWeatherHumidity, sWeatherPressure = otherdevices_svalues[sensorwu]:match("([^;]+);([^;]+);([^;]+)")
        sWeatherTemp = tonumber(sWeatherTemp)
        sWeatherHumidity = tonumber(sWeatherHumidity)
        sWeatherPressure = tonumber(sWeatherPressure)
        parseDebug = ('WU Script Parsed Temp=' .. sWeatherTemp .. ' Humidity=' .. sWeatherHumidity .. ' Pressure=' .. sWeatherPressure)
        print(parseDebug)

        commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. sWeatherTemp}
        commandArray[2] = {['UpdateDevice'] = idxh .. '|' .. tostring(sWeatherHumidity) .. '|' .. tostring(sHumFeelsLike)}
        --commandArray[3] = {['UpdateDevice'] = idxp .. '|0|' .. tostring(sWeatherPressure) .. ';' .. tostring(sWeatherPressForcast)}
end

return commandArray
This sdcript update value on domoticz widget, but cannot trigger change action in dzVents. How can I use this script-updated-virtual domotcz sensor?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents - event on temperature increase

Post by dannybloe »

Just update your virtual sensor. If you use dzVents 2.3 then updating the sensor should trigger the script:

Code: Select all

return {
	active = true,
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = "TEST_"
	},
	on = {
		devices = {
			'temperature1',
			'myVirtualTemperatureDevice'
		},
	},
	execute = function(domoticz, device)
		if (device.name == 'temperature1') then
		
			domoticz.log('My temperature1 device got a new value: ' .. tostring(device.temperature))
			-- update the virtual sensor:
			domoticz.devices('myVirtualTemperatureDevice'). updateTemperature(device.temperature)
			
		elseif (device.name == 'myVirtualTemperatureDevice') then
		
			domoticz.log('My virtual temperature device got a new value: ' .. tostring(device.temperature))
			
		end	
	end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: Ragdag and 1 guest