Wunderground weather in Domoticz with Python

So, last week out of nowhere my standard Wunderground integration stopped working. I tried to figure out what was going on, but it would take me too long, I re-added the service, but all to no avail. So I decided I was probably better off just writing a Python Script to do it myself. For the following code to work I am working without authentication from local calls to the Domoticz device, you can add these in your settings:

For the first bit to get this to work, just follow the instructions on the Wiki to get your API key. Then you need to add virtual devices to your setup. First you create a Dummy Hardware device and then you add virtual sensors. I added the following (click for large):

The virtual devices I created for the Weather service.

Also to learn a bit more of python I created a domoticz.py file with a couple of simple functions: updateDevice, readDevice and getSunRiseSet. The first two are obvious and the  last will become clear why later.

Lets start by just reading the data. You need the station you want. Now this can be tricky or simple. I would suggest to go to the documentation and find the data/geolookup API calls, you can find those here. If you use the IP based call and just paste the URL in your browser, you will get a response with a list of stations in there too. What you’re looking for is the ID of the station you like. You can also use any other of the API calls, as long as you find the ID of the station you prefer (maybe a big organisation’s instead of the hobbyist down the street). For me I went with a station that is in the next town, but supplies a great source of data. Add ‘pws:’ to the ID in the code to get the right call.

The first bits are easy, then a constant to convert information, then I grab the json data and the last bit is a bit of filtering out some spikes I noticed.

All pretty darn easy. The next bit is a bit of data cutting and pasting, but using my domoticz.py all relatively easy.

Just read through it and change the ID of your virtual devices to the corresponding IDs in your device overview. I added comment on why and what we’re updating so this should be straight forward, you can download both the files here: Python Wunderground Domoticz

Just make sure you change the IP to whatever the IP is of your Domoticz server or localhost if you run it on the same device.

The getSunRiseSet is used for the UV index to filter out spikes during the night. Unless we have some astrological wonder, I don’t think UV should be above 0 during the night.

The last bit to get this to work is to setup a cron job. Make sure you don’t call the cron too often, you only have 500 calls a day. To my math I worked out I can call about once every three minutes to be on the safe side. 

If you have any comments or suggested improvements, let me know!


Posted in Domoticz, Python, Weather | Leave a comment

Wake up light with Lua & Domoticz

This is a script I originally made with blocky, but that didn’t really work for some reason. Also I wanted it to be flexible, taking the date and time in consideration. So if my next alarm is set for monday, it won’t start on sunday when I want to sleep in.

This script uses three variables, which you’ll find at the top of the script.

wakeupspan – The time you want the light to take
steps – the number of iterations you want your light to take
switch – the name of the switch you want to use

Some thoughts

This doesn’t work very well if you don’t have Tasker as it is tied to a date, see below how to set that up. 
It’s a lot faster than adding a ‘wait’ or sleep in your script and should finish within a second or so. But the downside of this is that if you turn the light on or off during the timespan, the light will fall back to the scheduled commands, so if you decide to sleep in, it will come back with a vengeance ;-)
You might want to insert a ‘Holiday Mode’ check or whether you’re home at all.

Why two user variables? Well, it’s only one extra line in Tasker, but a whole lot more annoying to parse in Lua if I were to use one date-time or string.

So here’s the code:


To use

Place this script in your domoticz/scripts/lua folder named ‘script_time_wakeup.lua’. or something you prefer. Don’t forget to set two user variables ‘WakeUpTime’ and ‘WakeUpDate’.

I use Tasker and AutoAlarm to read my next alarm at around 3am and send it to my Raspberry Pi with a simple http get command:


(repace the IP address with your own)
It should look like this:

Posted in Domoticz, Lua | Tagged , , , | Leave a comment