• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[python] Get external weather info from weatherunderground
#1
Attached python script which retrieves current temperature and humidity data from weatherundergound and sends it to pilight. It's my first Python script ever, so not the best.

Requirements are a weatherundergound api key (free) and a generic weather device in pilight. I've used a device with id 100. If desires I also have a version that writes the data to a log file for graphing purposes.

The code is based on the example at wunderground. An overview of retrievable data can be found here.

To setup the scheduled logging trough crontab, ssh into your Pi and type "crontab -e". Add this line:

*/15 * * * * /usr/bin/python /root/templog/templogs.py

This runs the script located in /root/templog every 15 mins. Make sure that you end the line with a line feed (enter). Hit Ctrl+X, press Y and you should be done.

If you want to check if the cron job did execute, type "grep CRON /var/log/syslog|tail".


Attached Files
.zip   tempext.zip (Size: 1.12 KB / Downloads: 20)
 
Reply
#2
What about writing a C protocol around it?
 
Reply
#3
That is probably the best solution, unfortunately programming in C is new for me. I have to admit that the largest part of the script is based on a code example from wunderground. Maybe the script helps others a bit with the logic behind it and the data you get from wundergound.
 
Reply
#4
Updated the script, cleaned it and fixed a bug. The script didn't work correct as cron job beacuse the path to pilight-send was missing. Attached the new one.


Attached Files
.zip   tempext.zip (Size: 1.12 KB / Downloads: 25)
 
Reply
#5
just installed the new file, when i do python tempext.py

i get:

File "tempext.py", line 1
import urllib2 import json import subprocess
^
SyntaxError: invalid syntax

And how do you setup the crontab?
 
Reply
#6
I've updated the attachment, but the error could also appear when your edit the file with the wrong editor. Use notepad++ or even better nano. If that doesn't work out for you, pm me your api key.

To setup crontab, ssh into your Pi and type "crontab -e". Add this line:

*/15 * * * * /usr/bin/python /root/templog/tempext.py

This runs the script located in /root/templog every 15 mins. Make sure that you end the line with a line feed (enter). Hit Ctrl+X, press Y and you should be done.

If you want to check if the cron job did execute, type "grep CRON /var/log/syslog|tail".
 
Reply
#7
@Meloen, can you please post once.
 
Reply
#8
Sorry, me and this forum software are not a good match. Fixed.
 
Reply
#9
@meloen: Thanks! This works for me, for know. But a fully supported C version would me nice.
 
Reply
#10
@ meloen
I get the following ERROR
Code:
root@raspberrypi:~/templog# python tempext.py
Traceback (most recent call last):
  File "tempext.py", line 24, in <module>
    temp_c = parsed_json['current_observation']['temp_c']
KeyError: 'current_observation'

lcd4linux

edit: got it, wrong station, wrong pilight_path
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  clouds? on Weather Underground api Sjuul 4 1,780 08-16-2017, 01:35 PM
Last Post: Sjuul
  Python Ping pilight detect mobilephone Cryptomaster 0 2,404 01-10-2016, 04:17 PM
Last Post: Cryptomaster
  [python] Scheduled logging of pilight sensors to file meloen 10 11,028 10-31-2014, 09:20 AM
Last Post: hannibal-247
  pilight-daemon -D info -> log file BenPi 2 3,613 10-25-2014, 04:28 PM
Last Post: clach04
  [python] Trigger command based on event meloen 1 3,913 02-06-2014, 09:59 PM
Last Post: meloen

Forum Jump:


Browsing: 1 Guest(s)