Page 2 of 2

Re: Wind speed script

Posted: Sunday 22 March 2020 13:20
by Toulon7559
Extending my latest message in this thread in which I stated
Considering your stated application for sunscreencontrol, think about a strong&long hysteresys, because otherwise the screens may be jumping up and down!
;-) A very practical risk, but solution is rather easy.

2 General approaches, which can be combined (or not):
1) timing of the script loop, which causes the script to be executed with intervals
2) filtering of data, which 'smooths' the incoming data

1) is rather simple with many examples.
General approach:
if <time-check> then
[script-actions]
end

2) is slightly more complicated.
General approach:
a. make user-variable output_var and set default value
b. (in the script) set value alpha for 'speed' of filter. 1 = 100% of actual data (= quick reaction), and 0.1 is 10% of actual data (~ lazy reaction)
c. read actual data
d. read user-variable output_var
e. calculate output = output_var + alpha * data
f. check value of output to take action (or not)
g. save output as user-variable output_var
h. repeat c. till g. in which 1) may set the rythm of the input & output.

Re: Wind speed script

Posted: Sunday 22 March 2020 15:15
by Jan Jansen
waaren wrote: Sunday 22 March 2020 12:38
I don't see a command in this script to update a device. It is only sending something to the log.
First, the classic LUA suits me most at this time. I am not a programmer, but I see that it makes sense for me to study Dzvents.

My wish is for the following devices to be updated
1 dummy, type wind, called Windsnelheid,
2 dummy, type wind, called Windvlaag,
3 dummy, temperature type, called Buitentemperatuur.

I hope I don't ask too much.

@ Toulon
For the next challenge I choose solution 1, thanks anyway

Re: Wind speed script

Posted: Sunday 22 March 2020 17:17
by waaren
Jan Jansen wrote: Sunday 22 March 2020 15:15 My wish is for the following devices to be updated
1 dummy, type wind, called Windsnelheid,
2 dummy, type wind, called Windvlaag,
3 dummy, temperature type, called Buitentemperatuur.
Below is a dzVents version. If you need a Lua version you will have to wait for someone else on the forum to help.

Code: Select all

return 
{
	on = { devices = { 'Wind en buitentemperatuur' }},
	
	execute = function(dz, item)
	    dz.devices('Windsnelheid').updateWind(item.direction, item.directionString, item.speed, item.gust)
	    dz.devices('Windvlaag').updateWind(item.direction, item.directionString, item.gust, item.gust )
	    dz.devices('Buitentemperatuur').updateTemperature(item.temperature)
	end
}

Re: Wind speed script

Posted: Sunday 22 March 2020 19:19
by Jan Jansen
waaren wrote: Sunday 22 March 2020 17:17
Your tenacity convinced me. I'm going to practice with Dzvents.

Thank you very much for your help