Rule to calculate Windspeed

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
spranz
New user
Posts: 2
Joined: 10 Apr 2025, 06:29

Rule to calculate Windspeed

#1 Post by spranz » 10 Apr 2025, 06:39

Hey, my actuall Project is to build a weatherstation with espeasy.
To measure the windspeed i have an aneometer with a Hallsensor where i measure with a pulsecounter on D1. (one pulse = 30cm)
Now i need a rule to calculate the windspeed out of the Time Variable from the pulsecounter.
And store it in a dummy device.
I have no errors in my log, but also no value in my dummy device. Can anyone help me to fix my code?

Code: Select all

on Windgeschwindigkeit#Count do
  // Zeit in Millisekunden aus der Variablen lesen
  Let [Zeit_ms]=[Windgeschwindigkeit#Time]

  // Zurückgelegte Strecke in Kilometern (30 cm = 0.0003 km)
  Let [Strecke_km]=0.0003

  // Zeit von Millisekunden in Stunden umrechnen
  Let [Zeit_ms]/3600000

 Let [Zeit_h]=[Zeit_ms]

  // Geschwindigkeit in km/h berechnen
  Let [Geschwindigkeit_kmh]=[Strecke_km]/[Zeit_h]

  // Ergebnis in einer Variablen speichern (angenommen, Dummy-Device in Task 7, Feld 1)
  TaskValueSet 7,1,[Geschwindigkeit_kmh]
endon
Attachments
Screenshot 2025-04-10 063812.jpg
Screenshot 2025-04-10 063812.jpg (185.86 KiB) Viewed 6484 times

TD-er
Core team member
Posts: 9874
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rule to calculate Windspeed

#2 Post by TD-er » 10 Apr 2025, 09:56

How did you get to this syntax for those lines with "Let" ? Some Chat-GPT like suggestion?
In ESPEasy, the [...#...] syntax is being translated into a numerical value when parsing a rules line. See: https://espeasy.readthedocs.io/en/lates ... -notations
Also the '=' is not part of the command syntax.

You should use a numerical index to store a variable.
Ton is working on an extension to this to allow named variables, but that has not yet been included in an official build yet.

For internal variables, see: https://espeasy.readthedocs.io/en/lates ... -variables

Code: Select all

on Windgeschwindigkeit#Count do
  // Zeit in Millisekunden aus der Variablen lesen
  //   Let [Zeit_ms]=[Windgeschwindigkeit#Time]
  // Zeit von Millisekunden in Stunden umrechnen
  //  Let [Zeit_ms]/3600000
  //  Let [Zeit_h]=[Zeit_ms]
  // Zurückgelegte Strecke in Kilometern (30 cm = 0.0003 km)
  //  Let [Strecke_km]=0.0003
  // Geschwindigkeit in km/h berechnen
  //  Let [Geschwindigkeit_kmh]=[Strecke_km]/[Zeit_h]
  //
  // Factor: 
  //  0.0003 / (time / 3600000)
  // Simplify:
  // (3600000 * 0.0003) / t  ->  1080 / t
  if [Windgeschwindigkeit#Time] > 0
    let,1,1080/[Windgeschwindigkeit#Time]
  else
    let,1,0  // No measured time
  endif

  // Ergebnis in einer Variablen speichern (angenommen, Dummy-Device in Task 7, Feld 1)
  TaskValueSet 7,1,[var#1]
endon
Added bonus:
See the system variables page (tools->System variables) at the standard conversions.
When you have a display, or need to write it to log, you can also print the windspeed (and direction when present) like this:

Code: Select all

let,2,[var#1]/3.6 // Convert to meter/sec
logentry,"Windspeed: [var#1] km/h, [var#2] m/s, %c_ms2Bft%([var#2])"
// For wind direction, use:
// "Wind Dir.: %c_w_dir%(123.4)"  --> "Wind Dir.: ESE"

User avatar
Ath
Normal user
Posts: 4329
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rule to calculate Windspeed

#3 Post by Ath » 10 Apr 2025, 12:13

And to make these rules portable to other devices, you can set a Dummy Device using its name/valuename:

Code: Select all

  // Ergebnis in einer Variablen speichern (angenommen, Dummy-Device in Task 7, Feld 1)
  TaskValueSet ThingSpeak_2,Windgeschwindigkeit,[var#1]
NB: These names are not case-sensitive.
/Ton (PayPal.me)

spranz
New user
Posts: 2
Joined: 10 Apr 2025, 06:29

Re: Rule to calculate Windspeed

#4 Post by spranz » 10 Apr 2025, 21:42

Yes, it was a suggestion from ChatGPT :)
I also tried to find answers from google but without any functional code.
I tried out your code, but in the variable for the speed, there was no value at the end. Without any errors in the log.
Something ist wrong i think.

I modyfied the code:

Code: Select all

 on Windgeschwindigkeit#Time do
 let,1,1440/[Windgeschwindigkeit#Time]
  TaskValueSet,7,1,[var#1]
endon
with this it is calculating the value. I think something is wrong with the IF loop?
A zero when there is no windspeed would be nice, because at the moment the last value stays without changing from the counter.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest