Hello, can someone help me to display the air pressure from this site http://www.aviationweather.gov/adds/metars/index?submit=1&station_ids=EDDS&chk_metars=on&std_trans=translated
into a pimatic variable? how do I update it out every 5 minutes?
-
Display metar infomation in pimatic
-
It can be done but I don’t have the time now (want to go to bed ).
I quickly created a script that splits the lines into 2 variables: “the info” = “the value” which needs html2text (sudo apt-get install html2text
)bash script:
#!/bin/bash DATA=$(curl -s "http://www.aviationweather.gov/adds/metars/index?submit=1&station_ids=EDDS&chk_metars=on&std_trans=translated" |html2text -width 120) while read -r line; do #echo "$line" if [[ $line == *":"* ]] then var1=$(echo $line | cut -f1 -d:) var2=$(echo $line | cut -f2 -d:) echo "$var1 = $var2" fi done <<< "$DATA"
And this results in:
found at http = //www.aviationweather.gov/adds/metars/ METAR text = EDDS 302120Z 00000KT CAVOK 06/05 Q1030 Conditions at = EDDS (STUTTGART/ECHTER, DE) observed 2120 UTC 30 October 2016 Temperature = 6.0°C (43°F) Dewpoint = 5.0°C (41°F) [RH = 93%] Pressure (altimeter) = 30.41 inches Hg (1030.0 mb) Winds = calm Visibility = 6 or more miles (10+ km) Ceiling = ceiling and visibility are OK Clouds = unknown Weather = no significant weather observed at this time
This still requires removal of whitespace around the variables $var1 and $var2 and a curl command in the same while loop that uses $var1 as pimaticvariable name and $var2 as value.
I don’t know if I have time tomorrow, but maybe someone else could easily expand it.That is: if you want variables. Another option is to simply display it in an iframe in pimatic. Examples enough in the forum.
-
Hello, thanks for the first part. I need the pressure value saved in a pimatic variable to compare it to the bmp180 value. Thanks
-
You could have said that you only wanted the pressure.
script to run every x minutes from pimatic with a rule, or from your crontab:
#!/bin/bash DATA=$(curl -s "http://www.aviationweather.gov/adds/metars/index?submit=1&station_ids=EDDS&chk_metars=on&std_trans=translated" |html2text -width 120 -ascii | grep Pressure) #echo $DATA pressure=$(echo $DATA | cut -f2 -d: | cut -f2 -d\(| cut -f1 -dm | sed -e 's/[[:space:]]*$//') #echo $pressure curl -s -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$pressure'"}' --user "USERNAME:PASSWORD" http://localhost/api/variables/AMRS-pressure
Necessary tools for this script:
apt-get install grep curl html2text
(mostly grep and curl are already available)
Create a variableAMRS-pressure
in your pimatic or change script accordingly. Do not forget to specify a username & password in the script.
Make the script executable:chmod +x <scriptname>
-
Ergebnis ist:
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>404 - Not Found</title> </head> <body> <h1>404 - Not Found</h1> </body>
</html>
-
I just tested it on my own pimatic and for me it works fine.
What did you do?
Edit: Did you do this on your pimatic server itself?
if not you can’t usehttp://localhost/api/variables/AMRS-pressure
but should usehttp://<IP-ADDRESS>/api/variables/AMRS-pressure
And do you use port 80 for your pimatic?
If not you should usehttp://localhost:<PORT>/api/variables/AMRS-pressure
-
wrong port sorry…everything is fine…
this crontab line is correct?
*/5 * * * * /home/pi/pressurtest.sh
-
Yes,it is.