How to update one value of wind sensor from DzVents  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

How to update one value of wind sensor from DzVents

Post by erem »

Friends,

I update a wind sensor with data from weerlive.nl from a bash script like this

Code: Select all

/usr/bin/curl "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx="$domidx2"&nvalue=0&svalue="$_wb";"$_wd";"$_ws";"0";22;24"
https://wiki.domoticz.com/wiki/Domoticz ... fic_device (wind)

Wind
/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=WB;WD;WS;WG;22;24
IDX = id of your device (This number can be found in the devices tab in the column "IDX")
WB = Wind bearing (0-359)
WD = Wind direction (S, SW, NNW, etc.)
WS = 10 * Wind speed [m/s]
WG = 10 * Gust [m/s]
22 = Temperature
24 = Temperature Windchill

the temperature and temperature windchill do not show up anywhere in the sensor, so i ignore them for now.

The data comes from weerlive.nl. Weerlive does not provide windgusts, so i want to update that value from DzVents using the DzVents data option like this during the update of the sensor.

Code: Select all

return {
	on = {
		devices = {
			'Buitenstation Wind KNMI'  -- KNMI data, no wind gust info 
		}
	},
	data = {
        windGust = { history = true, maxItems = 10, maxMinutes = 10 } -- declare list
	},
	
	execute = function(domoticz, device)
   	   -- store current windspeed 
     	   domoticz.data.windGust.add(device.speed)
        
            **********Here i want to update ONLY the wind gust value of the sensor************

  	   domoticz.log('windGust Max is ' .. tostring(domoticz.data.windGust.maxSince('00:10:00') .. 'm/s'), domoticz.LOG_INFO)
	   domoticz.log('Device ' .. device.name .. ' was updated with wind gust information', domoticz.LOG_INFO)
	end
}
i found this in the documentation (here->https://wiki.domoticz.com/wiki/DzVents: ... pting#Wind)

Wind
chill: Number.
direction: Number. Degrees.
directionString: String. Formatted wind direction like N, SE.
gust: Number. ( in meters / second, might change in future releases to Meters/Counters settings for Wind Meter )
gustMs: Number. Gust ( in meters / second ) 2.4.9
temperature: Number
speed: Number. Windspeed ( in the unit set in Meters/Counters settings for Wind Meter )
speedMs: Number. Windspeed ( in meters / second ) 2.4.9
updateWind(bearing, direction, speed, gust, temperature, chill): Function. Bearing in degrees, direction in N, S, NNW etc, speed in m/s, gust in
m/s, temperature and chill in Celsius. Use domoticz.toCelsius() to convert a Fahrenheit temperature to Celsius. Supports command options.

i could not find how to update only the gust or gustMs value with the value domoticz.data.windGust.maxSince('00:10:00')

Any help will be greatly appreciated

thanks for reading,

Rob
Regards,

Rob
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to update one value of wind sensor from DzVents  [Solved]

Post by waaren »

erem wrote: Wednesday 12 December 2018 22:34 I update a wind sensor with data from weerlive.nl from a bash script
i could not find how to update only the gust or gustMs value with the value domoticz.data.windGust.maxSince('00:10:00')
Any help will be greatly appreciated
If you want to update a sensor attribute and do not have new values for other attributes; use the current ones.

in this case it would look like

Code: Select all

local windDevice = domoticz.devices("Buitenstation Wind KNMI")
           windDevice.updateWind(windDevice.direction, windDevice.directionString, windDevice.speed * 10, domoticz.data.windGust.maxSince('00:10:00'), windDevice.temperature, windDevice.chill).silent()
(not sure about the factor 10 here. Just test and you will know.)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: How to update one value of wind sensor from DzVents

Post by erem »

@waaren,

thank you so much, that did the trick. Wonderful, and i learned something.

Regards,

Rob
Regards,

Rob
Xztraz
Posts: 107
Joined: Tuesday 31 January 2017 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to update one value of wind sensor from DzVents

Post by Xztraz »

some dzvents code i wrote thats inspired by this thread.

i use this code for my accurite 5in1 weather station to get gust, avg wind and wind chill

script takes current wind speed(m/s) and temperature(c)
and calculates avg wind(m/s), gust(m/s) and wind chill(c) to a dummy sensor

Code: Select all

return {
	on = { 
	    devices = {'WINDMETER'} --trigger on your wind meter
	},
	data = {
	    windGust = { history = true, maxItems = 30, maxMinutes = 10 }
	},
	
	execute = function(domoticz, device)
		if (device.isDevice) then
		    local windDummy = domoticz.devices("WINDDUMMYSENSOR")	--create a dummy device wind with temp and chill and enter name here
		    local tempDevice = domoticz.devices("TEMPMETER")	--your temperature meter 
		    local windDevice = domoticz.devices("WINDMETER")	--your wind meter
		    
		    domoticz.data.windGust.add(windDevice.speed)		--saves data for history calculations

		    --make some local variables
		    local windAVG = domoticz.utils.round(domoticz.data.windGust.avgSince('00:10:00'),2) --get average wind value from history
		    local windMAX = domoticz.data.windGust.maxSince('00:10:00')	--get max wind from history
		    local temp = domoticz.utils.round(tempDevice.temperature,2)	--round of and get temperature 

		    local windChill = temp
		    
		    --Calculate wind chill if wind an temp range is ok
		    if ((temp < 10.0) and (windDevice.speed >= 1.4)) then
                        --wind chill calculation
                        windChill = domoticz.utils.round( 13.12 + 0.6215*temp - 11.37*math.pow( windAVG*3.6 , 0.16) + 0.3965*temp*math.pow( windAVG*3.6, 0.16),1) 
                    end

                    windDummy.updateWind(windDevice.direction, windDevice.directionString, windAVG, windMAX, temp, windChill) --save data to dummy sensor

                	--log selection
			--domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
	    		--domoticz.log('Speed ' .. windAVG .. ' m/s', domoticz.LOG_INFO)
	    		--domoticz.log('Gust  ' .. windMAX .. ' m/s' , domoticz.LOG_INFO)
	    		--domoticz.log('Dir   ' .. windDevice.direction , domoticz.LOG_INFO)
	    		--domoticz.log('Temp  ' .. temp .. ' c' , domoticz.LOG_INFO)	    	
	    		--domoticz.log('Chill ' .. windChill .. ' c', domoticz.LOG_INFO)

		end
	end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest